MDL-69521 core: Move all comments in code from 4.1 to 3.11
[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
fcb6ed47 30use Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException,
e259795c 31 Behat\Gherkin\Node\TableNode as TableNode,
5fa90114 32 Behat\Gherkin\Node\PyStringNode as PyStringNode;
e7c71c44 33
c3a40dea
DM
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 */
42class behat_deprecated extends behat_base {
43
c8edee42
MM
44 /**
45 * Docks a block. Editing mode should be previously enabled.
46 * @throws ExpectationException
47 * @param string $blockname
48 * @return void
49 * @deprecated since Moodle 3.7 MDL-64506 - please do not use this definition step any more.
74ee34fd 50 * @todo MDL-65215 This will be deleted in Moodle 3.11.
c8edee42
MM
51 */
52 public function i_dock_block($blockname) {
53
54 $message = "Block docking is no longer used as of MDL-64506. Please update your tests.";
55 $this->deprecated_message($message);
56
57 // Looking for both title and alt.
58 $xpath = "//input[@type='image'][@title='" . get_string('dockblock', 'block', $blockname) . "' or @alt='" . get_string('addtodock', 'block') . "']";
59 $this->execute('behat_general::i_click_on_in_the',
60 array($xpath, "xpath_element", $this->escape($blockname), "block")
61 );
62 }
63
c3a40dea
DM
64 /**
65 * Throws an exception if $CFG->behat_usedeprecated is not allowed.
66 *
67 * @throws Exception
68 * @param string|array $alternatives Alternative/s to the requested step
1973a7e2 69 * @param bool $throwexception If set to true we always throw exception, irrespective of behat_usedeprecated setting.
c3a40dea
DM
70 * @return void
71 */
1973a7e2 72 protected function deprecated_message($alternatives, $throwexception = false) {
c3a40dea
DM
73 global $CFG;
74
75 // We do nothing if it is enabled.
1973a7e2 76 if (!empty($CFG->behat_usedeprecated) && !$throwexception) {
c3a40dea
DM
77 return;
78 }
79
80 if (is_scalar($alternatives)) {
81 $alternatives = array($alternatives);
82 }
83
1973a7e2
AA
84 // Show an appropriate message based on the throwexception flag.
85 if ($throwexception) {
86 $message = 'This step has been removed. Rather than using this step you can:';
87 } else {
88 $message = 'Deprecated step, rather than using this step you can:';
89 }
90
91 // Add all alternatives to the message.
c3a40dea
DM
92 foreach ($alternatives as $alternative) {
93 $message .= PHP_EOL . '- ' . $alternative;
94 }
1973a7e2
AA
95
96 if (!$throwexception) {
97 $message .= PHP_EOL . '- Set $CFG->behat_usedeprecated in config.php to allow the use of deprecated steps
98 if you don\'t have any other option';
99 }
100
c3a40dea
DM
101 throw new Exception($message);
102 }
103
104}