MDL-62834 behat: Move include to function
[moodle.git] / lib / tests / behat / behat_filters.php
CommitLineData
8aedf6d4
TH
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
481548f5
AN
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.
8aedf6d4
TH
28
29require_once(__DIR__ . '/../../behat/behat_base.php');
8aedf6d4
TH
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 */
39class 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) {
481548f5
AN
50 require_once(__DIR__ . '/../../filterlib.php');
51
8aedf6d4
TH
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}