Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

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

   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       * Throws an exception if $CFG->behat_usedeprecated is not allowed.
  46       *
  47       * @throws Exception
  48       * @param string|array $alternatives Alternative/s to the requested step
  49       * @param bool $throwexception If set to true we always throw exception, irrespective of behat_usedeprecated setting.
  50       * @return void
  51       */
  52      protected function deprecated_message($alternatives, $throwexception = false) {
  53          global $CFG;
  54  
  55          // We do nothing if it is enabled.
  56          if (!empty($CFG->behat_usedeprecated) && !$throwexception) {
  57              return;
  58          }
  59  
  60          if (is_scalar($alternatives)) {
  61              $alternatives = array($alternatives);
  62          }
  63  
  64          // Show an appropriate message based on the throwexception flag.
  65          if ($throwexception) {
  66              $message = 'This step has been removed. Rather than using this step you can:';
  67          } else {
  68              $message = 'Deprecated step, rather than using this step you can:';
  69          }
  70  
  71          // Add all alternatives to the message.
  72          foreach ($alternatives as $alternative) {
  73              $message .= PHP_EOL . '- ' . $alternative;
  74          }
  75  
  76          if (!$throwexception) {
  77              $message .= PHP_EOL . '- Set $CFG->behat_usedeprecated in config.php to allow the use of deprecated steps
  78                      if you don\'t have any other option';
  79          }
  80  
  81          throw new Exception($message);
  82      }
  83  
  84  }