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 related with blocks.
22 * @copyright 2012 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 use Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
30 require_once(__DIR__ . '/../../../lib/behat/behat_base.php');
33 * Blocks management steps definitions.
37 * @copyright 2012 David Monllaó
38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40 class behat_blocks extends behat_base {
43 * Adds the selected block. Editing mode must be previously enabled.
45 * @Given /^I add the "(?P<block_name_string>(?:[^"]|\\")*)" block$/
46 * @param string $blockname
48 public function i_add_the_block($blockname) {
49 $this->execute('behat_forms::i_set_the_field_to',
50 array("bui_addblock", $this->escape($blockname))
53 // If we are running without javascript we need to submit the form.
54 if (!$this->running_javascript()) {
55 $this->execute('behat_general::i_click_on_in_the',
56 array(get_string('go'), "button", "#add_block", "css_element")
62 * Adds the selected block if it is not already present. Editing mode must be previously enabled.
64 * @Given /^I add the "(?P<block_name_string>(?:[^"]|\\")*)" block if not present$/
65 * @param string $blockname
67 public function i_add_the_block_if_not_present($blockname) {
69 $this->get_text_selector_node('block', $blockname);
70 } catch (ElementNotFoundException $e) {
71 $this->execute('behat_blocks::i_add_the_block', [$blockname]);
76 * Docks a block. Editing mode should be previously enabled.
78 * @Given /^I dock "(?P<block_name_string>(?:[^"]|\\")*)" block$/
79 * @param string $blockname
81 public function i_dock_block($blockname) {
83 // Looking for both title and alt.
84 $xpath = "//input[@type='image'][@title='" . get_string('dockblock', 'block', $blockname) . "' or @alt='" . get_string('addtodock', 'block') . "']";
85 $this->execute('behat_general::i_click_on_in_the',
86 array($xpath, "xpath_element", $this->escape($blockname), "block")
91 * Opens a block's actions menu if it is not already opened.
93 * @Given /^I open the "(?P<block_name_string>(?:[^"]|\\")*)" blocks action menu$/
94 * @throws DriverException The step is not available when Javascript is disabled
95 * @param string $blockname
97 public function i_open_the_blocks_action_menu($blockname) {
99 if (!$this->running_javascript()) {
100 // Action menu does not need to be open if Javascript is off.
104 // If it is already opened we do nothing.
105 $blocknode = $this->get_text_selector_node('block', $blockname);
106 if ($blocknode->hasClass('action-menu-shown')) {
110 $this->execute('behat_general::i_click_on_in_the',
111 array(get_string('actions'), "link", $this->escape($blockname), "block")
116 * Clicks on Configure block for specified block. Page must be in editing mode.
118 * Argument block_name may be either the name of the block or CSS class of the block.
120 * @Given /^I configure the "(?P<block_name_string>(?:[^"]|\\")*)" block$/
121 * @param string $blockname
123 public function i_configure_the_block($blockname) {
124 // Note that since $blockname may be either block name or CSS class, we can not use the exact label of "Configure" link.
126 $this->execute("behat_blocks::i_open_the_blocks_action_menu", $this->escape($blockname));
128 $this->execute('behat_general::i_click_on_in_the',
129 array("Configure", "link", $this->escape($blockname), "block")
134 * Ensures that block can be added to the page but does not actually add it.
136 * @Then /^the add block selector should contain "(?P<block_name_string>(?:[^"]|\\")*)" block$/
137 * @param string $blockname
139 public function the_add_block_selector_should_contain_block($blockname) {
140 $this->execute('behat_forms::the_select_box_should_contain', [get_string('addblock'), $blockname]);
144 * Ensures that block can not be added to the page.
146 * @Then /^the add block selector should not contain "(?P<block_name_string>(?:[^"]|\\")*)" block$/
147 * @param string $blockname
149 public function the_add_block_selector_should_not_contain_block($blockname) {
150 $this->execute('behat_forms::the_select_box_should_not_contain', [get_string('addblock'), $blockname]);