Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 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.
   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 related to mod_quiz.
  19   *
  20   * @package   core_form
  21   * @category  test
  22   * @copyright 2020 The Open University
  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  require_once (__DIR__ . '/../../../../question/tests/behat/behat_question_base.php');
  30  
  31  use Behat\Gherkin\Node\TableNode as TableNode;
  32  
  33  use Behat\Mink\Exception\ExpectationException as ExpectationException;
  34  
  35  /**
  36   * Steps definitions related to core_form.
  37   */
  38  class behat_core_form extends behat_question_base {
  39  
  40      /**
  41       * Convert page names to URLs for steps like 'When I am on the "core_form > [page name]" page'.
  42       *
  43       * Recognised page names are:
  44       * | None so far!      |                                                              |
  45       *
  46       * @param string $page name of the page, with the component name removed e.g. 'Admin notification'.
  47       * @return moodle_url the corresponding URL.
  48       * @throws Exception with a meaningful error message if the specified page cannot be found.
  49       */
  50      protected function resolve_page_url(string $page): moodle_url {
  51          switch (strtolower($page)) {
  52              default:
  53                  throw new Exception('Unrecognised core_form page type "' . $page . '."');
  54          }
  55      }
  56  
  57      /**
  58       * Convert page names to URLs for steps like 'When I am on the "[identifier]" "core_form > [page type]" page'.
  59       *
  60       * Recognised page names are:
  61       * | pagetype | name meaning | description                         |
  62       * | Fixture  | script-name  | Fixture file name without extension |
  63       *
  64       * The fixture name should be the filename without path or extension. E.g.
  65       * autocomplete-disabledif for lib/form/tests/fixtures/autocomplete-disabledif.php.
  66       *
  67       * @param string $type identifies which type of page this is, e.g. 'Fixture'.
  68       * @param string $identifier identifies the particular page, e.g. 'autocomplete-disabledif'.
  69       * @return moodle_url the corresponding URL.
  70       * @throws Exception with a meaningful error message if the specified page cannot be found.
  71       */
  72      protected function resolve_page_instance_url(string $type, string $identifier): moodle_url {
  73          switch (strtolower($type)) {
  74              case 'fixture':
  75                  return new moodle_url('/lib/form/tests/fixtures/' .
  76                          clean_param($identifier, PARAM_ALPHAEXT) . '.php');
  77  
  78              default:
  79                  throw new Exception('Unrecognised core_form page type "' . $type . '."');
  80          }
  81      }
  82  }