Merge branch 'MDL-56584-master-fix1' of http://github.com/damyon/moodle
[moodle.git] / blocks / tests / behat / behat_blocks.php
CommitLineData
fe856690
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 related with blocks.
19 *
abe572e3 20 * @package core_block
fe856690
DM
21 * @category test
22 * @copyright 2012 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
fe856690
DM
30/**
31 * Blocks management steps definitions.
32 *
abe572e3 33 * @package core_block
fe856690
DM
34 * @category test
35 * @copyright 2012 David MonllaĆ³
36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 */
38class behat_blocks extends behat_base {
39
40 /**
41 * Adds the selected block. Editing mode must be previously enabled.
42 *
43 * @Given /^I add the "(?P<block_name_string>(?:[^"]|\\")*)" block$/
44 * @param string $blockname
45 */
46 public function i_add_the_block($blockname) {
eb9ca848
RT
47 $this->execute('behat_forms::i_set_the_field_to',
48 array("bui_addblock", $this->escape($blockname))
49 );
1c00d6f6
DM
50
51 // If we are running without javascript we need to submit the form.
52 if (!$this->running_javascript()) {
eb9ca848
RT
53 $this->execute('behat_general::i_click_on_in_the',
54 array(get_string('go'), "button", "#add_block", "css_element")
1c00d6f6
DM
55 );
56 }
fe856690
DM
57 }
58
5d2b6722
DM
59 /**
60 * Docks a block. Editing mode should be previously enabled.
61 *
62 * @Given /^I dock "(?P<block_name_string>(?:[^"]|\\")*)" block$/
63 * @param string $blockname
5d2b6722
DM
64 */
65 public function i_dock_block($blockname) {
66
67 // Looking for both title and alt.
68 $xpath = "//input[@type='image'][@title='" . get_string('dockblock', 'block', $blockname) . "' or @alt='" . get_string('addtodock', 'block') . "']";
eb9ca848
RT
69 $this->execute('behat_general::i_click_on_in_the',
70 array($xpath, "xpath_element", $this->escape($blockname), "block")
71 );
5d2b6722
DM
72 }
73
b100c4e3
AN
74 /**
75 * Opens a block's actions menu if it is not already opened.
76 *
77 * @Given /^I open the "(?P<block_name_string>(?:[^"]|\\")*)" blocks action menu$/
78 * @throws DriverException The step is not available when Javascript is disabled
79 * @param string $blockname
b100c4e3
AN
80 */
81 public function i_open_the_blocks_action_menu($blockname) {
82
83 if (!$this->running_javascript()) {
3ee51425
MG
84 // Action menu does not need to be open if Javascript is off.
85 return;
b100c4e3
AN
86 }
87
88 // If it is already opened we do nothing.
3ee51425
MG
89 $blocknode = $this->get_text_selector_node('block', $blockname);
90 if ($blocknode->hasClass('action-menu-shown')) {
b100c4e3
AN
91 return;
92 }
93
eb9ca848
RT
94 $this->execute('behat_general::i_click_on_in_the',
95 array("a[role='menuitem']", "css_element", $this->escape($blockname), "block")
96 );
b100c4e3
AN
97 }
98
99 /**
3ee51425
MG
100 * Clicks on Configure block for specified block. Page must be in editing mode.
101 *
102 * Argument block_name may be either the name of the block or CSS class of the block.
b100c4e3 103 *
3ee51425
MG
104 * @Given /^I configure the "(?P<block_name_string>(?:[^"]|\\")*)" block$/
105 * @param string $blockname
b100c4e3 106 */
3ee51425
MG
107 public function i_configure_the_block($blockname) {
108 // Note that since $blockname may be either block name or CSS class, we can not use the exact label of "Configure" link.
eb9ca848
RT
109
110 $this->execute("behat_blocks::i_open_the_blocks_action_menu", $this->escape($blockname));
111
112 $this->execute('behat_general::i_click_on_in_the',
113 array("Configure", "link", $this->escape($blockname), "block")
3ee51425 114 );
b100c4e3 115 }
fe856690 116}