weekly release 3.7dev
[moodle.git] / theme / boost / tests / behat / behat_theme_boost_behat_blocks.php
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/>.
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  */
26 // NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
28 require_once(__DIR__ . '/../../../../blocks/tests/behat/behat_blocks.php');
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  */
38 class behat_theme_boost_behat_blocks extends behat_blocks {
40     public function i_add_the_block($blockname) {
41         $addblock = get_string('addblock');
42         $this->execute('behat_navigation::i_select_from_flat_navigation_drawer', $addblock);
44         if (!$this->running_javascript()) {
45             $this->execute('behat_general::i_click_on_in_the', [$blockname, 'link_exact', '#region-main', 'css_element']);
46         } else {
47             $this->execute('behat_general::i_click_on_in_the', [$blockname, 'link_exact', $addblock, 'dialogue']);
48         }
49     }
51     public function i_open_the_blocks_action_menu($blockname) {
53         if (!$this->running_javascript()) {
54             // Action menu does not need to be open if Javascript is off.
55             return;
56         }
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         }
64         $this->execute('behat_general::i_click_on_in_the',
65             array("a[data-toggle='dropdown']", "css_element", $this->escape($blockname), "block")
66         );
67     }
69     public function the_add_block_selector_should_contain_block($blockname) {
70         $addblock = get_string('addblock');
71         $this->execute('behat_navigation::i_select_from_flat_navigation_drawer', $addblock);
73         $cancelstr = get_string('cancel');
74         if (!$this->running_javascript()) {
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']);
77         } else {
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']);
80         }
81     }
83     public function the_add_block_selector_should_not_contain_block($blockname) {
84         $addblock = get_string('addblock');
85         $this->execute('behat_navigation::i_select_from_flat_navigation_drawer', $addblock);
87         $cancelstr = get_string('cancel');
88         if (!$this->running_javascript()) {
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']);
91         } else {
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']);
94         }
95     }
97 }