Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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   block_multiblock
21
 * @copyright 2020 Peter Spicer <peter.spicer@catalyst-eu.net>
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
26
 
27
use Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
28
 
29
require_once(__DIR__ . '/../../../../lib/behat/behat_base.php');
30
 
31
/**
32
 * Blocks management steps definitions.
33
 *
34
 * @package   block_multiblock
35
 * @copyright 2020 Peter Spicer <peter.spicer@catalyst-eu.net>
36
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37
 */
38
class behat_block_multiblock extends behat_base {
39
    /** @var object|null HTML/Text object based on moodle version. */
40
    private $htmlblock = null;
41
 
42
    /**
43
     * Return HTML/Text object based on moodle version
44
     *
45
     * @return object
46
     */
47
    private function htmlblock() {
48
        if (!empty($this->htmlblock)) {
49
            return $this->htmlblock;
50
        }
51
 
52
        global $CFG;
53
        $newblockname = $CFG->branch >= 400;
54
 
55
        $htmlblock = new stdClass;
56
        $htmlblock->name = $newblockname ? 'Text' : 'HTML';
57
        $htmlblock->defaulttitle = $newblockname ? '(new text block)' : '(new HTML block)';
58
 
59
        $this->htmlblock = $htmlblock;
60
 
61
        return $htmlblock;
62
    }
63
 
64
    /**
65
     * Clicks on "Manage ... contents" for specified block. Page must be in editing mode.
66
     *
67
     * Argument block_name may be either the name of the block or CSS class of the block.
68
     *
69
     * @Given /^I manage the contents of "(?P<block_name_string>(?:[^"]|\\")*)" block$/
70
     * @param string $blockname
71
     */
72
    public function i_manage_the_contents_of_block($blockname) {
73
        // Problem 1, the block name might be the name or the CSS.
74
        // Problem 2, the string conceivably could be 'Manage  contents' if the block name is empty.
75
        // As such we need to use what we do have of it.
76
 
77
        if (in_array($blockname, ["Text", "HTML"])) {
78
            $htmlblock = $this->htmlblock();
79
            $blockname = $htmlblock->name;
80
        }
81
 
82
        $this->execute("behat_blocks::i_open_the_blocks_action_menu", $this->escape($blockname));
83
 
84
        $this->execute('behat_general::i_click_on_in_the',
85
            array("Manage", "link", $this->escape($blockname), "block")
86
        );
87
    }
88
 
89
    /**
90
     * Adds an Text/HTML subblock in the manage contents page of a multiblock.
91
     *
92
     * @Given /^I add the HTML block field$/
93
     */
94
    public function i_add_the_html_block_field() {
95
        $block = $this->htmlblock();
96
 
97
        $this->execute("behat_forms::i_set_the_field_to", ["Add a block", $this->escape($block->name)]);
98
        $this->execute("behat_general::i_click_on_in_the", ["input[value=Add]", "css_element", "[role=main]", "css_element"]);
99
    }
100
 
101
    /**
102
     * Changes the title of a Text/HTML block in its configuration page.
103
     *
104
     * Argument oldtitle is the current name of the block.
105
     * Argument newtitle is the new name of the block.
106
     *
107
     * @Given /^I set the title of the HTML block to "(?P<new_string>(?:[^"]|\\")*)"$/
108
     * @Given /^I set the title of the HTML block to "(?P<new_string>(?:[^"]|\\")*)" from "(?P<old_string>(?:[^"]|\\")*)"$/
109
     *
110
     * @param string $newtitle
111
     * @param string|false $oldtitle
112
     */
113
    public function i_set_the_title_of_the_html_block_to($newtitle, $oldtitle = false) {
114
        $block = $this->htmlblock();
115
        $titlefieldlabel = $block->name . ' block title';
116
        $oldtitle = $oldtitle ?: $block->defaulttitle;
117
 
118
        $this->execute("behat_general::i_click_on_in_the", ["Settings", "link", $oldtitle, "table_row"]);
119
        $this->execute("behat_forms::i_set_the_field_to", [$this->escape($titlefieldlabel), $this->escape($newtitle)]);
120
    }
121
 
122
    /**
123
     * Enables editing mode for when you are on the dashboard.
124
     *
125
     * @Given /^I enable editing mode whilst on the dashboard$/
126
     */
127
    public function i_enable_editing_mode_whilst_on_the_dashboard() {
128
        global $CFG;
129
        if ($CFG->branch >= 400) {
130
            $this->execute("behat_navigation::i_turn_editing_mode_on");
131
        } else {
132
            $this->execute(
133
                'behat_general::i_click_on_in_the',
134
                [
135
                    'Customise this page',
136
                    'button',
137
                    "[id='page-header']",
138
                    'css_element'
139
                ]
140
            );
141
        }
142
    }
143
}