Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.
   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  // NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
  18  // For that reason, we can't even rely on $CFG->admin being available here.
  19  
  20  require_once (__DIR__ . '/../../../../lib/tests/behat/behat_navigation.php');
  21  
  22  use Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
  23  use Behat\Mink\Exception\ExpectationException as ExpectationException;
  24  
  25  /**
  26   * Step definitions related to the navigation in the Boost theme.
  27   *
  28   * @package    theme_boost
  29   * @category   test
  30   * @copyright  2021 Mihail Geshoski
  31   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  32   */
  33  class behat_theme_boost_behat_navigation extends behat_navigation {
  34      /**
  35       * Checks whether a node is active in the navbar.
  36       *
  37       * @override i should see :name is active in navigation
  38       *
  39       * @throws ElementNotFoundException
  40       * @param string      $element The name of the nav elemnent to look for.
  41       * @return void
  42       */
  43      public function i_should_see_is_active_in_navigation($element) {
  44          $this->execute("behat_general::assert_element_contains_text",
  45              [$element, '.navbar .nav-link.active', 'css_element']);
  46      }
  47      /**
  48       * Checks whether a node is active in the secondary nav.
  49       *
  50       * @Given i should see :name is active in secondary navigation
  51       * @throws ElementNotFoundException
  52       * @param string      $element The name of the nav elemnent to look for.
  53       * @return void
  54       */
  55      public function i_should_see_is_active_in_secondary_navigation($element) {
  56          $this->execute("behat_general::assert_element_contains_text",
  57              [$element, '.secondary-navigation .nav-link.active', 'css_element']);
  58      }
  59  
  60      /**
  61       * Checks whether the language selector menu is present in the navbar.
  62       *
  63       * @Given language selector menu should exist in the navbar
  64       * @Given language selector menu should :not exist in the navbar
  65       *
  66       * @throws ElementNotFoundException
  67       * @param string|null $not Instructs to checks whether the element does not exist in the user menu, if defined
  68       * @return void
  69       */
  70      public function lang_menu_should_exist($not = null) {
  71          $callfunction = is_null($not) ? 'should_exist' : 'should_not_exist';
  72          $this->execute("behat_general::{$callfunction}", [$this->get_lang_menu_xpath(), 'xpath_element']);
  73      }
  74  
  75      /**
  76       * Checks whether an item exists in the language selector menu.
  77       *
  78       * @Given :itemtext :selectortype should exist in the language selector menu
  79       * @Given :itemtext :selectortype should :not exist in the language selector menu
  80       *
  81       * @throws ElementNotFoundException
  82       * @param string $itemtext The menu item to find
  83       * @param string $selectortype The selector type
  84       * @param string|null $not Instructs to checks whether the element does not exist in the user menu, if defined
  85       * @return void
  86       */
  87      public function should_exist_in_lang_menu($itemtext, $selectortype, $not = null) {
  88          $callfunction = is_null($not) ? 'should_exist_in_the' : 'should_not_exist_in_the';
  89          $this->execute("behat_general::{$callfunction}",
  90              [$itemtext, $selectortype, $this->get_lang_menu_xpath(), 'xpath_element']);
  91      }
  92  
  93      /**
  94       * Return the xpath for the language selector menu element.
  95       *
  96       * @return string The xpath
  97       */
  98      protected function get_lang_menu_xpath() {
  99          return "//nav[contains(concat(' ', @class, ' '), ' navbar ')]" .
 100              "//div[contains(concat(' ', @class, ' '),  ' langmenu ')]" .
 101              "//div[contains(concat(' ', @class, ' '), ' dropdown-menu ')]";
 102      }
 103  }