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