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 |
* Override definitions for the upload repository type for the Classic theme.
|
|
|
19 |
*
|
|
|
20 |
* @package theme_classic
|
|
|
21 |
* @category test
|
|
|
22 |
* @copyright 2019 Michael Hawkins
|
|
|
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 |
|
|
|
28 |
require_once(__DIR__ . '/../../../../repository/upload/tests/behat/behat_repository_upload.php');
|
|
|
29 |
|
|
|
30 |
use Behat\Mink\Exception\ExpectationException as ExpectationException;
|
|
|
31 |
|
|
|
32 |
/**
|
|
|
33 |
* Override step definitions to deal with the upload repository in the Classic theme.
|
|
|
34 |
*
|
|
|
35 |
* @package theme_classic
|
|
|
36 |
* @category test
|
|
|
37 |
* @copyright 2019 Michael Hawkins
|
|
|
38 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
39 |
*/
|
|
|
40 |
class behat_theme_classic_behat_repository_upload extends behat_repository_upload {
|
|
|
41 |
|
|
|
42 |
/**
|
|
|
43 |
* Gets the NodeElement for filepicker of filemanager moodleform element.
|
|
|
44 |
*
|
|
|
45 |
* @throws ExpectationException
|
|
|
46 |
* @param string $filepickerelement The filepicker form field label
|
|
|
47 |
* @return NodeElement The hidden element node.
|
|
|
48 |
*/
|
|
|
49 |
protected function get_filepicker_node($filepickerelement) {
|
|
|
50 |
|
|
|
51 |
// More info about the problem (in case there is a problem).
|
|
|
52 |
$exception = new ExpectationException('"' . $filepickerelement . '" filepicker can not be found', $this->getSession());
|
|
|
53 |
|
|
|
54 |
// If no file picker label is mentioned take the first file picker from the page.
|
|
|
55 |
if (empty($filepickerelement)) {
|
|
|
56 |
$filepickercontainer = $this->find(
|
|
|
57 |
'xpath',
|
|
|
58 |
"//*[@class=\"form-filemanager\"]",
|
|
|
59 |
$exception
|
|
|
60 |
);
|
|
|
61 |
} else {
|
|
|
62 |
// Gets the filemanager node specified by the locator which contains the filepicker container.
|
|
|
63 |
$filepickerelement = behat_context_helper::escape($filepickerelement);
|
|
|
64 |
$filepickercontainer = $this->find(
|
|
|
65 |
'xpath',
|
|
|
66 |
"//input[./@id = substring-before(//p[normalize-space(.)=$filepickerelement]/@id, '_label')]" .
|
|
|
67 |
"//ancestor::*[@data-fieldtype = 'filemanager' or @data-fieldtype = 'filepicker']",
|
|
|
68 |
$exception
|
|
|
69 |
);
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
return $filepickercontainer;
|
|
|
73 |
}
|
|
|
74 |
}
|