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 filters.
  19   *
  20   * @package    core
  21   * @category   test
  22   * @copyright  2018 the Open University
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  // Note: You cannot use MOODLE_INTERNAL test here, or include files which do so.
  27  // This file is required by behat before including /config.php.
  28  
  29  require_once (__DIR__ . '/../../behat/behat_base.php');
  30  
  31  /**
  32   * Steps definitions related to filters.
  33   *
  34   * @package    core
  35   * @category   test
  36   * @copyright  2018 the Open University
  37   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  38   */
  39  class behat_filters extends behat_base {
  40  
  41      /**
  42       * Set the global filter configuration.
  43       *
  44       * @Given /^the "(?P<filter_name>(?:[^"]|\\")*)" filter is "(on|off|disabled)"$/
  45       *
  46       * @param string $filtername the name of a filter, e.g. 'glossary'.
  47       * @param string $statename 'on', 'off' or 'disabled'.
  48       */
  49      public function the_filter_is($filtername, $statename) {
  50          require_once (__DIR__ . '/../../filterlib.php');
  51  
  52          switch ($statename) {
  53              case 'on':
  54                  $state = TEXTFILTER_ON;
  55                  break;
  56              case 'off':
  57                  $state = TEXTFILTER_OFF;
  58                  break;
  59              case 'disabled':
  60                  $state = TEXTFILTER_DISABLED;
  61                  break;
  62              default:
  63                  throw new coding_exception('Unknown filter state: ' . $statename);
  64          }
  65          filter_set_global_state($filtername, $state);
  66      }
  67  
  68      /**
  69       * Set the global filter target.
  70       *
  71       * @Given /^the "(?P<filter_name>(?:[^"]|\\")*)" filter applies to "(content|content and headings)"$/
  72       *
  73       * @param string $filtername the name of a filter, e.g. 'glossary'.
  74       * @param string $filtertarget 'content' or 'content and headings'.
  75       */
  76      public function the_filter_applies_to($filtername, $filtertarget) {
  77          switch ($filtertarget) {
  78              case 'content and headings':
  79                  filter_set_applies_to_strings($filtername, 1);
  80                  break;
  81              case 'content':
  82                  filter_set_applies_to_strings($filtername, 0);
  83                  break;
  84              default:
  85                  throw new coding_exception('Unknown filter target: ' . $filtertarget);
  86          }
  87      }
  88  }