MDL-58428 theme: Shift templates ready for Bootstrapbase removal
[moodle.git] / theme / bootstrapbase / tests / behat / behat_theme_bootstrapbase_behat_files.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 * Files interactions with behat overrides.
19 *
e3652936
MM
20 * @package theme_bootstrapbase
21 * @category test
63e4df60
DW
22 * @copyright 2016 Damyon Wiese
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_files.php');
29
30use Behat\Mink\Exception\ExpectationException as ExpectationException,
31 Behat\Mink\Element\NodeElement as NodeElement;
32
33/**
34 * Files-related actions overrides.
35 *
e3652936
MM
36 * @package theme_bootstrapbase
37 * @category test
63e4df60
DW
38 * @copyright 2016 Damyon Wiese
39 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40 */
e3652936 41class behat_theme_bootstrapbase_behat_files extends behat_files {
63e4df60
DW
42
43 protected function get_filepicker_node($filepickerelement) {
44
45 // More info about the problem (in case there is a problem).
46 $exception = new ExpectationException('"' . $filepickerelement . '" filepicker can not be found', $this->getSession());
47
48 // If no file picker label is mentioned take the first file picker from the page.
49 if (empty($filepickerelement)) {
50 $filepickercontainer = $this->find(
e3652936
MM
51 'xpath',
52 "//*[@data-fieldtype=\"filemanager\"]",
53 $exception
63e4df60
DW
54 );
55 } else {
56 // Gets the ffilemanager node specified by the locator which contains the filepicker container.
57 $filepickerelement = behat_context_helper::escape($filepickerelement);
58 $filepickercontainer = $this->find(
e3652936
MM
59 'xpath',
60 "//input[./@id = //label[normalize-space(.)=$filepickerelement]/@for]" .
61 '//ancestor::div[@data-fieldtype="filemanager" or @data-fieldtype="filepicker"]',
62 $exception
63e4df60
DW
63 );
64 }
65
66 return $filepickercontainer;
67 }
68
69}