weekly back-to-dev release 3.3dev
[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') . ' ');
47 $linkxpath = "//a[./img[starts-with(@title,$edit) and contains(@title,$gradeitem)]]";
48
49 $this->execute("behat_general::i_click_on", array($this->escape($linkxpath), "xpath_element"));
50 $this->execute("behat_forms::i_set_the_following_fields_to_these_values", $data);
51 $this->execute('behat_forms::press_button', $this->escape($savechanges));
52 }
53
54 public function i_set_calculation_for_grade_item_with_idnumbers($calculation, $gradeitem, TableNode $data) {
55
56 $gradeitem = behat_context_helper::escape($gradeitem);
57
58 if ($this->running_javascript()) {
59 $xpath = "//tr[contains(.,$gradeitem)]//*[contains(@class,'moodle-actionmenu')]";
60 if ($this->getSession()->getPage()->findAll('xpath', $xpath)) {
e584e6ae
DW
61 $this->execute("behat_action_menu::i_open_the_action_menu_in",
62 array("//tr[contains(.,$gradeitem)]",
63 "xpath_element"));
63e4df60
DW
64 }
65 }
66
67 // Going to edit calculation.
68 $savechanges = get_string('savechanges', 'grades');
69 $edit = behat_context_helper::escape(get_string('editcalculation', 'grades'));
70 $linkxpath = "//a[./img[starts-with(@title,$edit) and contains(@title,$gradeitem)]]";
71 $this->execute("behat_general::i_click_on", array($this->escape($linkxpath), "xpath_element"));
72
73 // Mapping names to idnumbers.
74 $datahash = $data->getRowsHash();
75 foreach ($datahash as $gradeitem => $idnumber) {
76 // This xpath looks for course, categories and items with the provided name.
77 // Grrr, we can't equal in categoryitem and courseitem because there is a line jump...
e584e6ae 78 $inputxpath = "//input[@class='idnumber'][" .
63e4df60
DW
79 "parent::li[@class='item'][text()='" . $gradeitem . "']" .
80 " or " .
e584e6ae
DW
81 "parent::li[@class='categoryitem' or @class='courseitem']" .
82 "/parent::ul/parent::li[starts-with(text(),'" . $gradeitem . "')]" .
63e4df60
DW
83 "]";
84 $this->execute('behat_forms::i_set_the_field_with_xpath_to', array($inputxpath, $idnumber));
85 }
86
87 $this->execute('behat_forms::press_button', get_string('addidnumbers', 'grades'));
88 $this->execute('behat_forms::i_set_the_field_to', array(get_string('calculation', 'grades'), $calculation));
89 $this->execute('behat_forms::press_button', $savechanges);
90
91 }
92
93 public function i_set_calculation_for_grade_category_with_idnumbers($calculation, $gradeitem, TableNode $data) {
94
95 $gradecategorytotal = behat_context_helper::escape($gradeitem . ' total');
96 $gradeitem = behat_context_helper::escape($gradeitem);
97
98 if ($this->running_javascript()) {
99 $xpath = "//tr[contains(.,$gradecategorytotal)]//*[contains(@class,'moodle-actionmenu')]";
100 if ($this->getSession()->getPage()->findAll('xpath', $xpath)) {
101 $xpath = "//tr[contains(.,$gradecategorytotal)]";
102 $this->execute("behat_action_menu::i_open_the_action_menu_in", array($xpath, "xpath_element"));
103 }
104 }
105
106 // Going to edit calculation.
107 $savechanges = get_string('savechanges', 'grades');
108 $edit = behat_context_helper::escape(get_string('editcalculation', 'grades'));
109 $linkxpath = "//a[./img[starts-with(@title,$edit) and contains(@title,$gradeitem)]]";
110 $this->execute("behat_general::i_click_on", array($this->escape($linkxpath), "xpath_element"));
111
112 // Mapping names to idnumbers.
113 $datahash = $data->getRowsHash();
114 foreach ($datahash as $gradeitem => $idnumber) {
115 // This xpath looks for course, categories and items with the provided name.
116 // Grrr, we can't equal in categoryitem and courseitem because there is a line jump...
117 $inputxpath = "//input[@class='idnumber'][" .
118 "parent::li[@class='item'][text()='" . $gradeitem . "']" .
119 " | " .
120 "parent::li[@class='categoryitem' | @class='courseitem']" .
121 "/parent::ul/parent::li[starts-with(text(),'" . $gradeitem . "')]" .
122 "]";
123 $this->execute('behat_forms::i_set_the_field_with_xpath_to', array($inputxpath, $idnumber));
124 }
125
126 $this->execute('behat_forms::press_button', get_string('addidnumbers', 'grades'));
127
128 $this->execute('behat_forms::i_set_the_field_to', array(get_string('calculation', 'grades'), $calculation));
129 $this->execute('behat_forms::press_button', $savechanges);
130 }
131
132 public function i_reset_weights_for_grade_category($gradeitem) {
133
134 $steps = array();
135
136 if ($this->running_javascript()) {
137 $gradeitemliteral = behat_context_helper::escape($gradeitem);
138 $xpath = "//tr[contains(.,$gradeitemliteral)]//*[contains(@class,'moodle-actionmenu')]";
139 if ($this->getSession()->getPage()->findAll('xpath', $xpath)) {
140 $xpath = "//tr[contains(.,$gradeitemliteral)]";
141 $this->execute("behat_action_menu::i_open_the_action_menu_in", array($xpath, "xpath_element"));
142 }
143 }
144
145 $linktext = get_string('resetweights', 'grades', (object)array('itemname' => $gradeitem));
146 $this->execute("behat_general::i_click_on", array($this->escape($linktext), "link"));
147 }
148}