mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 08:26:37 +02:00
131 lines
5.2 KiB
PHP
131 lines
5.2 KiB
PHP
<?php
|
|
// This file is part of Moodle - http://moodle.org/
|
|
//
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
/**
|
|
* Navigation steps overrides.
|
|
*
|
|
* @copyright 2016 Damyon Wiese
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
*/
|
|
|
|
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
|
|
|
|
require_once(__DIR__ . '/../../../../lib/tests/behat/behat_navigation.php');
|
|
|
|
use Behat\Mink\Exception\ExpectationException as ExpectationException;
|
|
use Behat\Mink\Exception\DriverException as DriverException;
|
|
|
|
/**
|
|
* Steps definitions to navigate through the navigation tree nodes (overrides).
|
|
*
|
|
* @copyright 2016 Damyon Wiese
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
*/
|
|
class behat_theme_boost_behat_navigation extends behat_navigation {
|
|
|
|
public function i_follow_in_the_user_menu($nodetext) {
|
|
|
|
if ($this->running_javascript()) {
|
|
// The user menu must be expanded when JS is enabled.
|
|
$xpath = "//div[@class='usermenu']//a[contains(concat(' ', @class, ' '), ' dropdown-toggle ')]";
|
|
$this->execute("behat_general::i_click_on", array($this->escape($xpath), "xpath_element"));
|
|
}
|
|
|
|
// Now select the link.
|
|
// The CSS path is always present, with or without JS.
|
|
$csspath = ".usermenu .dropdown-menu";
|
|
|
|
$this->execute('behat_general::i_click_on_in_the',
|
|
array($nodetext, "link", $csspath, "css_element")
|
|
);
|
|
}
|
|
|
|
protected function get_top_navigation_node($nodetext) {
|
|
|
|
// Avoid problems with quotes.
|
|
$nodetextliteral = behat_context_helper::escape($nodetext);
|
|
$exception = new ExpectationException('Top navigation node "' . $nodetext . ' not found in "', $this->getSession());
|
|
|
|
// First find in navigation block.
|
|
$xpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' card-text ')]" .
|
|
"/ul[contains(concat(' ', normalize-space(@class), ' '), ' block_tree ')]" .
|
|
"/li[contains(concat(' ', normalize-space(@class), ' '), ' contains_branch ')]" .
|
|
"/ul/li[contains(concat(' ', normalize-space(@class), ' '), ' contains_branch ')]" .
|
|
"[p[contains(concat(' ', normalize-space(@class), ' '), ' branch ')]" .
|
|
"/*[normalize-space(.)=" . $nodetextliteral ."]]" .
|
|
"|" .
|
|
"//div[contains(concat(' ', normalize-space(@class), ' '), ' card-text ')]/div" .
|
|
"/ul[contains(concat(' ', normalize-space(@class), ' '), ' block_tree ')]" .
|
|
"/li[p[contains(concat(' ', normalize-space(@class), ' '), ' branch ')]" .
|
|
"/*[normalize-space(.)=" . $nodetextliteral ."]]";
|
|
|
|
$node = $this->find('xpath', $xpath, $exception);
|
|
|
|
return $node;
|
|
}
|
|
|
|
/**
|
|
* Opens the flat navigation drawer if it is not already open
|
|
*
|
|
* @When /^I open flat navigation drawer$/
|
|
* @throws ElementNotFoundException Thrown by behat_base::find
|
|
*/
|
|
public function i_open_flat_navigation_drawer() {
|
|
if (!$this->running_javascript()) {
|
|
// Navigation drawer is always open without JS.
|
|
return;
|
|
}
|
|
$xpath = "//button[contains(@data-action,'toggle-drawer')]";
|
|
$node = $this->find('xpath', $xpath);
|
|
$expanded = $node->getAttribute('aria-expanded');
|
|
if ($expanded === 'false') {
|
|
$node->click();
|
|
$this->wait_for_pending_js();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Closes the flat navigation drawer if it is open (does nothing if JS disabled)
|
|
*
|
|
* @When /^I close flat navigation drawer$/
|
|
* @throws ElementNotFoundException Thrown by behat_base::find
|
|
*/
|
|
public function i_close_flat_navigation_drawer() {
|
|
if (!$this->running_javascript()) {
|
|
// Navigation drawer can not be closed without JS.
|
|
return;
|
|
}
|
|
$xpath = "//button[contains(@data-action,'toggle-drawer')]";
|
|
$node = $this->find('xpath', $xpath);
|
|
$expanded = $node->getAttribute('aria-expanded');
|
|
if ($expanded === 'true') {
|
|
$node->click();
|
|
$this->wait_for_pending_js();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Clicks link with specified id|title|alt|text in the flat navigation drawer.
|
|
*
|
|
* @When /^I select "(?P<link_string>(?:[^"]|\\")*)" from flat navigation drawer$/
|
|
* @throws ElementNotFoundException Thrown by behat_base::find
|
|
* @param string $link
|
|
*/
|
|
public function i_select_from_flat_navigation_drawer($link) {
|
|
$this->i_open_flat_navigation_drawer();
|
|
$this->execute('behat_general::i_click_on_in_the', [$link, 'link', '#nav-drawer', 'css_element']);
|
|
}
|
|
}
|