MDL-42174 behat: change word filepicker to filemanager in step definitions
[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 *
20 * @package core
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
30use Behat\Behat\Context\Step\Given as Given;
31
32/**
33 * Blocks management steps definitions.
34 *
35 * @package core
36 * @category test
37 * @copyright 2012 David MonllaĆ³
38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39 */
40class behat_blocks extends behat_base {
41
42 /**
43 * Adds the selected block. Editing mode must be previously enabled.
44 *
45 * @Given /^I add the "(?P<block_name_string>(?:[^"]|\\")*)" block$/
46 * @param string $blockname
47 */
48 public function i_add_the_block($blockname) {
38976081 49 $steps = new Given('I select "' . $this->escape($blockname) . '" from "bui_addblock"');
1c00d6f6
DM
50
51 // If we are running without javascript we need to submit the form.
52 if (!$this->running_javascript()) {
53 $steps = array(
54 $steps,
dedb9738 55 new Given('I click on "' . get_string('go') . '" "button" in the "#add_block" "css_element"')
1c00d6f6
DM
56 );
57 }
58 return $steps;
fe856690
DM
59 }
60
b100c4e3
AN
61 /**
62 * Opens a block's actions menu if it is not already opened.
63 *
64 * @Given /^I open the "(?P<block_name_string>(?:[^"]|\\")*)" blocks action menu$/
65 * @throws DriverException The step is not available when Javascript is disabled
66 * @param string $blockname
67 * @return Given
68 */
69 public function i_open_the_blocks_action_menu($blockname) {
70
71 if (!$this->running_javascript()) {
72 throw new DriverException('Blocks action menu not available when Javascript is disabled');
73 }
74
75 // If it is already opened we do nothing.
76 $blocknode = $this->get_block_node($blockname);
77 $classes = array_flip(explode(' ', $blocknode->getAttribute('class')));
78 if (!empty($classes['action-menu-shown'])) {
79 return;
80 }
81
82 return new Given('I click on "a[role=\'menuitem\']" "css_element" in the "' . $this->escape($blockname) . '" "block"');
83 }
84
85 /**
86 * Returns the DOM node of the block from <div>.
87 *
88 * @throws ElementNotFoundException Thrown by behat_base::find
89 * @param string $blockname The block name
90 * @return NodeElement
91 */
92 protected function get_block_node($blockname) {
93
94 $blockname = $this->getSession()->getSelectorsHandler()->xpathLiteral($blockname);
95 $xpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' block ')][contains(., $blockname)]";
96
97 return $this->find('xpath', $xpath);
98 }
99
fe856690 100}