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