[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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 /** 18 * Behat grade related steps definitions. 19 * 20 * @package core_grades 21 * @category test 22 * @copyright 2014 Mark Nelson <markn@moodle.com> 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 // NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php. 27 28 require_once (__DIR__ . '/../../../lib/behat/behat_base.php'); 29 30 use Behat\Gherkin\Node\TableNode as TableNode; 31 32 class behat_grade extends behat_base { 33 34 /** 35 * Enters a grade via the gradebook for a specific grade item and user when viewing the 'Grader report' with editing mode turned on. 36 * 37 * @Given /^I give the grade "(?P<grade_number>(?:[^"]|\\")*)" to the user "(?P<username_string>(?:[^"]|\\")*)" for the grade item "(?P<grade_activity_string>(?:[^"]|\\")*)"$/ 38 * @param int $grade 39 * @param string $userfullname the user's fullname as returned by fullname() 40 * @param string $itemname 41 */ 42 public function i_give_the_grade($grade, $userfullname, $itemname) { 43 $gradelabel = $userfullname . ' ' . $itemname; 44 $fieldstr = get_string('useractivitygrade', 'gradereport_grader', $gradelabel); 45 46 $this->execute('behat_forms::i_set_the_field_to', array($this->escape($fieldstr), $grade)); 47 } 48 49 /** 50 * Enters a quick feedback via the gradebook for a specific grade item and user when viewing 51 * the 'Grader report' with editing mode turned on. 52 * 53 * @Given /^I give the feedback "(?P<grade_number>(?:[^"]|\\")*)" to the user "(?P<username_string>(?:[^"]|\\")*)" for the grade item "(?P<grade_activity_string>(?:[^"]|\\")*)"$/ 54 * @param string $feedback 55 * @param string $userfullname the user's fullname as returned by fullname() 56 * @param string $itemname 57 */ 58 public function i_give_the_feedback($feedback, $userfullname, $itemname) { 59 $gradelabel = $userfullname . ' ' . $itemname; 60 $fieldstr = get_string('useractivityfeedback', 'gradereport_grader', $gradelabel); 61 62 $this->execute('behat_forms::i_set_the_field_to', array($this->escape($fieldstr), $this->escape($feedback))); 63 } 64 65 /** 66 * Changes the settings of a grade item or category or the course. 67 * 68 * Teacher must be either on the grade setup page or on the Grader report page with editing mode turned on. 69 * 70 * @Given /^I set the following settings for grade item "(?P<grade_item_string>(?:[^"]|\\")*)":$/ 71 * @param string $gradeitem 72 * @param TableNode $data 73 */ 74 public function i_set_the_following_settings_for_grade_item($gradeitem, TableNode $data) { 75 76 $gradeitem = behat_context_helper::escape($gradeitem); 77 78 if ($this->running_javascript()) { 79 $xpath = "//tr[contains(.,$gradeitem)]//*[contains(@class,'moodle-actionmenu')]//a[contains(@class,'toggle-display')]"; 80 if ($this->getSession()->getPage()->findAll('xpath', $xpath)) { 81 $this->execute("behat_general::i_click_on", array($this->escape($xpath), "xpath_element")); 82 } 83 } 84 85 $savechanges = get_string('savechanges', 'grades'); 86 $edit = behat_context_helper::escape(get_string('edit') . ' '); 87 $linkxpath = "//a[./img[starts-with(@title,$edit) and contains(@title,$gradeitem)]]"; 88 89 $this->execute("behat_general::i_click_on", array($this->escape($linkxpath), "xpath_element")); 90 $this->execute("behat_forms::i_set_the_following_fields_to_these_values", $data); 91 $this->execute('behat_forms::press_button', $this->escape($savechanges)); 92 } 93 94 /** 95 * Sets a calculated manual grade item. Needs a table with item name - idnumber relation. 96 * The step requires you to be in the 'Gradebook setup' page. 97 * 98 * @Given /^I set "(?P<calculation_string>(?:[^"]|\\")*)" calculation for grade item "(?P<grade_item_string>(?:[^"]|\\")*)" with idnumbers:$/ 99 * @param string $calculation The calculation. 100 * @param string $gradeitem The grade item name. 101 * @param TableNode $TableNode The grade item name - idnumbers relation. 102 */ 103 public function i_set_calculation_for_grade_item_with_idnumbers($calculation, $gradeitem, TableNode $data) { 104 105 $gradeitem = behat_context_helper::escape($gradeitem); 106 107 if ($this->running_javascript()) { 108 $xpath = "//tr[contains(.,$gradeitem)]//*[contains(@class,'moodle-actionmenu')]//a[contains(@class,'toggle-display')]"; 109 if ($this->getSession()->getPage()->findAll('xpath', $xpath)) { 110 $this->execute("behat_general::i_click_on", array($this->escape($xpath), "xpath_element")); 111 } 112 } 113 114 // Going to edit calculation. 115 $savechanges = get_string('savechanges', 'grades'); 116 $edit = behat_context_helper::escape(get_string('editcalculation', 'grades')); 117 $linkxpath = "//a[./img[starts-with(@title,$edit) and contains(@title,$gradeitem)]]"; 118 $this->execute("behat_general::i_click_on", array($this->escape($linkxpath), "xpath_element")); 119 120 // Mapping names to idnumbers. 121 $datahash = $data->getRowsHash(); 122 foreach ($datahash as $gradeitem => $idnumber) { 123 // This xpath looks for course, categories and items with the provided name. 124 // Grrr, we can't equal in categoryitem and courseitem because there is a line jump... 125 $inputxpath ="//input[@class='idnumber'][" . 126 "parent::li[@class='item'][text()='" . $gradeitem . "']" . 127 " or " . 128 "parent::li[@class='categoryitem' or @class='courseitem']/parent::ul/parent::li[starts-with(text(),'" . $gradeitem . "')]" . 129 "]"; 130 $this->execute('behat_forms::i_set_the_field_with_xpath_to', array($inputxpath, $idnumber)); 131 } 132 133 $this->execute('behat_forms::press_button', get_string('addidnumbers', 'grades')); 134 $this->execute('behat_forms::i_set_the_field_to', array(get_string('calculation', 'grades'), $calculation)); 135 $this->execute('behat_forms::press_button', $savechanges); 136 137 } 138 139 /** 140 * Sets a calculated manual grade category total. Needs a table with item name - idnumber relation. 141 * The step requires you to be in the 'Gradebook setup' page. 142 * 143 * @Given /^I set "(?P<calculation_string>(?:[^"]|\\")*)" calculation for grade category "(?P<grade_item_string>(?:[^"]|\\")*)" with idnumbers:$/ 144 * @param string $calculation The calculation. 145 * @param string $gradeitem The grade item name. 146 * @param TableNode $data The grade item name - idnumbers relation. 147 */ 148 public function i_set_calculation_for_grade_category_with_idnumbers($calculation, $gradeitem, TableNode $data) { 149 150 $gradecategorytotal = behat_context_helper::escape($gradeitem . ' total'); 151 $gradeitem = behat_context_helper::escape($gradeitem); 152 153 if ($this->running_javascript()) { 154 $xpath = "//tr[contains(.,$gradecategorytotal)]//*[contains(@class,'moodle-actionmenu')]" . 155 "//a[contains(@class,'toggle-display')]"; 156 if ($this->getSession()->getPage()->findAll('xpath', $xpath)) { 157 $this->execute("behat_general::i_click_on", array($this->escape($xpath), "xpath_element")); 158 } 159 } 160 161 // Going to edit calculation. 162 $savechanges = get_string('savechanges', 'grades'); 163 $edit = behat_context_helper::escape(get_string('editcalculation', 'grades')); 164 $linkxpath = "//a[./img[starts-with(@title,$edit) and contains(@title,$gradeitem)]]"; 165 $this->execute("behat_general::i_click_on", array($this->escape($linkxpath), "xpath_element")); 166 167 // Mapping names to idnumbers. 168 $datahash = $data->getRowsHash(); 169 foreach ($datahash as $gradeitem => $idnumber) { 170 // This xpath looks for course, categories and items with the provided name. 171 // Grrr, we can't equal in categoryitem and courseitem because there is a line jump... 172 $inputxpath = "//input[@class='idnumber'][" . 173 "parent::li[@class='item'][text()='" . $gradeitem . "']" . 174 " | " . 175 "parent::li[@class='categoryitem' | @class='courseitem']" . 176 "/parent::ul/parent::li[starts-with(text(),'" . $gradeitem . "')]" . 177 "]"; 178 $this->execute('behat_forms::i_set_the_field_with_xpath_to', array($inputxpath, $idnumber)); 179 } 180 181 $this->execute('behat_forms::press_button', get_string('addidnumbers', 'grades')); 182 183 $this->execute('behat_forms::i_set_the_field_to', array(get_string('calculation', 'grades'), $calculation)); 184 $this->execute('behat_forms::press_button', $savechanges); 185 } 186 187 /** 188 * Resets the weights for the grade category 189 * 190 * Teacher must be on the grade setup page. 191 * 192 * @Given /^I reset weights for grade category "(?P<grade_item_string>(?:[^"]|\\")*)"$/ 193 * @param $gradeitem 194 */ 195 public function i_reset_weights_for_grade_category($gradeitem) { 196 197 $steps = array(); 198 199 if ($this->running_javascript()) { 200 $gradeitemliteral = behat_context_helper::escape($gradeitem); 201 $xpath = "//tr[contains(.,$gradeitemliteral)]//*[contains(@class,'moodle-actionmenu')]//a[contains(@class,'toggle-display')]"; 202 if ($this->getSession()->getPage()->findAll('xpath', $xpath)) { 203 $this->execute("behat_general::i_click_on", array($this->escape($xpath), "xpath_element")); 204 } 205 } 206 207 $linktext = get_string('resetweights', 'grades', (object)array('itemname' => $gradeitem)); 208 $this->execute("behat_general::i_click_on", array($this->escape($linktext), "link")); 209 } 210 211 /** 212 * Step allowing to test before-the-fix behaviour of the gradebook 213 * 214 * @Given /^gradebook calculations for the course "(?P<coursename_string>(?:[^"]|\\")*)" are frozen at version "(?P<version_string>(?:[^"]|\\")*)"$/ 215 * @param string $coursename 216 * @param string $version 217 */ 218 public function gradebook_calculations_for_the_course_are_frozen_at_version($coursename, $version) { 219 global $DB; 220 $courseid = $DB->get_field('course', 'id', array('shortname' => $coursename), MUST_EXIST); 221 set_config('gradebook_calculations_freeze_' . $courseid, $version); 222 } 223 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |