MDL-66999 theme_boost: @extend remove extends for grades
[moodle.git] / grade / grading / tests / behat / behat_grading.php
CommitLineData
37fcfd99
DM
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 * Grading methods steps definitions.
19 *
20 * @package core_grading
21 * @category test
22 * @copyright 2013 David MonllaĆ³
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__ . '/../../../../lib/behat/behat_base.php');
29
eb9ca848 30use Behat\Gherkin\Node\TableNode as TableNode;
37fcfd99
DM
31
32/**
33 * Generic grading methods step definitions.
34 *
35 * @package core_grading
36 * @category test
37 * @copyright 2013 David MonllaĆ³
38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39 */
40class behat_grading extends behat_base {
41
42 /**
43 * Goes to the selected advanced grading page. You should be in the course page when this step begins.
44 *
45 * @Given /^I go to "(?P<activity_name_string>(?:[^"]|\\")*)" advanced grading page$/
46 * @param string $activityname
37fcfd99
DM
47 */
48 public function i_go_to_advanced_grading_page($activityname) {
eb9ca848
RT
49
50 $this->execute('behat_general::click_link', $this->escape($activityname));
51
ebcff7e2
MG
52 $this->execute('behat_navigation::i_navigate_to_in_current_page_administration',
53 get_string('gradingmanagement', 'grading'));
37fcfd99
DM
54 }
55
56 /**
57 * Goes to the selected advanced grading definition page. You should be in the course page when this step begins.
58 *
59 * @Given /^I go to "(?P<activity_name_string>(?:[^"]|\\")*)" advanced grading definition page$/
60 * @param string $activityname
37fcfd99
DM
61 */
62 public function i_go_to_advanced_grading_definition_page($activityname) {
63
64 // Transforming to literals, probably not necessary, just in case.
921faad9
RT
65 $newactionliteral = behat_context_helper::escape(get_string("manageactionnew", "grading"));
66 $editactionliteral = behat_context_helper::escape(get_string("manageactionedit", "grading"));
37fcfd99
DM
67
68 // Working both when adding and editing.
cacf6925 69 $definitionxpath = "//a[@class='action btn btn-lg']" .
37fcfd99
DM
70 "[./descendant::*[contains(., $newactionliteral) or contains(., $editactionliteral)]]";
71
eb9ca848
RT
72 $this->execute('behat_grading::i_go_to_advanced_grading_page', $this->escape($activityname));
73
74 $this->execute("behat_general::i_click_on", array($this->escape($definitionxpath), "xpath_element"));
37fcfd99
DM
75 }
76 /**
77 * Goes to the student's advanced grading page.
78 *
79 * @Given /^I go to "(?P<user_fullname_string>(?:[^"]|\\")*)" "(?P<activity_name_string>(?:[^"]|\\")*)" activity advanced grading page$/
80 * @param string $userfullname The user full name including firstname and lastname.
81 * @param string $activityname The activity name
37fcfd99
DM
82 */
83 public function i_go_to_activity_advanced_grading_page($userfullname, $activityname) {
84
85 // Step to access the user grade page from the grading page.
821ab1bf 86 $gradetext = get_string('grade');
37fcfd99 87
eb9ca848
RT
88 $this->execute('behat_general::click_link', $this->escape($activityname));
89
ebcff7e2
MG
90 $this->execute('behat_navigation::i_navigate_to_in_current_page_administration',
91 get_string('viewgrading', 'mod_assign'));
eb9ca848 92
821ab1bf
DW
93 $this->execute('behat_general::i_click_on_in_the',
94 array(
95 $this->escape($gradetext),
96 'link',
97 $this->escape($userfullname),
98 'table_row'
99 ));
37fcfd99
DM
100 }
101
102 /**
103 * Publishes current activity grading defined form as a public template.
104 *
105 * @Given /^I publish "(?P<activity_name_string>(?:[^"]|\\")*)" grading form definition as a public template$/
106 * @param string $activityname
37fcfd99
DM
107 */
108 public function i_publish_grading_form_definition_as_a_public_template($activityname) {
109
eb9ca848
RT
110 $this->execute('behat_grading::i_go_to_advanced_grading_page', $this->escape($activityname));
111
112 $this->execute("behat_general::i_click_on", array($this->escape(get_string("manageactionshare", "grading")), "link"));
113
114 $this->execute('behat_forms::press_button', get_string('continue'));
37fcfd99
DM
115 }
116
117 /**
118 * Sets a previously created grading form as the activity grading form.
119 *
120 * @Given /^I set "(?P<activity_name_string>(?:[^"]|\\")*)" activity to use "(?P<grading_form_template_string>(?:[^"]|\\")*)" grading form$/
121 * @param string $activityname
122 * @param string $templatename
37fcfd99
DM
123 */
124 public function i_set_activity_to_use_grading_form($activityname, $templatename) {
125
921faad9 126 $templateliteral = behat_context_helper::escape($templatename);
37fcfd99
DM
127
128 $templatexpath = "//h2[@class='template-name'][contains(., $templateliteral)]/" .
129 "following-sibling::div[contains(concat(' ', normalize-space(@class), ' '), ' template-actions ')]";
130
131 // Should work with both templates and own forms.
921faad9
RT
132 $literaltemplate = behat_context_helper::escape(get_string('templatepick', 'grading'));
133 $literalownform = behat_context_helper::escape(get_string('templatepickownform', 'grading'));
ddfbdf09
RT
134 $usetemplatexpath = "/a[./descendant::div[text()=$literaltemplate]]|" .
135 "/a[./descendant::div[text()=$literalownform]]";
37fcfd99 136
eb9ca848
RT
137 $this->execute('behat_grading::i_go_to_advanced_grading_page', $this->escape($activityname));
138
139 $this->execute('behat_general::click_link', $this->escape(get_string('manageactionclone', 'grading')));
140 $this->execute('behat_forms::i_set_the_field_to', array(get_string('searchownforms', 'grading'), 1));
141 $this->execute('behat_general::i_click_on_in_the',
142 array(get_string('search'), "button", "region-main", "region")
143 );
144 $this->execute('behat_general::i_click_on_in_the',
145 array($this->escape($usetemplatexpath), "xpath_element", $this->escape($templatexpath), "xpath_element")
37fcfd99 146 );
eb9ca848
RT
147 $this->execute('behat_forms::press_button', get_string('continue'));
148
37fcfd99
DM
149 }
150
151 /**
152 * Saves the current page advanced grading form.
153 *
154 * @When /^I save the advanced grading form$/
37fcfd99
DM
155 */
156 public function i_save_the_advanced_grading_form() {
eb9ca848
RT
157
158 $this->execute('behat_forms::press_button', get_string('savechanges'));
821ab1bf
DW
159 $this->execute('behat_forms::press_button', 'Ok');
160 $this->execute('behat_general::i_click_on', array($this->escape(get_string('editsettings')), 'link'));
161 $this->execute('behat_forms::press_button', get_string('cancel'));
ebcff7e2
MG
162 $this->execute('behat_navigation::i_navigate_to_in_current_page_administration',
163 get_string('viewgrading', 'mod_assign'));
37fcfd99
DM
164 }
165
166 /**
167 * Grades an activity using advanced grading. Note the grade is set by other steps, depending on the grading method.
168 *
169 * @Given /^I complete the advanced grading form with these values:$/
170 * @param TableNode $data
37fcfd99
DM
171 */
172 public function i_complete_the_advanced_grading_form_with_these_values(TableNode $data) {
eb9ca848
RT
173 $this->execute("behat_forms::i_set_the_following_fields_to_these_values", $data);
174 $this->execute('behat_grading::i_save_the_advanced_grading_form');
37fcfd99
DM
175 }
176}