weekly release 3.7dev
[moodle.git] / theme / boost / tests / behat / behat_theme_boost_behat_blocks.php
CommitLineData
63e4df60
DW
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 *
20 * @package core_block
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__ . '/../../../../blocks/tests/behat/behat_blocks.php');
29
30/**
31 * Blocks management steps definitions.
32 *
33 * @package core_block
34 * @category test
35 * @copyright 2012 David MonllaĆ³
36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 */
2ede86d7 38class behat_theme_boost_behat_blocks extends behat_blocks {
63e4df60
DW
39
40 public function i_add_the_block($blockname) {
2a77813b
AN
41 $addblock = get_string('addblock');
42 $this->execute('behat_navigation::i_select_from_flat_navigation_drawer', $addblock);
be2247fb
DW
43
44 if (!$this->running_javascript()) {
1dc320f1 45 $this->execute('behat_general::i_click_on_in_the', [$blockname, 'link_exact', '#region-main', 'css_element']);
be2247fb 46 } else {
2a77813b 47 $this->execute('behat_general::i_click_on_in_the', [$blockname, 'link_exact', $addblock, 'dialogue']);
be2247fb 48 }
63e4df60
DW
49 }
50
51 public function i_open_the_blocks_action_menu($blockname) {
52
53 if (!$this->running_javascript()) {
54 // Action menu does not need to be open if Javascript is off.
55 return;
56 }
57
58 // If it is already opened we do nothing.
59 $blocknode = $this->get_text_selector_node('block', $blockname);
60 if ($blocknode->hasClass('action-menu-shown')) {
61 return;
62 }
63
64 $this->execute('behat_general::i_click_on_in_the',
65 array("a[data-toggle='dropdown']", "css_element", $this->escape($blockname), "block")
66 );
67 }
68
392367c4 69 public function the_add_block_selector_should_contain_block($blockname) {
2a77813b
AN
70 $addblock = get_string('addblock');
71 $this->execute('behat_navigation::i_select_from_flat_navigation_drawer', $addblock);
392367c4
MG
72
73 $cancelstr = get_string('cancel');
74 if (!$this->running_javascript()) {
1dc320f1
RT
75 $this->execute('behat_general::should_exist_in_the', [$blockname, 'link_exact', '#region-main', 'css_element']);
76 $this->execute('behat_general::i_click_on_in_the', [$cancelstr, 'link_exact', '#region-main', 'css_element']);
392367c4 77 } else {
2a77813b
AN
78 $this->execute('behat_general::should_exist_in_the', [$blockname, 'link_exact', $addblock, 'dialogue']);
79 $this->execute('behat_general::i_click_on_in_the', [$cancelstr, 'button', $addblock, 'dialogue']);
392367c4
MG
80 }
81 }
82
83 public function the_add_block_selector_should_not_contain_block($blockname) {
2a77813b
AN
84 $addblock = get_string('addblock');
85 $this->execute('behat_navigation::i_select_from_flat_navigation_drawer', $addblock);
392367c4
MG
86
87 $cancelstr = get_string('cancel');
88 if (!$this->running_javascript()) {
1dc320f1
RT
89 $this->execute('behat_general::should_not_exist_in_the', [$blockname, 'link_exact', '#region-main', 'css_element']);
90 $this->execute('behat_general::i_click_on_in_the', [$cancelstr, 'link_exact', '#region-main', 'css_element']);
392367c4 91 } else {
2a77813b
AN
92 $this->execute('behat_general::should_not_exist_in_the', [$blockname, 'link_exact', $addblock, 'dialogue']);
93 $this->execute('behat_general::i_click_on_in_the', [$cancelstr, 'button', $addblock, 'dialogue']);
392367c4
MG
94 }
95 }
96
63e4df60 97}