2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * Steps definitions that will be deprecated in the next releases.
22 * @copyright 2013 David Monllaó
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 // NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
28 require_once(__DIR__ . '/../../../lib/behat/behat_base.php');
30 use Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException,
31 Behat\Gherkin\Node\TableNode as TableNode,
32 Behat\Gherkin\Node\PyStringNode as PyStringNode;
35 * Deprecated behat step definitions.
39 * @copyright 2013 David Monllaó
40 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
42 class behat_deprecated extends behat_base {
45 * Navigates to the course gradebook and selects a specified item from the grade navigation tabs.
46 * @Given /^I go to "(?P<gradepath_string>(?:[^"]|\\")*)" in the course gradebook$/
47 * @param string $gradepath
48 * @deprecated since Moodle 3.3 MDL-57282 - please do not use this step any more.
50 public function i_go_to_in_the_course_gradebook($gradepath) {
51 $alternative = 'I navigate to "' . $this->escape($gradepath) . '" in the course gradebook';
52 $this->deprecated_message($alternative);
54 $this->execute('behat_grade::i_navigate_to_in_the_course_gradebook', $gradepath);
58 * Click link in navigation tree that matches the text in parentnode/s (seperated using greater-than character if more than one)
60 * @Given /^I navigate to "(?P<nodetext_string>(?:[^"]|\\")*)" node in "(?P<parentnodes_string>(?:[^"]|\\")*)"$/
62 * @throws ExpectationException
63 * @param string $nodetext navigation node to click.
64 * @param string $parentnodes comma seperated list of parent nodes.
66 * @deprecated since Moodle 3.6 MDL-57281 - please do not use this definition step any more.
67 * @todo MDL-63004 This will be deleted in Moodle 4.0.
69 public function i_navigate_to_node_in($nodetext, $parentnodes) {
70 $alternative[] = 'I navigate to "PATH" in current page administration';
71 $alternative[] = 'I navigate to "PATH" in site administration';
72 $alternative[] = 'I navigate to "TAB1 > TAB2" in the course gradebook';
73 $alternative[] = 'I navigate to course participants';
74 $alternative[] = 'If some items are not available without Navigation block at all, one can use combination of:
75 I add the "Navigation" block if not present
76 I click on "LINK" "link" in the "Navigation" "block"';
78 $this->deprecated_message($alternative);
80 $parentnodes = array_map('trim', explode('>', $parentnodes));
81 $this->execute('behat_navigation::select_node_in_navigation', array($nodetext, $parentnodes));
85 * Throws an exception if $CFG->behat_usedeprecated is not allowed.
88 * @param string|array $alternatives Alternative/s to the requested step
89 * @param bool $throwexception If set to true we always throw exception, irrespective of behat_usedeprecated setting.
92 protected function deprecated_message($alternatives, $throwexception = false) {
95 // We do nothing if it is enabled.
96 if (!empty($CFG->behat_usedeprecated) && !$throwexception) {
100 if (is_scalar($alternatives)) {
101 $alternatives = array($alternatives);
104 // Show an appropriate message based on the throwexception flag.
105 if ($throwexception) {
106 $message = 'This step has been removed. Rather than using this step you can:';
108 $message = 'Deprecated step, rather than using this step you can:';
111 // Add all alternatives to the message.
112 foreach ($alternatives as $alternative) {
113 $message .= PHP_EOL . '- ' . $alternative;
116 if (!$throwexception) {
117 $message .= PHP_EOL . '- Set $CFG->behat_usedeprecated in config.php to allow the use of deprecated steps
118 if you don\'t have any other option';
121 throw new Exception($message);