[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/tests/behat/ -> behat_deprecated.php (source)

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


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1