Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 39 and 310] [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]

   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      Behat\Gherkin\Node\PyStringNode as PyStringNode;
  33  
  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   */
  42  class behat_deprecated extends behat_base {
  43  
  44      /**
  45       * Click link in navigation tree that matches the text in parentnode/s (seperated using greater-than character if more than one)
  46       *
  47       * @throws ExpectationException
  48       * @param string $nodetext navigation node to click.
  49       * @param string $parentnodes comma seperated list of parent nodes.
  50       * @return void
  51       * @deprecated since Moodle 3.6 MDL-57281 - please do not use this definition step any more.
  52       * @todo MDL-63004 This will be deleted in Moodle 4.0.
  53       */
  54      public function i_navigate_to_node_in($nodetext, $parentnodes) {
  55          $alternative[] = 'I navigate to "PATH" in current page administration';
  56          $alternative[] = 'I navigate to "PATH" in site administration';
  57          $alternative[] = 'I navigate to "TAB1 > TAB2" in the course gradebook';
  58          $alternative[] = 'I navigate to course participants';
  59          $alternative[] = 'If some items are not available without Navigation block at all, one can use combination of:
  60                                I add the "Navigation" block if not present
  61                                I click on "LINK" "link" in the "Navigation" "block"';
  62  
  63          $this->deprecated_message($alternative);
  64  
  65          $parentnodes = array_map('trim', explode('>', $parentnodes));
  66          $nodelist = array_merge($parentnodes, [$nodetext]);
  67          $firstnode = array_shift($nodelist);
  68  
  69          if ($firstnode === get_string('administrationsite')) {
  70              $this->execute('behat_theme_boost_behat_navigation::i_select_from_flat_navigation_drawer',
  71                      array(get_string('administrationsite')));
  72              $this->execute('behat_theme_boost_behat_navigation::select_on_administration_page', array($nodelist));
  73              return;
  74          }
  75  
  76          if ($firstnode === get_string('sitepages')) {
  77              if ($nodetext === get_string('calendar', 'calendar')) {
  78                  $this->execute('behat_theme_boost_behat_navigation::i_select_from_flat_navigation_drawer',
  79                          array(($nodetext)));
  80              } else {
  81                  // TODO MDL-57120 other links under "Site pages" are not accessible without navigation block.
  82                  $this->execute('behat_theme_boost_behat_navigation::select_node_in_navigation',
  83                          array($nodetext, $parentnodes));
  84              }
  85              return;
  86          }
  87  
  88          if ($firstnode === get_string('courseadministration')) {
  89              // Administration menu is available only on the main course page where settings in Administration
  90              // block (original purpose of the step) are available on every course page.
  91              $this->execute('behat_theme_boost_behat_navigation::go_to_main_course_page', array());
  92          }
  93  
  94          $this->execute('behat_theme_boost_behat_navigation::select_from_administration_menu', array($nodelist));
  95      }
  96  
  97      /**
  98       * Docks a block. Editing mode should be previously enabled.
  99       * @throws ExpectationException
 100       * @param string $blockname
 101       * @return void
 102       * @deprecated since Moodle 3.7 MDL-64506 - please do not use this definition step any more.
 103       * @todo MDL-65215 This will be deleted in Moodle 4.1.
 104       */
 105      public function i_dock_block($blockname) {
 106  
 107          $message = "Block docking is no longer used as of MDL-64506. Please update your tests.";
 108          $this->deprecated_message($message);
 109  
 110          // Looking for both title and alt.
 111          $xpath = "//input[@type='image'][@title='" . get_string('dockblock', 'block', $blockname) . "' or @alt='" . get_string('addtodock', 'block') . "']";
 112          $this->execute('behat_general::i_click_on_in_the',
 113                  array($xpath, "xpath_element", $this->escape($blockname), "block")
 114          );
 115      }
 116  
 117      /**
 118       * Throws an exception if $CFG->behat_usedeprecated is not allowed.
 119       *
 120       * @throws Exception
 121       * @param string|array $alternatives Alternative/s to the requested step
 122       * @param bool $throwexception If set to true we always throw exception, irrespective of behat_usedeprecated setting.
 123       * @return void
 124       */
 125      protected function deprecated_message($alternatives, $throwexception = false) {
 126          global $CFG;
 127  
 128          // We do nothing if it is enabled.
 129          if (!empty($CFG->behat_usedeprecated) && !$throwexception) {
 130              return;
 131          }
 132  
 133          if (is_scalar($alternatives)) {
 134              $alternatives = array($alternatives);
 135          }
 136  
 137          // Show an appropriate message based on the throwexception flag.
 138          if ($throwexception) {
 139              $message = 'This step has been removed. Rather than using this step you can:';
 140          } else {
 141              $message = 'Deprecated step, rather than using this step you can:';
 142          }
 143  
 144          // Add all alternatives to the message.
 145          foreach ($alternatives as $alternative) {
 146              $message .= PHP_EOL . '- ' . $alternative;
 147          }
 148  
 149          if (!$throwexception) {
 150              $message .= PHP_EOL . '- Set $CFG->behat_usedeprecated in config.php to allow the use of deprecated steps
 151                      if you don\'t have any other option';
 152          }
 153  
 154          throw new Exception($message);
 155      }
 156  
 157  }