. /** * 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(?:[^"]|\\")*)" 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']); } }