MDL-42627 behat: New steps definitions class for deprecated steps
[moodle.git] / lib / tests / behat / behat_deprecated.php
CommitLineData
c3a40dea
DM
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
28require_once(__DIR__ . '/../../../lib/behat/behat_base.php');
29
30/**
31 * Deprecated behat step definitions.
32 *
33 * @package core
34 * @category test
35 * @copyright 2013 David MonllaĆ³
36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 */
38class behat_deprecated extends behat_base {
39
40 /**
41 * Throws an exception if $CFG->behat_usedeprecated is not allowed.
42 *
43 * @throws Exception
44 * @param string|array $alternatives Alternative/s to the requested step
45 * @return void
46 */
47 protected function deprecated_message($alternatives) {
48 global $CFG;
49
50 // We do nothing if it is enabled.
51 if (!empty($CFG->behat_usedeprecated)) {
52 return;
53 }
54
55 if (is_scalar($alternatives)) {
56 $alternatives = array($alternatives);
57 }
58
59 $message = 'Deprecated step, rather than using this step you can:';
60 foreach ($alternatives as $alternative) {
61 $message .= PHP_EOL . '- ' . $alternative;
62 }
63 $message .= PHP_EOL . '- Set $CFG->behat_usedeprecated in config.php to allow the use of deprecated steps if you don\'t have any other option';
64 throw new Exception($message);
65 }
66
67}