MDL-50163 behat: Return subcontext from session
[moodle.git] / lib / tests / behat / behat_deprecated.php
CommitLineData
c3a40dea
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 * Steps definitions that will be deprecated in the next releases.
19 *
20 * @package core
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
fcb6ed47 30use Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException,
a5254141 31 Behat\Behat\Context\Step\Given as Given,
12427e77
DM
32 Behat\Behat\Context\Step\Then as Then,
33 Behat\Gherkin\Node\TableNode as TableNode;
e7c71c44 34
c3a40dea
DM
35/**
36 * Deprecated behat step definitions.
37 *
38 * @package core
39 * @category test
40 * @copyright 2013 David MonllaĆ³
41 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
42 */
43class behat_deprecated extends behat_base {
44
e7c71c44 45 /**
e7c71c44 46 * @Given /^I click on "(?P<element_string>(?:[^"]|\\")*)" "(?P<selector_string>(?:[^"]|\\")*)" in the "(?P<row_text_string>(?:[^"]|\\")*)" table row$/
88b12253 47 * @deprecated since Moodle 2.7 MDL-42627 - please do not use this step any more.
e7c71c44
DM
48 */
49 public function i_click_on_in_the_table_row($element, $selectortype, $tablerowtext) {
e7c71c44
DM
50 $alternative = 'I click on "' . $this->escape($element) . '" "' . $this->escape($selectortype) .
51 '" in the "' . $this->escape($tablerowtext) . '" "table_row"';
88b12253 52 $this->deprecated_message($alternative, true);
e7c71c44
DM
53 }
54
6dfd8325 55 /**
6dfd8325 56 * @Given /^I go to notifications page$/
88b12253 57 * @deprecated since Moodle 2.7 MDL-42731 - please do not use this step any more.
6dfd8325
MG
58 */
59 public function i_go_to_notifications_page() {
60 $alternative = array(
61 'I expand "' . get_string('administrationsite') . '" node',
62 'I click on "' . get_string('notifications') . '" "link" in the "'.get_string('administration').'" "block"'
63 );
88b12253 64 $this->deprecated_message($alternative, true);
6dfd8325
MG
65 }
66
fcb6ed47 67 /**
fcb6ed47 68 * @When /^I add "(?P<filename_string>(?:[^"]|\\")*)" file from recent files to "(?P<filepicker_field_string>(?:[^"]|\\")*)" filepicker$/
88b12253 69 * @deprecated since Moodle 2.7 MDL-42174 - please do not use this step any more.
fcb6ed47
MG
70 */
71 public function i_add_file_from_recent_files_to_filepicker($filename, $filepickerelement) {
72 $reponame = get_string('pluginname', 'repository_recent');
73 $alternative = 'I add "' . $this->escape($filename) . '" file from "' .
74 $reponame . '" to "' . $this->escape($filepickerelement) . '" filemanager';
88b12253 75 $this->deprecated_message($alternative, true);
07622451
MG
76 }
77
78 /**
07622451 79 * @When /^I upload "(?P<filepath_string>(?:[^"]|\\")*)" file to "(?P<filepicker_field_string>(?:[^"]|\\")*)" filepicker$/
88b12253 80 * @deprecated since Moodle 2.7 MDL-42174 - please do not use this step any more.
07622451
MG
81 */
82 public function i_upload_file_to_filepicker($filepath, $filepickerelement) {
83 $alternative = 'I upload "' . $this->escape($filepath) . '" file to "' .
84 $this->escape($filepickerelement) . '" filemanager';
88b12253 85 $this->deprecated_message($alternative, true);
fcb6ed47
MG
86 }
87
cde67a83 88 /**
cde67a83 89 * @Given /^I create "(?P<foldername_string>(?:[^"]|\\")*)" folder in "(?P<filepicker_field_string>(?:[^"]|\\")*)" filepicker$/
88b12253 90 * @deprecated since Moodle 2.7 MDL-42174 - please do not use this step any more.
cde67a83
MG
91 */
92 public function i_create_folder_in_filepicker($foldername, $filepickerelement) {
93 $alternative = 'I create "' . $this->escape($foldername) .
94 '" folder in "' . $this->escape($filepickerelement) . '" filemanager';
88b12253 95 $this->deprecated_message($alternative, true);
cde67a83
MG
96 }
97
98 /**
cde67a83 99 * @Given /^I open "(?P<foldername_string>(?:[^"]|\\")*)" folder from "(?P<filepicker_field_string>(?:[^"]|\\")*)" filepicker$/
88b12253 100 * @deprecated since Moodle 2.7 MDL-42174 - please do not use this step any more.
cde67a83
MG
101 */
102 public function i_open_folder_from_filepicker($foldername, $filepickerelement) {
103 $alternative = 'I open "' . $this->escape($foldername) . '" folder from "' .
104 $this->escape($filepickerelement) . '" filemanager';
88b12253 105 $this->deprecated_message($alternative, true);
cde67a83
MG
106 }
107
108 /**
cde67a83 109 * @Given /^I unzip "(?P<filename_string>(?:[^"]|\\")*)" file from "(?P<filepicker_field_string>(?:[^"]|\\")*)" filepicker$/
88b12253 110 * @deprecated since Moodle 2.7 MDL-42174 - please do not use this step any more.
cde67a83
MG
111 */
112 public function i_unzip_file_from_filepicker($filename, $filepickerelement) {
113 $alternative = 'I unzip "' . $this->escape($filename) . '" file from "' .
114 $this->escape($filepickerelement) . '" filemanager';
88b12253 115 $this->deprecated_message($alternative, true);
cde67a83
MG
116 }
117
118 /**
cde67a83 119 * @Given /^I zip "(?P<filename_string>(?:[^"]|\\")*)" folder from "(?P<filepicker_field_string>(?:[^"]|\\")*)" filepicker$/
88b12253 120 * @deprecated since Moodle 2.7 MDL-42174 - please do not use this step any more.
cde67a83
MG
121 */
122 public function i_zip_folder_from_filepicker($foldername, $filepickerelement) {
123 $alternative = 'I zip "' . $this->escape($foldername) . '" folder from "' .
124 $this->escape($filepickerelement) . '" filemanager';
88b12253 125 $this->deprecated_message($alternative, true);
cde67a83
MG
126 }
127
128 /**
cde67a83 129 * @Given /^I delete "(?P<file_or_folder_name_string>(?:[^"]|\\")*)" from "(?P<filepicker_field_string>(?:[^"]|\\")*)" filepicker$/
88b12253 130 * @deprecated since Moodle 2.7 MDL-42174 - please do not use this step any more.
cde67a83
MG
131 */
132 public function i_delete_file_from_filepicker($name, $filepickerelement) {
133 $alternative = 'I delete "' . $this->escape($name) . '" from "' .
134 $this->escape($filepickerelement) . '" filemanager';
88b12253 135 $this->deprecated_message($alternative, true);
cde67a83
MG
136 }
137
14ebd163 138 /**
14ebd163 139 * @Given /^I send "(?P<message_contents_string>(?:[^"]|\\")*)" message to "(?P<username_string>(?:[^"]|\\")*)"$/
88b12253 140 * @deprecated since Moodle 2.7 MDL-43584 - please do not use this step any more.
14ebd163
DM
141 */
142 public function i_send_message_to_user($messagecontent, $tousername) {
88b12253
AA
143 $alternative = 'I send "' . $this->escape($messagecontent) . '" message to "USER_FULL_NAME" user';
144 $this->deprecated_message($alternative, true);
14ebd163
DM
145 }
146
147 /**
14ebd163 148 * @Given /^I add "(?P<user_username_string>(?:[^"]|\\")*)" user to "(?P<cohort_idnumber_string>(?:[^"]|\\")*)" cohort$/
88b12253 149 * @deprecated since Moodle 2.7 MDL-43584 - please do not use this step any more.
14ebd163
DM
150 */
151 public function i_add_user_to_cohort($username, $cohortidnumber) {
88b12253
AA
152 $alternative = 'I add "USER_FIRST_NAME USER_LAST_NAME (USER_EMAIL)" user to "'
153 . $this->escape($cohortidnumber) . '" cohort members';
154 $this->deprecated_message($alternative, true);
14ebd163
DM
155 }
156
157 /**
14ebd163 158 * @Given /^I add "(?P<username_string>(?:[^"]|\\")*)" user to "(?P<group_name_string>(?:[^"]|\\")*)" group$/
88b12253 159 * @deprecated since Moodle 2.7 MDL-43584 - please do not use this step any more.
14ebd163
DM
160 */
161 public function i_add_user_to_group($username, $groupname) {
88b12253
AA
162 $alternative = 'I add "USER_FULL_NAME" user to "' . $this->escape($groupname) . '" group members';
163 $this->deprecated_message($alternative, true);
14ebd163
DM
164 }
165
a5254141 166 /**
a5254141 167 * @When /^I fill in "(?P<field_string>(?:[^"]|\\")*)" with "(?P<value_string>(?:[^"]|\\")*)"$/
88b12253 168 * @deprecated since Moodle 2.7 MDL-43738 - please do not use this step any more.
a5254141
DM
169 */
170 public function fill_field($field, $value) {
171 $alternative = 'I set the field "' . $this->escape($field) . '" to "' . $this->escape($value) . '"';
88b12253 172 $this->deprecated_message($alternative, true);
a5254141
DM
173 }
174
175 /**
a5254141 176 * @When /^I select "(?P<option_string>(?:[^"]|\\")*)" from "(?P<select_string>(?:[^"]|\\")*)"$/
88b12253 177 * @deprecated since Moodle 2.7 MDL-43738 - please do not use this step any more.
a5254141
DM
178 */
179 public function select_option($option, $select) {
180 $alternative = 'I set the field "' . $this->escape($select) . '" to "' . $this->escape($option) . '"';
88b12253 181 $this->deprecated_message($alternative, true);
a5254141
DM
182 }
183
184 /**
a5254141 185 * @When /^I select "(?P<radio_button_string>(?:[^"]|\\")*)" radio button$/
88b12253 186 * @deprecated since Moodle 2.7 MDL-43738 - please do not use this step any more.
a5254141
DM
187 */
188 public function select_radio($radio) {
189 $alternative = 'I set the field "' . $this->escape($radio) . '" to "1"';
88b12253 190 $this->deprecated_message($alternative, true);
a5254141
DM
191 }
192
193 /**
a5254141 194 * @When /^I check "(?P<option_string>(?:[^"]|\\")*)"$/
88b12253 195 * @deprecated since Moodle 2.7 MDL-43738 - please do not use this step any more.
a5254141
DM
196 */
197 public function check_option($option) {
198 $alternative = 'I set the field "' . $this->escape($option) . '" to "1"';
88b12253 199 $this->deprecated_message($alternative, true);
a5254141
DM
200 }
201
202 /**
a5254141 203 * @When /^I uncheck "(?P<option_string>(?:[^"]|\\")*)"$/
88b12253 204 * @deprecated since Moodle 2.7 MDL-43738 - please do not use this step any more.
a5254141
DM
205 */
206 public function uncheck_option($option) {
207 $alternative = 'I set the field "' . $this->escape($option) . '" to ""';
88b12253 208 $this->deprecated_message($alternative, true);
a5254141
DM
209 }
210
211 /**
a5254141 212 * @Then /^the "(?P<field_string>(?:[^"]|\\")*)" field should match "(?P<value_string>(?:[^"]|\\")*)" value$/
88b12253 213 * @deprecated since Moodle 2.7 MDL-43738 - please do not use this step any more.
a5254141
DM
214 */
215 public function the_field_should_match_value($locator, $value) {
216 $alternative = 'the field "' . $this->escape($locator) . '" matches value "' . $this->escape($value) . '"';
88b12253 217 $this->deprecated_message($alternative, true);
a5254141
DM
218 }
219
220 /**
a5254141 221 * @Then /^the "(?P<checkbox_string>(?:[^"]|\\")*)" checkbox should be checked$/
88b12253 222 * @deprecated since Moodle 2.7 MDL-43738 - please do not use this step any more.
a5254141
DM
223 */
224 public function assert_checkbox_checked($checkbox) {
225 $alternative = 'the field "' . $this->escape($checkbox) . '" matches value "1"';
88b12253 226 $this->deprecated_message($alternative, true);
a5254141
DM
227 }
228
229 /**
a5254141 230 * @Then /^the "(?P<checkbox_string>(?:[^"]|\\")*)" checkbox should not be checked$/
88b12253 231 * @deprecated since Moodle 2.7 MDL-43738 - please do not use this step any more.
a5254141
DM
232 */
233 public function assert_checkbox_not_checked($checkbox) {
234 $alternative = 'the field "' . $this->escape($checkbox) . '" matches value ""';
88b12253 235 $this->deprecated_message($alternative, true);
a5254141
DM
236 }
237
238 /**
a5254141 239 * @Given /^I fill the moodle form with:$/
88b12253 240 * @deprecated since Moodle 2.7 MDL-43738 - please do not use this step any more.
a5254141
DM
241 */
242 public function i_fill_the_moodle_form_with(TableNode $data) {
243 $alternative = 'I set the following fields to these values:';
88b12253 244 $this->deprecated_message($alternative, true);
a5254141
DM
245 }
246
c51c3b55 247 /**
c51c3b55 248 * @Then /^"(?P<element_string>(?:[^"]|\\")*)" "(?P<selector_string>[^"]*)" should exists$/
88b12253 249 * @deprecated since Moodle 2.7 MDL-43236 - please do not use this step any more.
c51c3b55
DM
250 */
251 public function should_exists($element, $selectortype) {
252 $alternative = '"' . $this->escape($element) . '" "' . $this->escape($selectortype) . '" should exist';
88b12253 253 $this->deprecated_message($alternative, true);
c51c3b55
DM
254 }
255
256 /**
c51c3b55 257 * @Then /^"(?P<element_string>(?:[^"]|\\")*)" "(?P<selector_string>[^"]*)" should not exists$/
88b12253 258 * @deprecated since Moodle 2.7 MDL-43236 - please do not use this step any more.
c51c3b55
DM
259 */
260 public function should_not_exists($element, $selectortype) {
261 $alternative = '"' . $this->escape($element) . '" "' . $this->escape($selectortype) . '" should not exist';
88b12253 262 $this->deprecated_message($alternative, true);
c51c3b55
DM
263 }
264
265 /**
c51c3b55 266 * @Given /^the following "(?P<element_string>(?:[^"]|\\")*)" exists:$/
88b12253 267 * @deprecated since Moodle 2.7 MDL-43236 - please do not use this step any more.
c51c3b55
DM
268 */
269 public function the_following_exists($elementname, TableNode $data) {
ced0f983 270 $alternative = 'the following "' . $this->escape($elementname) . '" exist:';
88b12253 271 $this->deprecated_message($alternative, true);
c51c3b55
DM
272 }
273
88b12253 274
c3a40dea
DM
275 /**
276 * Throws an exception if $CFG->behat_usedeprecated is not allowed.
277 *
278 * @throws Exception
279 * @param string|array $alternatives Alternative/s to the requested step
1973a7e2 280 * @param bool $throwexception If set to true we always throw exception, irrespective of behat_usedeprecated setting.
c3a40dea
DM
281 * @return void
282 */
1973a7e2 283 protected function deprecated_message($alternatives, $throwexception = false) {
c3a40dea
DM
284 global $CFG;
285
286 // We do nothing if it is enabled.
1973a7e2 287 if (!empty($CFG->behat_usedeprecated) && !$throwexception) {
c3a40dea
DM
288 return;
289 }
290
291 if (is_scalar($alternatives)) {
292 $alternatives = array($alternatives);
293 }
294
1973a7e2
AA
295 // Show an appropriate message based on the throwexception flag.
296 if ($throwexception) {
297 $message = 'This step has been removed. Rather than using this step you can:';
298 } else {
299 $message = 'Deprecated step, rather than using this step you can:';
300 }
301
302 // Add all alternatives to the message.
c3a40dea
DM
303 foreach ($alternatives as $alternative) {
304 $message .= PHP_EOL . '- ' . $alternative;
305 }
1973a7e2
AA
306
307 if (!$throwexception) {
308 $message .= PHP_EOL . '- Set $CFG->behat_usedeprecated in config.php to allow the use of deprecated steps
309 if you don\'t have any other option';
310 }
311
c3a40dea
DM
312 throw new Exception($message);
313 }
314
315}