Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 // NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php. 18 19 require_once (__DIR__ . '/../../../lib/behat/behat_base.php'); 20 21 /** 22 * Behat grade related steps definitions. 23 * 24 * @package core_grades 25 * @copyright 2022 Mathew May <mathew.solutions> 26 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 27 */ 28 class behat_grades extends behat_base { 29 30 /** 31 * Convert page names to URLs for steps like 'When I am on the "[identifier]" "[page type]" page'. 32 * 33 * Recognised page names are: 34 * | pagetype | name meaning | description | 35 * | [report] view | Course name | The view page for the specified course and report | 36 * | gradebook setup | Course name | The gradebook setup page for the specified course | 37 * | course grade settings | Course name | The grade settings page | 38 * | outcomes | Course name | The grade outcomes page | 39 * | scales | Course name | The grade scales page | 40 * 41 * @param string $type identifies which type of page this is - for example "Grader > View" 42 * @param string $identifier identifies the particular page - for example "Course name" 43 * @return moodle_url the corresponding URL. 44 */ 45 protected function resolve_page_instance_url(string $type, string $identifier): moodle_url { 46 $type = strtolower($type); 47 if (strpos($type, '>') !== false) { 48 [$pluginname, $type] = explode('>', $type); 49 $pluginname = strtolower(trim($pluginname)); 50 51 // Fetch the list of plugins. 52 $plugins = \core_component::get_plugin_list('gradereport'); 53 54 if (array_key_exists($pluginname, $plugins)) { 55 $plugin = $pluginname; 56 } else { 57 $plugins = array_combine( 58 array_keys($plugins), 59 array_keys($plugins) 60 ); 61 62 // This plugin is not in the list of plugins. Check the pluginname string. 63 $names = array_map(function($name) { 64 return strtolower(get_string('pluginname', "gradereport_{$name}")); 65 }, $plugins); 66 $result = array_search($pluginname, $names); 67 if ($result === false) { 68 throw new \coding_exception("Unknown plugin '{$pluginname}'"); 69 } 70 $plugin = $result; 71 } 72 } 73 $type = trim($type); 74 75 switch ($type) { 76 case 'view': 77 return new moodle_url( 78 "/grade/report/{$plugin}/index.php", 79 ['id' => $this->get_course_id($identifier)] 80 ); 81 case 'gradebook setup': 82 return new moodle_url( 83 "/grade/edit/tree/index.php", 84 ['id' => $this->get_course_id($identifier)] 85 ); 86 case 'course grade settings': 87 return new moodle_url( 88 "/grade/edit/settings/index.php", 89 ['id' => $this->get_course_id($identifier)] 90 ); 91 case 'outcomes': 92 return new moodle_url( 93 "/grade/edit/outcome/course.php", 94 ['id' => $this->get_course_id($identifier)] 95 ); 96 case 'scales': 97 return new moodle_url( 98 "/grade/edit/scale/index.php", 99 ['id' => $this->get_course_id($identifier)] 100 ); 101 default: 102 throw new \coding_exception( 103 "Unknown page type '$type' for page identifier '$identifier'" 104 ); 105 } 106 } 107 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body