1 |
efrain |
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 |
$this->execute('behat_navigation::i_close_block_drawer_if_open');
|
|
|
44 |
$gradelabel = $userfullname . ' ' . $itemname;
|
|
|
45 |
$fieldstr = get_string('useractivitygrade', 'gradereport_grader', $gradelabel);
|
|
|
46 |
|
|
|
47 |
$this->execute('behat_forms::i_set_the_field_to', array($this->escape($fieldstr), $grade));
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
/**
|
|
|
51 |
* Changes the settings of a grade item or category or the course.
|
|
|
52 |
*
|
|
|
53 |
* Teacher must be either on the grade setup page or on the Grader report page with editing mode turned on.
|
|
|
54 |
*
|
|
|
55 |
* @Given /^I set the following settings for grade item "(?P<grade_item_string>(?:[^"]|\\")*)" of type "([^"]*)" on "([^"]*)" page:$/
|
|
|
56 |
* @param string $gradeitem
|
|
|
57 |
* @param string $type
|
|
|
58 |
* @param string $page
|
|
|
59 |
* @param TableNode $data
|
|
|
60 |
*/
|
|
|
61 |
public function i_set_the_following_settings_for_grade_item(string $gradeitem, string $type, string $page, TableNode $data) {
|
|
|
62 |
$this->execute("behat_navigation::i_close_block_drawer_if_open");
|
|
|
63 |
|
|
|
64 |
if ($this->running_javascript()) {
|
|
|
65 |
$this->execute("behat_grades::i_click_on_grade_item_menu", [$gradeitem, $type, $page]);
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
$linktext = $type == 'gradeitem' ? get_string('itemsedit', 'grades') : get_string('categoryedit', 'grades');
|
|
|
69 |
|
|
|
70 |
$this->execute("behat_action_menu::i_choose_in_the_open_action_menu", $linktext);
|
|
|
71 |
|
|
|
72 |
if ($type !== 'gradeitem') {
|
|
|
73 |
$this->execute('behat_general::i_click_on_in_the', [get_string('showmore', 'form'),
|
|
|
74 |
'link', '.modal-dialog', 'css_element']);
|
|
|
75 |
}
|
|
|
76 |
|
11 |
efrain |
77 |
|
1 |
efrain |
78 |
$this->execute("behat_forms::i_set_the_following_fields_to_these_values", $data);
|
|
|
79 |
if ($this->getSession()->getPage()->find('xpath', './/button[@data-action="save"]')) {
|
|
|
80 |
$container = $this->get_selected_node("core_grades > gradeitem modal", "form");
|
11 |
efrain |
81 |
$this->execute('behat_general::i_click_on_in_the', [
|
|
|
82 |
'.//button[@data-action="save"]',
|
|
|
83 |
'xpath',
|
|
|
84 |
$container,
|
|
|
85 |
'NodeElement',
|
|
|
86 |
]);
|
1 |
efrain |
87 |
} else {
|
|
|
88 |
$savechanges = get_string('savechanges', 'grades');
|
|
|
89 |
$this->execute('behat_forms::press_button', $this->escape($savechanges));
|
|
|
90 |
}
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
/**
|
|
|
94 |
* Hids a grade item or category on gradebook setup or grader page.
|
|
|
95 |
*
|
|
|
96 |
* Teacher must be on the grade setup page.
|
|
|
97 |
*
|
|
|
98 |
* @Given /^I hide the grade item "(?P<grade_item_string>(?:[^"]|\\")*)" of type "([^"]*)" on "([^"]*)" page$/
|
|
|
99 |
* @param string $gradeitem
|
|
|
100 |
* @param string $type
|
|
|
101 |
* @param string $page
|
|
|
102 |
*/
|
|
|
103 |
public function i_hide_the_grade_item(string $gradeitem, string $type, string $page) {
|
|
|
104 |
|
|
|
105 |
$linktext = get_string('hide');
|
|
|
106 |
|
|
|
107 |
if ($this->running_javascript()) {
|
|
|
108 |
$this->execute("behat_grades::i_click_on_grade_item_menu", [$gradeitem, $type, $page]);
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
$this->execute("behat_action_menu::i_choose_in_the_open_action_menu", $linktext);
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
/**
|
|
|
115 |
* Duplicates a grade item or category.
|
|
|
116 |
*
|
|
|
117 |
* Teacher must be on the grade setup page.
|
|
|
118 |
*
|
|
|
119 |
* @Given /^I duplicate the grade item "(?P<grade_item_string>(?:[^"]|\\")*)"$/
|
|
|
120 |
* @param string $gradeitem
|
|
|
121 |
*/
|
|
|
122 |
public function i_duplicate_the_grade_item(string $gradeitem) {
|
|
|
123 |
$linktext = get_string('duplicate');
|
|
|
124 |
|
|
|
125 |
if ($this->running_javascript()) {
|
|
|
126 |
$this->execute("behat_grades::i_click_on_grade_item_menu", [$gradeitem, 'gradeitem', 'setup']);
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
$this->execute("behat_action_menu::i_choose_in_the_open_action_menu", $linktext);
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
/**
|
|
|
133 |
* Sets a calculated manual grade item. Needs a table with item name - idnumber relation.
|
|
|
134 |
* The step requires you to be in the 'Gradebook setup' page.
|
|
|
135 |
*
|
|
|
136 |
* @Given /^I set "(?P<calculation_string>(?:[^"]|\\")*)" calculation for grade item "(?P<grade_item_string>(?:[^"]|\\")*)" with idnumbers:$/
|
|
|
137 |
* @param string $calculation The calculation.
|
|
|
138 |
* @param string $gradeitem The grade item name.
|
|
|
139 |
* @param TableNode $TableNode The grade item name - idnumbers relation.
|
|
|
140 |
*/
|
|
|
141 |
public function i_set_calculation_for_grade_item_with_idnumbers($calculation, $gradeitem, TableNode $data) {
|
|
|
142 |
|
|
|
143 |
$edit = get_string('editcalculation', 'grades');
|
|
|
144 |
|
|
|
145 |
if ($this->running_javascript()) {
|
|
|
146 |
$this->execute("behat_grades::i_click_on_grade_item_menu", [$gradeitem, 'gradeitem', 'setup']);
|
|
|
147 |
}
|
|
|
148 |
$this->execute("behat_action_menu::i_choose_in_the_open_action_menu", $edit);
|
|
|
149 |
|
|
|
150 |
$savechanges = get_string('savechanges', 'grades');
|
|
|
151 |
|
|
|
152 |
// Mapping names to idnumbers.
|
|
|
153 |
$datahash = $data->getRowsHash();
|
|
|
154 |
foreach ($datahash as $gradeitem => $idnumber) {
|
|
|
155 |
// This xpath looks for course, categories and items with the provided name.
|
|
|
156 |
// Grrr, we can't equal in categoryitem and courseitem because there is a line jump...
|
|
|
157 |
$inputxpath = "//input[@class='idnumber'][" .
|
|
|
158 |
"parent::li[@class='item'][text()='" . $gradeitem . "']" .
|
|
|
159 |
" or " .
|
|
|
160 |
"parent::li[@class='categoryitem' or @class='courseitem']" .
|
|
|
161 |
"/parent::ul/parent::li[starts-with(text(),'" . $gradeitem . "')]" .
|
|
|
162 |
"]";
|
|
|
163 |
$this->execute('behat_forms::i_set_the_field_with_xpath_to', [$inputxpath, $idnumber]);
|
|
|
164 |
}
|
|
|
165 |
|
|
|
166 |
$this->execute('behat_forms::press_button', get_string('addidnumbers', 'grades'));
|
|
|
167 |
$this->execute('behat_forms::i_set_the_field_to', [get_string('calculation', 'grades'), $calculation]);
|
|
|
168 |
$this->execute('behat_forms::press_button', $savechanges);
|
|
|
169 |
|
|
|
170 |
}
|
|
|
171 |
|
|
|
172 |
/**
|
|
|
173 |
* Sets a calculated manual grade category total. Needs a table with item name - idnumber relation.
|
|
|
174 |
* The step requires you to be in the 'Gradebook setup' page.
|
|
|
175 |
*
|
|
|
176 |
* @Given /^I set "(?P<calculation_string>(?:[^"]|\\")*)" calculation for grade category "(?P<grade_item_string>(?:[^"]|\\")*)" with idnumbers:$/
|
|
|
177 |
* @param string $calculation The calculation.
|
|
|
178 |
* @param string $gradeitem The grade item name.
|
|
|
179 |
* @param TableNode $data The grade item name - idnumbers relation.
|
|
|
180 |
*/
|
|
|
181 |
public function i_set_calculation_for_grade_category_with_idnumbers(string $calculation, string $gradeitem, TableNode $data) {
|
|
|
182 |
|
|
|
183 |
$edit = get_string('editcalculation', 'grades');
|
|
|
184 |
|
|
|
185 |
if ($this->running_javascript()) {
|
|
|
186 |
$this->execute("behat_grades::i_click_on_grade_item_menu", [$gradeitem, 'gradeitem', 'setup']);
|
|
|
187 |
}
|
|
|
188 |
$this->execute("behat_action_menu::i_choose_in_the_open_action_menu", $edit);
|
|
|
189 |
|
|
|
190 |
$savechanges = get_string('savechanges', 'grades');
|
|
|
191 |
|
|
|
192 |
// Mapping names to idnumbers.
|
|
|
193 |
$datahash = $data->getRowsHash();
|
|
|
194 |
foreach ($datahash as $gradeitem => $idnumber) {
|
|
|
195 |
// This xpath looks for course, categories and items with the provided name.
|
|
|
196 |
// Grrr, we can't equal in categoryitem and courseitem because there is a line jump...
|
|
|
197 |
$inputxpath = "//input[@class='idnumber'][" .
|
|
|
198 |
"parent::li[@class='item'][text()='" . $gradeitem . "']" .
|
|
|
199 |
" | " .
|
|
|
200 |
"parent::li[@class='categoryitem' or @class='courseitem']" .
|
|
|
201 |
"/parent::ul/parent::li[starts-with(text(),'" . $gradeitem . "')]" .
|
|
|
202 |
"]";
|
|
|
203 |
$this->execute('behat_forms::i_set_the_field_with_xpath_to', array($inputxpath, $idnumber));
|
|
|
204 |
}
|
|
|
205 |
|
|
|
206 |
$this->execute('behat_forms::press_button', get_string('addidnumbers', 'grades'));
|
|
|
207 |
|
|
|
208 |
$this->execute('behat_forms::i_set_the_field_to', [get_string('calculation', 'grades'), $calculation]);
|
|
|
209 |
$this->execute('behat_forms::press_button', $savechanges);
|
|
|
210 |
}
|
|
|
211 |
|
|
|
212 |
/**
|
|
|
213 |
* Resets the weights for the grade category
|
|
|
214 |
*
|
|
|
215 |
* Teacher must be on the grade setup page.
|
|
|
216 |
*
|
|
|
217 |
* @Given /^I reset weights for grade category "(?P<grade_item_string>(?:[^"]|\\")*)"$/
|
|
|
218 |
* @param string $gradeitem
|
|
|
219 |
*/
|
|
|
220 |
public function i_reset_weights_for_grade_category(string $gradeitem) {
|
|
|
221 |
|
|
|
222 |
if ($this->running_javascript()) {
|
|
|
223 |
$this->execute("behat_grades::i_click_on_grade_item_menu", [$gradeitem, 'category', 'setup']);
|
|
|
224 |
}
|
|
|
225 |
$linktext = get_string('resetweightsshort', 'grades');
|
|
|
226 |
$this->execute("behat_action_menu::i_choose_in_the_open_action_menu", [$this->escape($linktext), "link"]);
|
|
|
227 |
}
|
|
|
228 |
|
|
|
229 |
/**
|
|
|
230 |
* Step allowing to test before-the-fix behaviour of the gradebook
|
|
|
231 |
*
|
|
|
232 |
* @Given /^gradebook calculations for the course "(?P<coursename_string>(?:[^"]|\\")*)" are frozen at version "(?P<version_string>(?:[^"]|\\")*)"$/
|
|
|
233 |
* @param string $coursename
|
|
|
234 |
* @param string $version
|
|
|
235 |
*/
|
|
|
236 |
public function gradebook_calculations_for_the_course_are_frozen_at_version($coursename, $version) {
|
|
|
237 |
global $DB;
|
|
|
238 |
$courseid = $DB->get_field('course', 'id', array('shortname' => $coursename), MUST_EXIST);
|
|
|
239 |
set_config('gradebook_calculations_freeze_' . $courseid, $version);
|
|
|
240 |
}
|
|
|
241 |
|
|
|
242 |
/**
|
|
|
243 |
* @deprecated since 4.0 - use behat_forms::i_set_the_field_to() instead.
|
|
|
244 |
*/
|
1441 |
ariadna |
245 |
#[\core\attribute\deprecated('behat_forms::i_set_the_field_to', since: '4.0', final: true)]
|
|
|
246 |
protected function select_in_gradebook_tabs() {
|
|
|
247 |
\core\deprecation::emit_deprecation([self::class, __FUNCTION__]);
|
1 |
efrain |
248 |
}
|
|
|
249 |
|
|
|
250 |
/**
|
|
|
251 |
* Navigates to the course gradebook and selects the specified item from the general grade navigation selector.
|
|
|
252 |
*
|
|
|
253 |
* Examples:
|
|
|
254 |
* - I navigate to "Setup > Gradebook setup" in the course gradebook
|
|
|
255 |
* - I navigate to "Scales" in the course gradebook
|
|
|
256 |
* - I navigate to "More > Grade letters" in the course gradebook
|
|
|
257 |
*
|
|
|
258 |
* @Given /^I navigate to "(?P<gradepath_string>(?:[^"]|\\")*)" in the course gradebook$/
|
|
|
259 |
* @param string $gradepath The path string. If the path has two items (ex. "More > Grade letters"), the first item
|
|
|
260 |
* ("More") will be used to identify an option group in the navigation selector, while the
|
|
|
261 |
* second ("Grade letters") will be used to identify an option within that option group.
|
|
|
262 |
* Otherwise, a single item in a path (ex. "Scales") will be used to identify an option in
|
|
|
263 |
* the navigation selector regardless of the option group.
|
|
|
264 |
*/
|
|
|
265 |
public function i_navigate_to_in_the_course_gradebook($gradepath) {
|
|
|
266 |
// If we are not on one of the gradebook pages already, follow "Grades" link in the navigation drawer.
|
|
|
267 |
$xpath = '//div[contains(@class,\'grade-navigation\')]';
|
|
|
268 |
if (!$this->getSession()->getPage()->findAll('xpath', $xpath)) {
|
|
|
269 |
$this->execute('behat_navigation::i_select_from_secondary_navigation', get_string('grades'));
|
|
|
270 |
}
|
|
|
271 |
|
|
|
272 |
$this->execute('behat_forms::i_set_the_field_to', [get_string('gradebooknavigationmenu', 'grades'), $gradepath]);
|
|
|
273 |
}
|
|
|
274 |
|
|
|
275 |
/**
|
|
|
276 |
* Navigates to the imports page in the course gradebook and selects the specified import type from the grade
|
|
|
277 |
* imports navigation selector.
|
|
|
278 |
*
|
|
|
279 |
* Examples:
|
|
|
280 |
* - I navigate to "CSV file" import page in the course gradebook
|
|
|
281 |
*
|
|
|
282 |
* @Given /^I navigate to "(?P<importoption_string>(?:[^"]|\\")*)" import page in the course gradebook$/
|
|
|
283 |
* @param string $gradeimportoption The name of an existing grade import option.
|
|
|
284 |
*/
|
|
|
285 |
public function i_navigate_to_import_page_in_the_course_gradebook($gradeimportoption) {
|
|
|
286 |
$this->i_navigate_to_in_the_course_gradebook("More > Import");
|
|
|
287 |
$this->execute('behat_forms::i_set_the_field_to', [get_string('importas', 'grades'), $gradeimportoption]);
|
|
|
288 |
}
|
|
|
289 |
|
|
|
290 |
/**
|
|
|
291 |
* Navigates to the exports page in the course gradebook and selects the specified export type from the grade
|
|
|
292 |
* exports navigation selector.
|
|
|
293 |
*
|
|
|
294 |
* Examples:
|
|
|
295 |
* - I navigate to "XML file" export page in the course gradebook
|
|
|
296 |
*
|
|
|
297 |
* @Given /^I navigate to "(?P<exportoption_string>(?:[^"]|\\")*)" export page in the course gradebook$/
|
|
|
298 |
* @param string $gradeexportoption The name of an existing grade export option.
|
|
|
299 |
*/
|
|
|
300 |
public function i_navigate_to_export_page_in_the_course_gradebook($gradeexportoption) {
|
|
|
301 |
$this->i_navigate_to_in_the_course_gradebook("More > Export");
|
|
|
302 |
$this->execute('behat_forms::i_set_the_field_to', [get_string('exportas', 'grades'), $gradeexportoption]);
|
|
|
303 |
}
|
|
|
304 |
|
|
|
305 |
/**
|
|
|
306 |
* @deprecated since 4.1 - use behat_forms::i_set_the_field_to() instead.
|
|
|
307 |
*/
|
1441 |
ariadna |
308 |
#[\core\attribute\deprecated('behat_forms::i_set_the_field_to', since: '4.1', final: true)]
|
|
|
309 |
protected function select_in_gradebook_navigation_selector() {
|
|
|
310 |
\core\deprecation::emit_deprecation([self::class, __FUNCTION__]);
|
1 |
efrain |
311 |
}
|
|
|
312 |
}
|