weekly release 3.7dev
[moodle.git] / theme / boost / tests / behat / behat_theme_boost_behat_grade.php
CommitLineData
63e4df60
DW
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 overrides.
19 *
20 * @copyright 2016 Damyon Wiese
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22 */
23
24// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
25
26require_once(__DIR__ . '/../../../../grade/tests/behat/behat_grade.php');
27
28use Behat\Gherkin\Node\TableNode as TableNode;
29
2ede86d7 30class behat_theme_boost_behat_grade extends behat_grade {
63e4df60
DW
31
32 public function i_set_the_following_settings_for_grade_item($gradeitem, TableNode $data) {
33
34 $gradeitem = behat_context_helper::escape($gradeitem);
35
36 if ($this->running_javascript()) {
37 $xpath = "//tr[contains(.,$gradeitem)]//*[contains(@class,'moodle-actionmenu')]";
38 if ($this->getSession()->getPage()->findAll('xpath', $xpath)) {
e584e6ae
DW
39 $this->execute("behat_action_menu::i_open_the_action_menu_in",
40 array("//tr[contains(.,$gradeitem)]",
41 "xpath_element"));
63e4df60
DW
42 }
43 }
44
45 $savechanges = get_string('savechanges', 'grades');
46 $edit = behat_context_helper::escape(get_string('edit') . ' ');
8857c715
DW
47 $linkxpath = "//a[./*[contains(concat(' ', normalize-space(@class), ' '), ' icon ') " .
48 "and starts-with(@title,$edit) and contains(@title,$gradeitem)]]";
63e4df60
DW
49
50 $this->execute("behat_general::i_click_on", array($this->escape($linkxpath), "xpath_element"));
51 $this->execute("behat_forms::i_set_the_following_fields_to_these_values", $data);
52 $this->execute('behat_forms::press_button', $this->escape($savechanges));
53 }
54
55 public function i_set_calculation_for_grade_item_with_idnumbers($calculation, $gradeitem, TableNode $data) {
56
57 $gradeitem = behat_context_helper::escape($gradeitem);
58
59 if ($this->running_javascript()) {
60 $xpath = "//tr[contains(.,$gradeitem)]//*[contains(@class,'moodle-actionmenu')]";
61 if ($this->getSession()->getPage()->findAll('xpath', $xpath)) {
e584e6ae
DW
62 $this->execute("behat_action_menu::i_open_the_action_menu_in",
63 array("//tr[contains(.,$gradeitem)]",
64 "xpath_element"));
63e4df60
DW
65 }
66 }
67
68 // Going to edit calculation.
69 $savechanges = get_string('savechanges', 'grades');
70 $edit = behat_context_helper::escape(get_string('editcalculation', 'grades'));
8857c715
DW
71 $linkxpath = "//a[./*[contains(concat(' ', normalize-space(@class), ' '), ' icon ') " .
72 "and starts-with(@title,$edit) and contains(@title,$gradeitem)]]";
63e4df60
DW
73 $this->execute("behat_general::i_click_on", array($this->escape($linkxpath), "xpath_element"));
74
75 // Mapping names to idnumbers.
76 $datahash = $data->getRowsHash();
77 foreach ($datahash as $gradeitem => $idnumber) {
78 // This xpath looks for course, categories and items with the provided name.
79 // Grrr, we can't equal in categoryitem and courseitem because there is a line jump...
e584e6ae 80 $inputxpath = "//input[@class='idnumber'][" .
63e4df60
DW
81 "parent::li[@class='item'][text()='" . $gradeitem . "']" .
82 " or " .
e584e6ae
DW
83 "parent::li[@class='categoryitem' or @class='courseitem']" .
84 "/parent::ul/parent::li[starts-with(text(),'" . $gradeitem . "')]" .
63e4df60
DW
85 "]";
86 $this->execute('behat_forms::i_set_the_field_with_xpath_to', array($inputxpath, $idnumber));
87 }
88
89 $this->execute('behat_forms::press_button', get_string('addidnumbers', 'grades'));
90 $this->execute('behat_forms::i_set_the_field_to', array(get_string('calculation', 'grades'), $calculation));
91 $this->execute('behat_forms::press_button', $savechanges);
92
93 }
94
95 public function i_set_calculation_for_grade_category_with_idnumbers($calculation, $gradeitem, TableNode $data) {
96
97 $gradecategorytotal = behat_context_helper::escape($gradeitem . ' total');
98 $gradeitem = behat_context_helper::escape($gradeitem);
99
100 if ($this->running_javascript()) {
101 $xpath = "//tr[contains(.,$gradecategorytotal)]//*[contains(@class,'moodle-actionmenu')]";
102 if ($this->getSession()->getPage()->findAll('xpath', $xpath)) {
103 $xpath = "//tr[contains(.,$gradecategorytotal)]";
104 $this->execute("behat_action_menu::i_open_the_action_menu_in", array($xpath, "xpath_element"));
105 }
106 }
107
108 // Going to edit calculation.
109 $savechanges = get_string('savechanges', 'grades');
110 $edit = behat_context_helper::escape(get_string('editcalculation', 'grades'));
8857c715
DW
111 $linkxpath = "//a[./*[contains(concat(' ', normalize-space(@class), ' '), ' icon ') " .
112 "and starts-with(@title,$edit) and contains(@title,$gradeitem)]]";
63e4df60
DW
113 $this->execute("behat_general::i_click_on", array($this->escape($linkxpath), "xpath_element"));
114
115 // Mapping names to idnumbers.
116 $datahash = $data->getRowsHash();
117 foreach ($datahash as $gradeitem => $idnumber) {
118 // This xpath looks for course, categories and items with the provided name.
119 // Grrr, we can't equal in categoryitem and courseitem because there is a line jump...
120 $inputxpath = "//input[@class='idnumber'][" .
121 "parent::li[@class='item'][text()='" . $gradeitem . "']" .
122 " | " .
123 "parent::li[@class='categoryitem' | @class='courseitem']" .
124 "/parent::ul/parent::li[starts-with(text(),'" . $gradeitem . "')]" .
125 "]";
126 $this->execute('behat_forms::i_set_the_field_with_xpath_to', array($inputxpath, $idnumber));
127 }
128
129 $this->execute('behat_forms::press_button', get_string('addidnumbers', 'grades'));
130
131 $this->execute('behat_forms::i_set_the_field_to', array(get_string('calculation', 'grades'), $calculation));
132 $this->execute('behat_forms::press_button', $savechanges);
133 }
134
135 public function i_reset_weights_for_grade_category($gradeitem) {
136
137 $steps = array();
138
139 if ($this->running_javascript()) {
140 $gradeitemliteral = behat_context_helper::escape($gradeitem);
141 $xpath = "//tr[contains(.,$gradeitemliteral)]//*[contains(@class,'moodle-actionmenu')]";
142 if ($this->getSession()->getPage()->findAll('xpath', $xpath)) {
143 $xpath = "//tr[contains(.,$gradeitemliteral)]";
144 $this->execute("behat_action_menu::i_open_the_action_menu_in", array($xpath, "xpath_element"));
145 }
146 }
147
148 $linktext = get_string('resetweights', 'grades', (object)array('itemname' => $gradeitem));
149 $this->execute("behat_general::i_click_on", array($this->escape($linktext), "link"));
150 }
ebcff7e2
MG
151
152 public function i_navigate_to_in_the_course_gradebook($gradepath) {
153 // If we are not on one of the gradebook pages already, follow "Grades" link in the navigation drawer.
154 $xpath = '//div[contains(@class,\'grade-navigation\')]';
155 if (!$this->getSession()->getPage()->findAll('xpath', $xpath)) {
156 $this->execute('behat_navigation::i_select_from_flat_navigation_drawer', get_string('grades'));
157 }
158
159 $this->select_in_gradebook_tabs($gradepath);
160 }
63e4df60 161}