MDL-69588 navigation: Address final point from review
[moodle.git] / mod / workshop / tests / behat / behat_mod_workshop.php
blobd02ce9532658276caa3f2e5477a1ca77a6713865
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.
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 * Steps definitions related to mod_workshop.
20 * @package mod_workshop
21 * @category test
22 * @copyright 2014 Marina Glancy
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
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 * Steps definitions related to mod_workshop.
35 * @package mod_workshop
36 * @category test
37 * @copyright 2014 Marina Glancy
38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40 class behat_mod_workshop extends behat_base {
41 /**
42 * Changes the submission phase for the workshop.
44 * @When /^I change phase in workshop "(?P<workshop_name_string>(?:[^"]|\\")*)" to "(?P<phase_name_string>(?:[^"]|\\")*)"$/
45 * @param string $questiontype
46 * @param string $workshopname
48 public function i_change_phase_in_workshop_to($workshopname, $phase) {
49 $workshopname = $this->escape($workshopname);
50 $phaseliteral = behat_context_helper::escape($phase);
52 $xpath = "//*[@class='userplan']/descendant::div[./span[contains(.,$phaseliteral)]]";
53 $continue = $this->escape(get_string('continue'));
55 $this->execute("behat_navigation::go_to_breadcrumb_location", $workshopname);
57 $this->execute('behat_general::i_click_on_in_the',
58 array('a.action-icon', "css_element", $this->escape($xpath), "xpath_element")
61 $this->execute("behat_forms::press_button", $continue);
64 /**
65 * Adds or edits a student workshop submission.
67 * @When /^I add a submission in workshop "(?P<workshop_name_string>(?:[^"]|\\")*)" as:"$/
68 * @param string $workshopname
69 * @param TableNode $table data to fill the submission form with, must contain 'Title'
71 public function i_add_a_submission_in_workshop_as($workshopname, $table) {
72 $workshopname = $this->escape($workshopname);
73 $savechanges = $this->escape(get_string('savechanges'));
74 $xpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' ownsubmission ')]/descendant::*[@type='submit']";
76 $this->execute("behat_navigation::go_to_breadcrumb_location", $workshopname);
78 $this->execute("behat_general::i_click_on", array($xpath, "xpath_element"));
80 $this->execute("behat_forms::i_set_the_following_fields_to_these_values", $table);
82 $this->execute("behat_forms::press_button", $savechanges);
85 /**
86 * Sets the workshop assessment form.
88 * @When /^I edit assessment form in workshop "(?P<workshop_name_string>(?:[^"]|\\")*)" as:"$/
89 * @param string $workshopname
90 * @param TableNode $table data to fill the submission form with, must contain 'Title'
92 public function i_edit_assessment_form_in_workshop_as($workshopname, $table) {
93 $this->execute("behat_navigation::i_am_on_page_instance", [$this->escape($workshopname), 'workshop activity']);
95 $this->execute('behat_navigation::i_navigate_to_in_current_page_administration',
96 get_string('editassessmentform', 'workshop'));
98 $this->execute("behat_forms::i_set_the_following_fields_to_these_values", $table);
100 $this->execute("behat_forms::press_button", get_string('saveandclose', 'workshop'));
104 * Peer-assesses a workshop submission.
106 * @When /^I assess submission "(?P<submission_string>(?:[^"]|\\")*)" in workshop "(?P<workshop_name_string>(?:[^"]|\\")*)" as:"$/
107 * @param string $submission
108 * @param string $workshopname
109 * @param TableNode $table
111 public function i_assess_submission_in_workshop_as($submission, $workshopname, TableNode $table) {
112 $workshopname = $this->escape($workshopname);
113 $submissionliteral = behat_context_helper::escape($submission);
114 $xpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' assessment-summary ') ".
115 "and contains(.,$submissionliteral)]";
116 $assess = $this->escape(get_string('assess', 'workshop'));
117 $saveandclose = $this->escape(get_string('saveandclose', 'workshop'));
119 $this->execute("behat_navigation::go_to_breadcrumb_location", $workshopname);
121 $this->execute('behat_general::i_click_on_in_the',
122 array($assess, "button", $xpath, "xpath_element")
125 $this->execute("behat_forms::i_set_the_following_fields_to_these_values", $table);
127 $this->execute("behat_forms::press_button", $saveandclose);
131 * Checks that the user has particular grade set by his reviewing peer in workshop
133 * @Then /^I should see grade "(?P<grade_string>[^"]*)" for workshop participant "(?P<participant_name_string>(?:[^"]|\\")*)" set by peer "(?P<reviewer_name_string>(?:[^"]|\\")*)"$/
134 * @param string $grade
135 * @param string $participant
136 * @param string $reviewer
138 public function i_should_see_grade_for_workshop_participant_set_by_peer($grade, $participant, $reviewer) {
139 $participantliteral = behat_context_helper::escape($participant);
140 $reviewerliteral = behat_context_helper::escape($reviewer);
141 $gradeliteral = behat_context_helper::escape($grade);
142 $participantselector = "contains(concat(' ', normalize-space(@class), ' '), ' participant ') ".
143 "and contains(.,$participantliteral)";
144 $trxpath = "//table/tbody/tr[td[$participantselector]]";
145 $tdparticipantxpath = "//table/tbody/tr/td[$participantselector]";
146 $tdxpath = "/td[contains(concat(' ', normalize-space(@class), ' '), ' receivedgrade ') and contains(.,$reviewerliteral)]/".
147 "descendant::span[contains(concat(' ', normalize-space(@class), ' '), ' grade ') and .=$gradeliteral]";
149 $tr = $this->find('xpath', $trxpath);
150 $rowspan = $this->find('xpath', $tdparticipantxpath)->getAttribute('rowspan');
152 $xpath = $trxpath.$tdxpath;
153 if (!empty($rowspan)) {
154 for ($i = 1; $i < $rowspan; $i++) {
155 $xpath .= ' | '.$trxpath."/following-sibling::tr[$i]".$tdxpath;
158 $this->find('xpath', $xpath);
162 * Configure portfolio plugin, set value for portfolio instance
164 * @When /^I set portfolio instance "(?P<portfolioinstance_string>(?:[^"]|\\")*)" to "(?P<value_string>(?:[^"]|\\")*)"$/
165 * @param string $portfolioinstance
166 * @param string $value
168 public function i_set_portfolio_instance_to($portfolioinstance, $value) {
170 $rowxpath = "//table[contains(@class, 'generaltable')]//tr//td[contains(text(), '"
171 . $portfolioinstance . "')]/following-sibling::td";
173 $selectxpath = $rowxpath.'//select';
174 $select = $this->find('xpath', $selectxpath);
175 $select->selectOption($value);
177 if (!$this->running_javascript()) {
178 $this->execute('behat_general::i_click_on_in_the',
179 array(get_string('go'), "button", $rowxpath, "xpath_element")