[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
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 28 require_once (__DIR__ . '/../../../lib/behat/behat_base.php'); 29 30 use Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException, 31 Behat\Behat\Context\Step\Given as Given, 32 Behat\Behat\Context\Step\Then as Then, 33 Behat\Gherkin\Node\TableNode as TableNode; 34 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 */ 43 class behat_deprecated extends behat_base { 44 45 /** 46 * Click on the specified element inside a table row containing the specified text. 47 * 48 * @deprecated since Moodle 2.7 MDL-42627 49 * @todo MDL-42862 This will be deleted in Moodle 2.9 50 * @see behat_general::i_click_on_in_the() 51 * 52 * @Given /^I click on "(?P<element_string>(?:[^"]|\\")*)" "(?P<selector_string>(?:[^"]|\\")*)" in the "(?P<row_text_string>(?:[^"]|\\")*)" table row$/ 53 * @throws ElementNotFoundException 54 * @param string $element Element we look for 55 * @param string $selectortype The type of what we look for 56 * @param string $tablerowtext The table row text 57 */ 58 public function i_click_on_in_the_table_row($element, $selectortype, $tablerowtext) { 59 60 // Throw an exception if deprecated methods are not allowed otherwise allow it's execution. 61 $alternative = 'I click on "' . $this->escape($element) . '" "' . $this->escape($selectortype) . 62 '" in the "' . $this->escape($tablerowtext) . '" "table_row"'; 63 $this->deprecated_message($alternative); 64 65 return new Given($alternative); 66 } 67 68 /** 69 * Goes to notification page ensuring site admin navigation is loaded. 70 * 71 * Step [I expand "Site administration" node] will ensure that administration menu 72 * is opened in both javascript and non-javascript modes. 73 * 74 * @deprecated since 2.7 75 * @todo MDL-42862 This will be deleted in Moodle 2.9 76 * 77 * @Given /^I go to notifications page$/ 78 * @return Given[] 79 */ 80 public function i_go_to_notifications_page() { 81 $alternative = array( 82 'I expand "' . get_string('administrationsite') . '" node', 83 'I click on "' . get_string('notifications') . '" "link" in the "'.get_string('administration').'" "block"' 84 ); 85 $this->deprecated_message($alternative); 86 return array( 87 new Given($alternative[0]), 88 new Given($alternative[1]), 89 ); 90 } 91 92 /** 93 * Adds the specified file from the 'Recent files' repository to the specified filepicker of the current page. 94 * 95 * @deprecated since 2.7 96 * @todo MDL-42862 This will be deleted in Moodle 2.9 97 * @see behat_filepicker::i_add_file_from_repository_to_filemanager() 98 * 99 * @When /^I add "(?P<filename_string>(?:[^"]|\\")*)" file from recent files to "(?P<filepicker_field_string>(?:[^"]|\\")*)" filepicker$/ 100 * @param string $filename 101 * @param string $filepickerelement 102 */ 103 public function i_add_file_from_recent_files_to_filepicker($filename, $filepickerelement) { 104 $reponame = get_string('pluginname', 'repository_recent'); 105 $alternative = 'I add "' . $this->escape($filename) . '" file from "' . 106 $reponame . '" to "' . $this->escape($filepickerelement) . '" filemanager'; 107 $this->deprecated_message($alternative); 108 return array( 109 new Given($alternative) 110 ); 111 } 112 113 /** 114 * Uploads a file to the specified filemanager leaving other fields in upload form default. The paths should be relative to moodle codebase. 115 * 116 * @deprecated since 2.7 117 * @todo MDL-42862 This will be deleted in Moodle 2.9 118 * @see behat_repository_upload::i_upload_file_to_filemanager() 119 * 120 * @When /^I upload "(?P<filepath_string>(?:[^"]|\\")*)" file to "(?P<filepicker_field_string>(?:[^"]|\\")*)" filepicker$/ 121 * @throws ExpectationException Thrown by behat_base::find 122 * @param string $filepath 123 * @param string $filepickerelement 124 */ 125 public function i_upload_file_to_filepicker($filepath, $filepickerelement) { 126 $alternative = 'I upload "' . $this->escape($filepath) . '" file to "' . 127 $this->escape($filepickerelement) . '" filemanager'; 128 $this->deprecated_message($alternative); 129 return array( 130 new Given($alternative) 131 ); 132 } 133 134 /** 135 * Creates a folder with specified name in the current folder and in the specified filepicker field. 136 * 137 * @deprecated since 2.7 138 * @todo MDL-42862 This will be deleted in Moodle 2.9 139 * @see behat_filepicker::i_create_folder_in_filemanager() 140 * 141 * @Given /^I create "(?P<foldername_string>(?:[^"]|\\")*)" folder in "(?P<filepicker_field_string>(?:[^"]|\\")*)" filepicker$/ 142 * @throws ExpectationException Thrown by behat_base::find 143 * @param string $foldername 144 * @param string $filepickerelement 145 */ 146 public function i_create_folder_in_filepicker($foldername, $filepickerelement) { 147 $alternative = 'I create "' . $this->escape($foldername) . 148 '" folder in "' . $this->escape($filepickerelement) . '" filemanager'; 149 $this->deprecated_message($alternative); 150 return array(new Given($alternative)); 151 } 152 153 /** 154 * Opens the contents of a filepicker folder. It looks for the folder in the current folder and in the path bar. 155 * 156 * @deprecated since 2.7 157 * @todo MDL-42862 This will be deleted in Moodle 2.9 158 * @see behat_filepicker::i_open_folder_from_filemanager() 159 * 160 * @Given /^I open "(?P<foldername_string>(?:[^"]|\\")*)" folder from "(?P<filepicker_field_string>(?:[^"]|\\")*)" filepicker$/ 161 * @throws ExpectationException Thrown by behat_base::find 162 * @param string $foldername 163 * @param string $filepickerelement 164 */ 165 public function i_open_folder_from_filepicker($foldername, $filepickerelement) { 166 $alternative = 'I open "' . $this->escape($foldername) . '" folder from "' . 167 $this->escape($filepickerelement) . '" filemanager'; 168 $this->deprecated_message($alternative); 169 return array(new Given($alternative)); 170 } 171 172 /** 173 * Unzips the specified file from the specified filepicker field. The zip file has to be visible in the current folder. 174 * 175 * @deprecated since 2.7 176 * @todo MDL-42862 This will be deleted in Moodle 2.9 177 * @see behat_filepicker::i_unzip_file_from_filemanager() 178 * 179 * @Given /^I unzip "(?P<filename_string>(?:[^"]|\\")*)" file from "(?P<filepicker_field_string>(?:[^"]|\\")*)" filepicker$/ 180 * @throws ExpectationException Thrown by behat_base::find 181 * @param string $filename 182 * @param string $filepickerelement 183 */ 184 public function i_unzip_file_from_filepicker($filename, $filepickerelement) { 185 $alternative = 'I unzip "' . $this->escape($filename) . '" file from "' . 186 $this->escape($filepickerelement) . '" filemanager'; 187 $this->deprecated_message($alternative); 188 return array(new Given($alternative)); 189 } 190 191 /** 192 * Zips the specified folder from the specified filepicker field. The folder has to be in the current folder. 193 * 194 * @deprecated since 2.7 195 * @todo MDL-42862 This will be deleted in Moodle 2.9 196 * @see behat_filepicker::i_zip_folder_from_filemanager() 197 * 198 * @Given /^I zip "(?P<filename_string>(?:[^"]|\\")*)" folder from "(?P<filepicker_field_string>(?:[^"]|\\")*)" filepicker$/ 199 * @throws ExpectationException Thrown by behat_base::find 200 * @param string $foldername 201 * @param string $filepickerelement 202 */ 203 public function i_zip_folder_from_filepicker($foldername, $filepickerelement) { 204 $alternative = 'I zip "' . $this->escape($foldername) . '" folder from "' . 205 $this->escape($filepickerelement) . '" filemanager'; 206 $this->deprecated_message($alternative); 207 return array(new Given($alternative)); 208 } 209 210 /** 211 * Deletes the specified file or folder from the specified filepicker field. 212 * 213 * @deprecated since 2.7 214 * @todo MDL-42862 This will be deleted in Moodle 2.9 215 * @see behat_filepicker::i_delete_file_from_filemanager() 216 * 217 * @Given /^I delete "(?P<file_or_folder_name_string>(?:[^"]|\\")*)" from "(?P<filepicker_field_string>(?:[^"]|\\")*)" filepicker$/ 218 * @throws ExpectationException Thrown by behat_base::find 219 * @param string $name 220 * @param string $filepickerelement 221 */ 222 public function i_delete_file_from_filepicker($name, $filepickerelement) { 223 $alternative = 'I delete "' . $this->escape($name) . '" from "' . 224 $this->escape($filepickerelement) . '" filemanager'; 225 $this->deprecated_message($alternative); 226 return array(new Given($alternative)); 227 } 228 229 /** 230 * Sends a message to the specified user from the logged user. 231 * 232 * @deprecated since 2.7 233 * @todo MDL-42862 This will be deleted in Moodle 2.9 234 * @see behat_message::i_send_message_to_user() 235 * 236 * @Given /^I send "(?P<message_contents_string>(?:[^"]|\\")*)" message to "(?P<username_string>(?:[^"]|\\")*)"$/ 237 * @throws ElementNotFoundException 238 * @param string $messagecontent 239 * @param string $tousername 240 */ 241 public function i_send_message_to_user($messagecontent, $tousername) { 242 243 global $DB; 244 245 // Runs by CLI, same PHP process that created the user. 246 $touser = $DB->get_record('user', array('username' => $tousername)); 247 if (!$touser) { 248 throw new ElementNotFoundException($this->getSession(), '"' . $tousername . '" '); 249 } 250 $tofullname = fullname($touser); 251 252 $alternative = 'I send "' . $this->escape($messagecontent) . '" message to "' . $tofullname . '" user'; 253 $this->deprecated_message($alternative); 254 return new Given($alternative); 255 } 256 257 /** 258 * Adds the user to the specified cohort. 259 * 260 * @deprecated since 2.7 261 * @todo MDL-42862 This will be deleted in Moodle 2.9 262 * @see behat_cohort::i_add_user_to_cohort_members() 263 * 264 * @Given /^I add "(?P<user_username_string>(?:[^"]|\\")*)" user to "(?P<cohort_idnumber_string>(?:[^"]|\\")*)" cohort$/ 265 * @param string $username 266 * @param string $cohortidnumber 267 */ 268 public function i_add_user_to_cohort($username, $cohortidnumber) { 269 global $DB; 270 271 // The user was created by the data generator, executed by the same PHP process that is 272 // running this step, not by any Selenium action. 273 $user = $DB->get_record('user', array('username' => $username)); 274 $userlocator = $user->firstname . ' ' . $user->lastname . ' (' . $user->email . ')'; 275 276 $alternative = 'I add "' . $this->escape($userlocator) . 277 '" user to "' . $this->escape($cohortidnumber) . '" cohort members'; 278 $this->deprecated_message($alternative); 279 280 return new Given($alternative); 281 } 282 283 /** 284 * Add the specified user to the group. You should be in the groups page when running this step. 285 * 286 * @deprecated since 2.7 287 * @todo MDL-42862 This will be deleted in Moodle 2.9 288 * @see behat_groups::i_add_user_to_group_members() 289 * 290 * @Given /^I add "(?P<username_string>(?:[^"]|\\")*)" user to "(?P<group_name_string>(?:[^"]|\\")*)" group$/ 291 * @param string $username 292 * @param string $groupname 293 */ 294 public function i_add_user_to_group($username, $groupname) { 295 global $DB; 296 297 $user = $DB->get_record('user', array('username' => $username)); 298 $userfullname = fullname($user); 299 300 $alternative = 'I add "' . $this->escape($userfullname) . 301 '" user to "' . $this->escape($groupname) . '" group members'; 302 $this->deprecated_message($alternative); 303 304 return new Given($alternative); 305 } 306 307 /** 308 * Fills in form text field with specified id|name|label|value. It works with text-based fields. 309 * 310 * @deprecated since 2.7 311 * @todo MDL-42862 This will be deleted in Moodle 2.9 312 * @see behat_forms::i_set_the_field_to() 313 * 314 * @When /^I fill in "(?P<field_string>(?:[^"]|\\")*)" with "(?P<value_string>(?:[^"]|\\")*)"$/ 315 * @throws ElementNotFoundException Thrown by behat_base::find 316 * @param string $field 317 * @param string $value 318 */ 319 public function fill_field($field, $value) { 320 $alternative = 'I set the field "' . $this->escape($field) . '" to "' . $this->escape($value) . '"'; 321 $this->deprecated_message($alternative); 322 323 return new Given($alternative); 324 } 325 326 /** 327 * Selects option in select field with specified id|name|label|value. 328 * 329 * @deprecated since 2.7 330 * @todo MDL-42862 This will be deleted in Moodle 2.9 331 * @see behat_forms::i_set_the_field_to() 332 * 333 * @When /^I select "(?P<option_string>(?:[^"]|\\")*)" from "(?P<select_string>(?:[^"]|\\")*)"$/ 334 * @throws ElementNotFoundException Thrown by behat_base::find 335 * @param string $option 336 * @param string $select 337 */ 338 public function select_option($option, $select) { 339 $alternative = 'I set the field "' . $this->escape($select) . '" to "' . $this->escape($option) . '"'; 340 $this->deprecated_message($alternative); 341 342 return new Given($alternative); 343 } 344 345 /** 346 * Selects the specified id|name|label from the specified radio button. 347 * 348 * @deprecated since 2.7 349 * @todo MDL-42862 This will be deleted in Moodle 2.9 350 * @see behat_forms::i_set_the_field_to() 351 * 352 * @When /^I select "(?P<radio_button_string>(?:[^"]|\\")*)" radio button$/ 353 * @throws ElementNotFoundException Thrown by behat_base::find 354 * @param string $radio The radio button id, name or label value 355 */ 356 public function select_radio($radio) { 357 $alternative = 'I set the field "' . $this->escape($radio) . '" to "1"'; 358 $this->deprecated_message($alternative); 359 360 return new Given($alternative); 361 } 362 363 /** 364 * Checks checkbox with specified id|name|label|value. 365 * 366 * @deprecated since 2.7 367 * @todo MDL-42862 This will be deleted in Moodle 2.9 368 * @see behat_forms::i_set_the_field_to() 369 * 370 * @When /^I check "(?P<option_string>(?:[^"]|\\")*)"$/ 371 * @throws ElementNotFoundException Thrown by behat_base::find 372 * @param string $option 373 */ 374 public function check_option($option) { 375 $alternative = 'I set the field "' . $this->escape($option) . '" to "1"'; 376 $this->deprecated_message($alternative); 377 378 return new Given($alternative); 379 } 380 381 /** 382 * Unchecks checkbox with specified id|name|label|value. 383 * 384 * @deprecated since 2.7 385 * @todo MDL-42862 This will be deleted in Moodle 2.9 386 * @see behat_forms::i_set_the_field_to() 387 * 388 * @When /^I uncheck "(?P<option_string>(?:[^"]|\\")*)"$/ 389 * @throws ElementNotFoundException Thrown by behat_base::find 390 * @param string $option 391 */ 392 public function uncheck_option($option) { 393 $alternative = 'I set the field "' . $this->escape($option) . '" to ""'; 394 $this->deprecated_message($alternative); 395 396 return new Given($alternative); 397 } 398 399 /** 400 * Checks that the field matches the specified value. When using multi-select fields use commas to separate selected options. 401 * 402 * @deprecated since 2.7 403 * @todo MDL-42862 This will be deleted in Moodle 2.9 404 * @see behat_forms::the_field_matches_value() 405 * 406 * @Then /^the "(?P<field_string>(?:[^"]|\\")*)" field should match "(?P<value_string>(?:[^"]|\\")*)" value$/ 407 * @throws ExpectationException 408 * @throws ElementNotFoundException Thrown by behat_base::find 409 * @param string $locator 410 * @param string $value 411 */ 412 public function the_field_should_match_value($locator, $value) { 413 $alternative = 'the field "' . $this->escape($locator) . '" matches value "' . $this->escape($value) . '"'; 414 $this->deprecated_message($alternative); 415 416 return new Then($alternative); 417 } 418 419 /** 420 * Checks, that checkbox with specified in|name|label|value is checked. 421 * 422 * @deprecated since 2.7 423 * @todo MDL-42862 This will be deleted in Moodle 2.9 424 * @see behat_forms::the_field_matches_value() 425 * 426 * @Then /^the "(?P<checkbox_string>(?:[^"]|\\")*)" checkbox should be checked$/ 427 * @param string $checkbox 428 */ 429 public function assert_checkbox_checked($checkbox) { 430 $alternative = 'the field "' . $this->escape($checkbox) . '" matches value "1"'; 431 $this->deprecated_message($alternative); 432 433 return new Then($alternative); 434 } 435 436 /** 437 * Checks, that checkbox with specified in|name|label|value is unchecked. 438 * 439 * @deprecated since 2.7 440 * @todo MDL-42862 This will be deleted in Moodle 2.9 441 * @see behat_forms::the_field_matches_value() 442 * 443 * @Then /^the "(?P<checkbox_string>(?:[^"]|\\")*)" checkbox should not be checked$/ 444 * @param string $checkbox 445 */ 446 public function assert_checkbox_not_checked($checkbox) { 447 $alternative = 'the field "' . $this->escape($checkbox) . '" matches value ""'; 448 $this->deprecated_message($alternative); 449 450 return new Then($alternative); 451 } 452 453 /** 454 * Fills a moodle form with field/value data. 455 * 456 * @deprecated since 2.7 457 * @todo MDL-42862 This will be deleted in Moodle 2.9 458 * @see behat_forms::i_set_the_following_fields_to_these_values() 459 * 460 * @Given /^I fill the moodle form with:$/ 461 * @throws ElementNotFoundException Thrown by behat_base::find 462 * @param TableNode $data 463 */ 464 public function i_fill_the_moodle_form_with(TableNode $data) { 465 $alternative = 'I set the following fields to these values:'; 466 $this->deprecated_message($alternative); 467 468 return new Given($alternative, $data); 469 } 470 471 /** 472 * Checks the provided element and selector type exists in the current page. 473 * 474 * This step is for advanced users, use it if you don't find anything else suitable for what you need. 475 * 476 * @Then /^"(?P<element_string>(?:[^"]|\\")*)" "(?P<selector_string>[^"]*)" should exists$/ 477 * @throws ElementNotFoundException Thrown by behat_base::find 478 * @param string $element The locator of the specified selector 479 * @param string $selectortype The selector type 480 */ 481 public function should_exists($element, $selectortype) { 482 $alternative = '"' . $this->escape($element) . '" "' . $this->escape($selectortype) . '" should exist'; 483 $this->deprecated_message($alternative); 484 return new Then($alternative); 485 } 486 487 /** 488 * Checks that the provided element and selector type not exists in the current page. 489 * 490 * This step is for advanced users, use it if you don't find anything else suitable for what you need. 491 * 492 * @Then /^"(?P<element_string>(?:[^"]|\\")*)" "(?P<selector_string>[^"]*)" should not exists$/ 493 * @throws ExpectationException 494 * @param string $element The locator of the specified selector 495 * @param string $selectortype The selector type 496 */ 497 public function should_not_exists($element, $selectortype) { 498 $alternative = '"' . $this->escape($element) . '" "' . $this->escape($selectortype) . '" should not exist'; 499 $this->deprecated_message($alternative); 500 return new Then($alternative); 501 } 502 503 /** 504 * Creates the specified element. More info about available elements in http://docs.moodle.org/dev/Acceptance_testing#Fixtures. 505 * 506 * @Given /^the following "(?P<element_string>(?:[^"]|\\")*)" exists:$/ 507 * 508 * @throws Exception 509 * @throws PendingException 510 * @param string $elementname The name of the entity to add 511 * @param TableNode $data 512 */ 513 public function the_following_exists($elementname, TableNode $data) { 514 $alternative = 'the following "' . $this->escape($elementname) . '" exist:'; 515 $this->deprecated_message($alternative); 516 return new Given($alternative, $data); 517 } 518 519 /** 520 * Throws an exception if $CFG->behat_usedeprecated is not allowed. 521 * 522 * @throws Exception 523 * @param string|array $alternatives Alternative/s to the requested step 524 * @return void 525 */ 526 protected function deprecated_message($alternatives) { 527 global $CFG; 528 529 // We do nothing if it is enabled. 530 if (!empty($CFG->behat_usedeprecated)) { 531 return; 532 } 533 534 if (is_scalar($alternatives)) { 535 $alternatives = array($alternatives); 536 } 537 538 $message = 'Deprecated step, rather than using this step you can:'; 539 foreach ($alternatives as $alternative) { 540 $message .= PHP_EOL . '- ' . $alternative; 541 } 542 $message .= PHP_EOL . '- Set $CFG->behat_usedeprecated in config.php to allow the use of deprecated steps if you don\'t have any other option'; 543 throw new Exception($message); 544 } 545 546 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |