MDL-66999 theme_boost: @extend remove extends for grades
[moodle.git] / grade / grading / tests / behat / behat_grading.php
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/>.
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  */
26 // NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
28 require_once(__DIR__ . '/../../../../lib/behat/behat_base.php');
30 use Behat\Gherkin\Node\TableNode as TableNode;
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  */
40 class behat_grading extends behat_base {
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
47      */
48     public function i_go_to_advanced_grading_page($activityname) {
50         $this->execute('behat_general::click_link', $this->escape($activityname));
52         $this->execute('behat_navigation::i_navigate_to_in_current_page_administration',
53             get_string('gradingmanagement', 'grading'));
54     }
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
61      */
62     public function i_go_to_advanced_grading_definition_page($activityname) {
64         // Transforming to literals, probably not necessary, just in case.
65         $newactionliteral = behat_context_helper::escape(get_string("manageactionnew", "grading"));
66         $editactionliteral = behat_context_helper::escape(get_string("manageactionedit", "grading"));
68         // Working both when adding and editing.
69         $definitionxpath = "//a[@class='action btn btn-lg']" .
70             "[./descendant::*[contains(., $newactionliteral) or contains(., $editactionliteral)]]";
72         $this->execute('behat_grading::i_go_to_advanced_grading_page', $this->escape($activityname));
74         $this->execute("behat_general::i_click_on", array($this->escape($definitionxpath), "xpath_element"));
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
82      */
83     public function i_go_to_activity_advanced_grading_page($userfullname, $activityname) {
85         // Step to access the user grade page from the grading page.
86         $gradetext = get_string('grade');
88         $this->execute('behat_general::click_link', $this->escape($activityname));
90         $this->execute('behat_navigation::i_navigate_to_in_current_page_administration',
91             get_string('viewgrading', 'mod_assign'));
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                        ));
100     }
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
107      */
108     public function i_publish_grading_form_definition_as_a_public_template($activityname) {
110         $this->execute('behat_grading::i_go_to_advanced_grading_page', $this->escape($activityname));
112         $this->execute("behat_general::i_click_on", array($this->escape(get_string("manageactionshare", "grading")), "link"));
114         $this->execute('behat_forms::press_button', get_string('continue'));
115     }
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
123      */
124     public function i_set_activity_to_use_grading_form($activityname, $templatename) {
126         $templateliteral = behat_context_helper::escape($templatename);
128         $templatexpath = "//h2[@class='template-name'][contains(., $templateliteral)]/" .
129             "following-sibling::div[contains(concat(' ', normalize-space(@class), ' '), ' template-actions ')]";
131         // Should work with both templates and own forms.
132         $literaltemplate = behat_context_helper::escape(get_string('templatepick', 'grading'));
133         $literalownform = behat_context_helper::escape(get_string('templatepickownform', 'grading'));
134         $usetemplatexpath = "/a[./descendant::div[text()=$literaltemplate]]|" .
135             "/a[./descendant::div[text()=$literalownform]]";
137         $this->execute('behat_grading::i_go_to_advanced_grading_page', $this->escape($activityname));
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")
146         );
147         $this->execute('behat_forms::press_button', get_string('continue'));
149     }
151     /**
152      * Saves the current page advanced grading form.
153      *
154      * @When /^I save the advanced grading form$/
155      */
156     public function i_save_the_advanced_grading_form() {
158         $this->execute('behat_forms::press_button', get_string('savechanges'));
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'));
162         $this->execute('behat_navigation::i_navigate_to_in_current_page_administration',
163             get_string('viewgrading', 'mod_assign'));
164     }
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
171      */
172     public function i_complete_the_advanced_grading_form_with_these_values(TableNode $data) {
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');
175     }