| 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 | 
            * Navigation steps definitions.
  | 
        
        
            | 
            | 
           19 | 
            *
  | 
        
        
            | 
            | 
           20 | 
            * @package    core
  | 
        
        
            | 
            | 
           21 | 
            * @category   test
  | 
        
        
            | 
            | 
           22 | 
            * @copyright  2012 David Monllaó
  | 
        
        
            | 
            | 
           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__ . '/../../behat/behat_base.php');
  | 
        
        
            | 
            | 
           29 | 
              | 
        
        
            | 
            | 
           30 | 
           use Behat\Mink\Element\NodeElement;
  | 
        
        
            | 
            | 
           31 | 
           use Behat\Mink\Exception\ExpectationException as ExpectationException;
  | 
        
        
            | 
            | 
           32 | 
           use Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
  | 
        
        
            | 
            | 
           33 | 
              | 
        
        
            | 
            | 
           34 | 
           /**
  | 
        
        
            | 
            | 
           35 | 
            * Steps definitions to navigate through the navigation tree nodes.
  | 
        
        
            | 
            | 
           36 | 
            *
  | 
        
        
            | 
            | 
           37 | 
            * @package    core
  | 
        
        
            | 
            | 
           38 | 
            * @category   test
  | 
        
        
            | 
            | 
           39 | 
            * @copyright  2012 David Monllaó
  | 
        
        
            | 
            | 
           40 | 
            * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  | 
        
        
            | 
            | 
           41 | 
            */
  | 
        
        
            | 
            | 
           42 | 
           class behat_navigation extends behat_base {
  | 
        
        
            | 
            | 
           43 | 
              | 
        
        
            | 
            | 
           44 | 
               /**
  | 
        
        
            | 
            | 
           45 | 
                * Checks whether a navigation node is active within the block navigation.
  | 
        
        
            | 
            | 
           46 | 
                *
  | 
        
        
            | 
            | 
           47 | 
                * @Given i should see :name is active in navigation
  | 
        
        
            | 
            | 
           48 | 
                *
  | 
        
        
            | 
            | 
           49 | 
                * @throws ElementNotFoundException
  | 
        
        
            | 
            | 
           50 | 
                * @param string      $element The name of the nav elemnent to look for.
  | 
        
        
            | 
            | 
           51 | 
                * @return void
  | 
        
        
            | 
            | 
           52 | 
                */
  | 
        
        
            | 
            | 
           53 | 
               public function i_should_see_is_active_in_navigation($element) {
  | 
        
        
            | 
            | 
           54 | 
                   $this->execute("behat_general::assert_element_contains_text",
  | 
        
        
            | 
            | 
           55 | 
                       [$element, '.block_navigation .active_tree_node', 'css_element']);
  | 
        
        
            | 
            | 
           56 | 
               }
  | 
        
        
            | 
            | 
           57 | 
              | 
        
        
            | 
            | 
           58 | 
               /**
  | 
        
        
            | 
            | 
           59 | 
                * Helper function to get a navigation nodes text element given its text from within the navigation block.
  | 
        
        
            | 
            | 
           60 | 
                *
  | 
        
        
            | 
            | 
           61 | 
                * This function finds the node with the given text from within the navigation block.
  | 
        
        
            | 
            | 
           62 | 
                * It checks to make sure the node is visible, and then returns it.
  | 
        
        
            | 
            | 
           63 | 
                *
  | 
        
        
            | 
            | 
           64 | 
                * @param string $text
  | 
        
        
            | 
            | 
           65 | 
                * @param bool $branch Set this true if you're only interested in the node if its a branch.
  | 
        
        
            | 
            | 
           66 | 
                * @param null|bool $collapsed Set this to true or false if you want the node to either be collapsed or not.
  | 
        
        
            | 
            | 
           67 | 
                *    If its left as null then we don't worry about it.
  | 
        
        
            | 
            | 
           68 | 
                * @param null|string|Exception|false $exception The exception to throw if the node is not found.
  | 
        
        
            | 
            | 
           69 | 
                * @return \Behat\Mink\Element\NodeElement
  | 
        
        
            | 
            | 
           70 | 
                */
  | 
        
        
            | 
            | 
           71 | 
               protected function get_node_text_node($text, $branch = false, $collapsed = null, $exception = null) {
  | 
        
        
            | 
            | 
           72 | 
                   if ($exception === null) {
  | 
        
        
            | 
            | 
           73 | 
                       $exception = new ExpectationException('The "' . $text . '" node could not be found', $this->getSession());
  | 
        
        
            | 
            | 
           74 | 
                   } else if (is_string($exception)) {
  | 
        
        
            | 
            | 
           75 | 
                       $exception = new ExpectationException($exception, $this->getSession());
  | 
        
        
            | 
            | 
           76 | 
                   }
  | 
        
        
            | 
            | 
           77 | 
              | 
        
        
            | 
            | 
           78 | 
                   $nodetextliteral = behat_context_helper::escape($text);
  | 
        
        
            | 
            | 
           79 | 
                   $hasblocktree = "[contains(concat(' ', normalize-space(@class), ' '), ' block_tree ')]";
  | 
        
        
            | 
            | 
           80 | 
                   $hasbranch = "[contains(concat(' ', normalize-space(@class), ' '), ' branch ')]";
  | 
        
        
            | 
            | 
           81 | 
                   $hascollapsed = "li[@aria-expanded='false']/p";
  | 
        
        
            | 
            | 
           82 | 
                   $notcollapsed = "li[@aria-expanded='true']/p";
  | 
        
        
            | 
            | 
           83 | 
                   $match = "[normalize-space(.)={$nodetextliteral}]";
  | 
        
        
            | 
            | 
           84 | 
              | 
        
        
            | 
            | 
           85 | 
                   // Avoid problems with quotes.
  | 
        
        
            | 
            | 
           86 | 
                   $isbranch = ($branch) ? $hasbranch : '';
  | 
        
        
            | 
            | 
           87 | 
                   if ($collapsed === true) {
  | 
        
        
            | 
            | 
           88 | 
                       $iscollapsed = $hascollapsed;
  | 
        
        
            | 
            | 
           89 | 
                   } else if ($collapsed === false) {
  | 
        
        
            | 
            | 
           90 | 
                       $iscollapsed = $notcollapsed;
  | 
        
        
            | 
            | 
           91 | 
                   } else {
  | 
        
        
            | 
            | 
           92 | 
                       $iscollapsed = 'li/p';
  | 
        
        
            | 
            | 
           93 | 
                   }
  | 
        
        
            | 
            | 
           94 | 
              | 
        
        
            | 
            | 
           95 | 
                   // First check root nodes, it can be a span or link.
  | 
        
        
            | 
            | 
           96 | 
                   $xpath  = "//ul{$hasblocktree}/{$hascollapsed}{$isbranch}/span{$match}|";
  | 
        
        
            | 
            | 
           97 | 
                   $xpath  .= "//ul{$hasblocktree}/{$hascollapsed}{$isbranch}/a{$match}|";
  | 
        
        
            | 
            | 
           98 | 
              | 
        
        
            | 
            | 
           99 | 
                   // Next search for the node containing the text within a link.
  | 
        
        
            | 
            | 
           100 | 
                   $xpath .= "//ul{$hasblocktree}//ul/{$iscollapsed}{$isbranch}/a{$match}|";
  | 
        
        
            | 
            | 
           101 | 
              | 
        
        
            | 
            | 
           102 | 
                   // Finally search for the node containing the text within a span.
  | 
        
        
            | 
            | 
           103 | 
                   $xpath .= "//ul{$hasblocktree}//ul/{$iscollapsed}{$isbranch}/span{$match}";
  | 
        
        
            | 
            | 
           104 | 
              | 
        
        
            | 
            | 
           105 | 
                   $node = $this->find('xpath', $xpath, $exception);
  | 
        
        
            | 
            | 
           106 | 
                   $this->ensure_node_is_visible($node);
  | 
        
        
            | 
            | 
           107 | 
                   return $node;
  | 
        
        
            | 
            | 
           108 | 
               }
  | 
        
        
            | 
            | 
           109 | 
              | 
        
        
            | 
            | 
           110 | 
               /**
  | 
        
        
            | 
            | 
           111 | 
                * Returns true if the navigation node with the given text is expandable.
  | 
        
        
            | 
            | 
           112 | 
                *
  | 
        
        
            | 
            | 
           113 | 
                * @Given /^navigation node "([^"]*)" should be expandable$/
  | 
        
        
            | 
            | 
           114 | 
                *
  | 
        
        
            | 
            | 
           115 | 
                * @throws ExpectationException
  | 
        
        
            | 
            | 
           116 | 
                * @param string $nodetext
  | 
        
        
            | 
            | 
           117 | 
                * @return bool
  | 
        
        
            | 
            | 
           118 | 
                */
  | 
        
        
            | 
            | 
           119 | 
               public function navigation_node_should_be_expandable($nodetext) {
  | 
        
        
            | 
            | 
           120 | 
                   if (!$this->running_javascript()) {
  | 
        
        
            | 
            | 
           121 | 
                       // Nodes are only expandable when JavaScript is enabled.
  | 
        
        
            | 
            | 
           122 | 
                       return false;
  | 
        
        
            | 
            | 
           123 | 
                   }
  | 
        
        
            | 
            | 
           124 | 
              | 
        
        
            | 
            | 
           125 | 
                   $node = $this->get_node_text_node($nodetext, true);
  | 
        
        
            | 
            | 
           126 | 
                   $node = $node->getParent();
  | 
        
        
            | 
            | 
           127 | 
                   if ($node->hasClass('emptybranch')) {
  | 
        
        
            | 
            | 
           128 | 
                       throw new ExpectationException('The "' . $nodetext . '" node is not expandable', $this->getSession());
  | 
        
        
            | 
            | 
           129 | 
                   }
  | 
        
        
            | 
            | 
           130 | 
              | 
        
        
            | 
            | 
           131 | 
                   return true;
  | 
        
        
            | 
            | 
           132 | 
               }
  | 
        
        
            | 
            | 
           133 | 
              | 
        
        
            | 
            | 
           134 | 
               /**
  | 
        
        
            | 
            | 
           135 | 
                * Returns true if the navigation node with the given text is not expandable.
  | 
        
        
            | 
            | 
           136 | 
                *
  | 
        
        
            | 
            | 
           137 | 
                * @Given /^navigation node "([^"]*)" should not be expandable$/
  | 
        
        
            | 
            | 
           138 | 
                *
  | 
        
        
            | 
            | 
           139 | 
                * @throws ExpectationException
  | 
        
        
            | 
            | 
           140 | 
                * @param string $nodetext
  | 
        
        
            | 
            | 
           141 | 
                * @return bool
  | 
        
        
            | 
            | 
           142 | 
                */
  | 
        
        
            | 
            | 
           143 | 
               public function navigation_node_should_not_be_expandable($nodetext) {
  | 
        
        
            | 
            | 
           144 | 
                   if (!$this->running_javascript()) {
  | 
        
        
            | 
            | 
           145 | 
                       // Nodes are only expandable when JavaScript is enabled.
  | 
        
        
            | 
            | 
           146 | 
                       return false;
  | 
        
        
            | 
            | 
           147 | 
                   }
  | 
        
        
            | 
            | 
           148 | 
              | 
        
        
            | 
            | 
           149 | 
                   $node = $this->get_node_text_node($nodetext);
  | 
        
        
            | 
            | 
           150 | 
                   $node = $node->getParent();
  | 
        
        
            | 
            | 
           151 | 
              | 
        
        
            | 
            | 
           152 | 
                   if ($node->hasClass('emptybranch') || $node->hasClass('tree_item')) {
  | 
        
        
            | 
            | 
           153 | 
                       return true;
  | 
        
        
            | 
            | 
           154 | 
                   }
  | 
        
        
            | 
            | 
           155 | 
                   throw new ExpectationException('The "' . $nodetext . '" node is expandable', $this->getSession());
  | 
        
        
            | 
            | 
           156 | 
               }
  | 
        
        
            | 
            | 
           157 | 
              | 
        
        
            | 
            | 
           158 | 
               /**
  | 
        
        
            | 
            | 
           159 | 
                * Click on an entry in the user menu.
  | 
        
        
            | 
            | 
           160 | 
                * @Given /^I follow "(?P<nodetext_string>(?:[^"]|\\")*)" in the user menu$/
  | 
        
        
            | 
            | 
           161 | 
                *
  | 
        
        
            | 
            | 
           162 | 
                * @param string $nodetext
  | 
        
        
            | 
            | 
           163 | 
                */
  | 
        
        
            | 
            | 
           164 | 
               public function i_follow_in_the_user_menu($nodetext) {
  | 
        
        
            | 
            | 
           165 | 
              | 
        
        
            | 
            | 
           166 | 
                   if ($this->running_javascript()) {
  | 
        
        
            | 
            | 
           167 | 
                       // The user menu must be expanded when JS is enabled.
  | 
        
        
            | 
            | 
           168 | 
                       $xpath = "//div[contains(concat(' ', @class, ' '), ' usermenu ')]//a[contains(concat(' ', @class, ' '), ' dropdown-toggle ')]";
  | 
        
        
            | 
            | 
           169 | 
                       $this->execute("behat_general::i_click_on", array($this->escape($xpath), "xpath_element"));
  | 
        
        
            | 
            | 
           170 | 
                   }
  | 
        
        
            | 
            | 
           171 | 
              | 
        
        
            | 
            | 
           172 | 
                   // Now select the link.
  | 
        
        
            | 
            | 
           173 | 
                   // The CSS path is always present, with or without JS.
  | 
        
        
            | 
            | 
           174 | 
                   $csspath = ".usermenu .dropdown-menu";
  | 
        
        
            | 
            | 
           175 | 
              | 
        
        
            | 
            | 
           176 | 
                   $this->execute('behat_general::i_click_on_in_the',
  | 
        
        
            | 
            | 
           177 | 
                           array($nodetext, "link", $csspath, "css_element")
  | 
        
        
            | 
            | 
           178 | 
                   );
  | 
        
        
            | 
            | 
           179 | 
               }
  | 
        
        
            | 
            | 
           180 | 
              | 
        
        
            | 
            | 
           181 | 
               /**
  | 
        
        
            | 
            | 
           182 | 
                * Expands the selected node of the navigation tree that matches the text.
  | 
        
        
            | 
            | 
           183 | 
                * @Given /^I expand "(?P<nodetext_string>(?:[^"]|\\")*)" node$/
  | 
        
        
            | 
            | 
           184 | 
                *
  | 
        
        
            | 
            | 
           185 | 
                * @throws ExpectationException
  | 
        
        
            | 
            | 
           186 | 
                * @param string $nodetext
  | 
        
        
            | 
            | 
           187 | 
                * @return bool|void
  | 
        
        
            | 
            | 
           188 | 
                */
  | 
        
        
            | 
            | 
           189 | 
               public function i_expand_node($nodetext) {
  | 
        
        
            | 
            | 
           190 | 
              | 
        
        
            | 
            | 
           191 | 
                   // This step is useless with Javascript disabled as Moodle auto expands
  | 
        
        
            | 
            | 
           192 | 
                   // all of tree's nodes; adding this because of scenarios that shares the
  | 
        
        
            | 
            | 
           193 | 
                   // same steps with and without Javascript enabled.
  | 
        
        
            | 
            | 
           194 | 
                   if (!$this->running_javascript()) {
  | 
        
        
            | 
            | 
           195 | 
                       if ($nodetext === get_string('administrationsite')) {
  | 
        
        
            | 
            | 
           196 | 
                           // Administration menu is not loaded by default any more. Click the link to expand.
  | 
        
        
            | 
            | 
           197 | 
                           $this->execute('behat_general::i_click_on_in_the',
  | 
        
        
            | 
            | 
           198 | 
                               array($nodetext, "link", get_string('administration'), "block")
  | 
        
        
            | 
            | 
           199 | 
                           );
  | 
        
        
            | 
            | 
           200 | 
                           return true;
  | 
        
        
            | 
            | 
           201 | 
                       }
  | 
        
        
            | 
            | 
           202 | 
                       return true;
  | 
        
        
            | 
            | 
           203 | 
                   }
  | 
        
        
            | 
            | 
           204 | 
              | 
        
        
            | 
            | 
           205 | 
                   $node = $this->get_node_text_node($nodetext, true, true, 'The "' . $nodetext . '" node can not be expanded');
  | 
        
        
            | 
            | 
           206 | 
                   // Check if the node is a link AND a branch.
  | 
        
        
            | 
            | 
           207 | 
                   if (strtolower($node->getTagName()) === 'a') {
  | 
        
        
            | 
            | 
           208 | 
                       // We just want to expand the node, we don't want to follow it.
  | 
        
        
            | 
            | 
           209 | 
                       $node = $node->getParent();
  | 
        
        
            | 
            | 
           210 | 
                   }
  | 
        
        
            | 
            | 
           211 | 
                   $this->execute('behat_general::i_click_on', [$node, 'NodeElement']);
  | 
        
        
            | 
            | 
           212 | 
               }
  | 
        
        
            | 
            | 
           213 | 
              | 
        
        
            | 
            | 
           214 | 
               /**
  | 
        
        
            | 
            | 
           215 | 
                * Collapses the selected node of the navigation tree that matches the text.
  | 
        
        
            | 
            | 
           216 | 
                *
  | 
        
        
            | 
            | 
           217 | 
                * @Given /^I collapse "(?P<nodetext_string>(?:[^"]|\\")*)" node$/
  | 
        
        
            | 
            | 
           218 | 
                * @throws ExpectationException
  | 
        
        
            | 
            | 
           219 | 
                * @param string $nodetext
  | 
        
        
            | 
            | 
           220 | 
                * @return bool|void
  | 
        
        
            | 
            | 
           221 | 
                */
  | 
        
        
            | 
            | 
           222 | 
               public function i_collapse_node($nodetext) {
  | 
        
        
            | 
            | 
           223 | 
              | 
        
        
            | 
            | 
           224 | 
                   // No collapsible nodes with non-JS browsers.
  | 
        
        
            | 
            | 
           225 | 
                   if (!$this->running_javascript()) {
  | 
        
        
            | 
            | 
           226 | 
                       return true;
  | 
        
        
            | 
            | 
           227 | 
                   }
  | 
        
        
            | 
            | 
           228 | 
              | 
        
        
            | 
            | 
           229 | 
                   $node = $this->get_node_text_node($nodetext, true, false, 'The "' . $nodetext . '" node can not be collapsed');
  | 
        
        
            | 
            | 
           230 | 
                   // Check if the node is a link AND a branch.
  | 
        
        
            | 
            | 
           231 | 
                   if (strtolower($node->getTagName()) === 'a') {
  | 
        
        
            | 
            | 
           232 | 
                       // We just want to expand the node, we don't want to follow it.
  | 
        
        
            | 
            | 
           233 | 
                       $node = $node->getParent();
  | 
        
        
            | 
            | 
           234 | 
                   }
  | 
        
        
            | 
            | 
           235 | 
                   $this->execute('behat_general::i_click_on', [$node, 'NodeElement']);
  | 
        
        
            | 
            | 
           236 | 
               }
  | 
        
        
            | 
            | 
           237 | 
              | 
        
        
            | 
            | 
           238 | 
               /**
  | 
        
        
            | 
            | 
           239 | 
                * Finds a node in the Navigation or Administration tree
  | 
        
        
            | 
            | 
           240 | 
                *
  | 
        
        
            | 
            | 
           241 | 
                * @param string $nodetext
  | 
        
        
            | 
            | 
           242 | 
                * @param array $parentnodes
  | 
        
        
            | 
            | 
           243 | 
                * @param string $nodetype node type (link or text)
  | 
        
        
            | 
            | 
           244 | 
                * @return NodeElement|null
  | 
        
        
            | 
            | 
           245 | 
                * @throws ExpectationException when one of the parent nodes is not found
  | 
        
        
            | 
            | 
           246 | 
                */
  | 
        
        
            | 
            | 
           247 | 
               protected function find_node_in_navigation($nodetext, $parentnodes, $nodetype = 'link') {
  | 
        
        
            | 
            | 
           248 | 
                   // Site admin is different and needs special treatment.
  | 
        
        
            | 
            | 
           249 | 
                   $siteadminstr = get_string('administrationsite');
  | 
        
        
            | 
            | 
           250 | 
              | 
        
        
            | 
            | 
           251 | 
                   // Create array of all parentnodes.
  | 
        
        
            | 
            | 
           252 | 
                   $countparentnode = count($parentnodes);
  | 
        
        
            | 
            | 
           253 | 
              | 
        
        
            | 
            | 
           254 | 
                   // If JS is disabled and Site administration is not expanded we
  | 
        
        
            | 
            | 
           255 | 
                   // should follow it, so all the lower-level nodes are available.
  | 
        
        
            | 
            | 
           256 | 
                   if (!$this->running_javascript()) {
  | 
        
        
            | 
            | 
           257 | 
                       if ($parentnodes[0] === $siteadminstr) {
  | 
        
        
            | 
            | 
           258 | 
                           // We don't know if there if Site admin is already expanded so
  | 
        
        
            | 
            | 
           259 | 
                           // don't wait, it is non-JS and we already waited for the DOM.
  | 
        
        
            | 
            | 
           260 | 
                           $siteadminlink = $this->getSession()->getPage()->find('named_exact', array('link', "'" . $siteadminstr . "'"));
  | 
        
        
            | 
            | 
           261 | 
                           if ($siteadminlink) {
  | 
        
        
            | 
            | 
           262 | 
                               $this->execute('behat_general::i_click_on', [$siteadminlink, 'NodeElement']);
  | 
        
        
            | 
            | 
           263 | 
                           }
  | 
        
        
            | 
            | 
           264 | 
                       }
  | 
        
        
            | 
            | 
           265 | 
                   }
  | 
        
        
            | 
            | 
           266 | 
              | 
        
        
            | 
            | 
           267 | 
                   // Get top level node.
  | 
        
        
            | 
            | 
           268 | 
                   $node = $this->get_top_navigation_node($parentnodes[0]);
  | 
        
        
            | 
            | 
           269 | 
              | 
        
        
            | 
            | 
           270 | 
                   // Expand all nodes.
  | 
        
        
            | 
            | 
           271 | 
                   for ($i = 0; $i < $countparentnode; $i++) {
  | 
        
        
            | 
            | 
           272 | 
                       if ($i > 0) {
  | 
        
        
            | 
            | 
           273 | 
                           // Sub nodes within top level node.
  | 
        
        
            | 
            | 
           274 | 
                           $node = $this->get_navigation_node($parentnodes[$i], $node);
  | 
        
        
            | 
            | 
           275 | 
                       }
  | 
        
        
            | 
            | 
           276 | 
              | 
        
        
            | 
            | 
           277 | 
                       // The p node contains the aria jazz.
  | 
        
        
            | 
            | 
           278 | 
                       $pnodexpath = "/p[contains(concat(' ', normalize-space(@class), ' '), ' tree_item ')]";
  | 
        
        
            | 
            | 
           279 | 
                       $pnode = $node->find('xpath', $pnodexpath);
  | 
        
        
            | 
            | 
           280 | 
                       $linode = $pnode->getParent();
  | 
        
        
            | 
            | 
           281 | 
              | 
        
        
            | 
            | 
           282 | 
                       // Keep expanding all sub-parents if js enabled.
  | 
        
        
            | 
            | 
           283 | 
                       if ($pnode && $this->running_javascript() && $linode->hasAttribute('aria-expanded') &&
  | 
        
        
            | 
            | 
           284 | 
                           ($linode->getAttribute('aria-expanded') == "false")) {
  | 
        
        
            | 
            | 
           285 | 
                           $this->js_trigger_click($pnode);
  | 
        
        
            | 
            | 
           286 | 
              | 
        
        
            | 
            | 
           287 | 
                           // Wait for node to load, if not loaded before.
  | 
        
        
            | 
            | 
           288 | 
                           if ($linode->hasAttribute('data-loaded') && $linode->getAttribute('data-loaded') == "false") {
  | 
        
        
            | 
            | 
           289 | 
                               $jscondition = '(document.evaluate("' . $linode->getXpath() . '", document, null, '.
  | 
        
        
            | 
            | 
           290 | 
                                   'XPathResult.ANY_TYPE, null).iterateNext().getAttribute(\'data-loaded\') == "true")';
  | 
        
        
            | 
            | 
           291 | 
              | 
        
        
            | 
            | 
           292 | 
                               $this->getSession()->wait(behat_base::get_extended_timeout() * 1000, $jscondition);
  | 
        
        
            | 
            | 
           293 | 
                           }
  | 
        
        
            | 
            | 
           294 | 
                       }
  | 
        
        
            | 
            | 
           295 | 
                   }
  | 
        
        
            | 
            | 
           296 | 
              | 
        
        
            | 
            | 
           297 | 
                   // Finally, click on requested node under navigation.
  | 
        
        
            | 
            | 
           298 | 
                   $nodetextliteral = behat_context_helper::escape($nodetext);
  | 
        
        
            | 
            | 
           299 | 
                   $tagname = ($nodetype === 'link') ? 'a' : 'span';
  | 
        
        
            | 
            | 
           300 | 
                   $xpath = "/ul/li/p[contains(concat(' ', normalize-space(@class), ' '), ' tree_item ')]" .
  | 
        
        
            | 
            | 
           301 | 
                       "/{$tagname}[normalize-space(.)=" . $nodetextliteral . "]";
  | 
        
        
            | 
            | 
           302 | 
                   return $node->find('xpath', $xpath);
  | 
        
        
            | 
            | 
           303 | 
               }
  | 
        
        
            | 
            | 
           304 | 
              | 
        
        
            | 
            | 
           305 | 
               /**
  | 
        
        
            | 
            | 
           306 | 
                * Finds a node in the Navigation or Administration tree and clicks on it.
  | 
        
        
            | 
            | 
           307 | 
                *
  | 
        
        
            | 
            | 
           308 | 
                * @param string $nodetext
  | 
        
        
            | 
            | 
           309 | 
                * @param array $parentnodes
  | 
        
        
            | 
            | 
           310 | 
                * @throws ExpectationException
  | 
        
        
            | 
            | 
           311 | 
                */
  | 
        
        
            | 
            | 
           312 | 
               protected function select_node_in_navigation($nodetext, $parentnodes) {
  | 
        
        
            | 
            | 
           313 | 
                   $nodetoclick = $this->find_node_in_navigation($nodetext, $parentnodes);
  | 
        
        
            | 
            | 
           314 | 
                   // Throw exception if no node found.
  | 
        
        
            | 
            | 
           315 | 
                   if (!$nodetoclick) {
  | 
        
        
            | 
            | 
           316 | 
                       throw new ExpectationException('Navigation node "' . $nodetext . '" not found under "' .
  | 
        
        
            | 
            | 
           317 | 
                           implode(' > ', $parentnodes) . '"', $this->getSession());
  | 
        
        
            | 
            | 
           318 | 
                   }
  | 
        
        
            | 
            | 
           319 | 
                   $this->execute('behat_general::i_click_on', [$nodetoclick, 'NodeElement']);
  | 
        
        
            | 
            | 
           320 | 
               }
  | 
        
        
            | 
            | 
           321 | 
              | 
        
        
            | 
            | 
           322 | 
               /**
  | 
        
        
            | 
            | 
           323 | 
                * Helper function to get top navigation node in tree.
  | 
        
        
            | 
            | 
           324 | 
                *
  | 
        
        
            | 
            | 
           325 | 
                * @throws ExpectationException if note not found.
  | 
        
        
            | 
            | 
           326 | 
                * @param string $nodetext name of top navigation node in tree.
  | 
        
        
            | 
            | 
           327 | 
                * @return NodeElement
  | 
        
        
            | 
            | 
           328 | 
                */
  | 
        
        
            | 
            | 
           329 | 
               protected function get_top_navigation_node($nodetext) {
  | 
        
        
            | 
            | 
           330 | 
              | 
        
        
            | 
            | 
           331 | 
                   // Avoid problems with quotes.
  | 
        
        
            | 
            | 
           332 | 
                   $nodetextliteral = behat_context_helper::escape($nodetext);
  | 
        
        
            | 
            | 
           333 | 
                   $exception = new ExpectationException('Top navigation node "' . $nodetext . ' not found in "', $this->getSession());
  | 
        
        
            | 
            | 
           334 | 
              | 
        
        
            | 
            | 
           335 | 
                   // First find in navigation block.
  | 
        
        
            | 
            | 
           336 | 
                   $xpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' card-text ')]" .
  | 
        
        
            | 
            | 
           337 | 
                           "/ul[contains(concat(' ', normalize-space(@class), ' '), ' block_tree ')]" .
  | 
        
        
            | 
            | 
           338 | 
                           "/li[contains(concat(' ', normalize-space(@class), ' '), ' contains_branch ')]" .
  | 
        
        
            | 
            | 
           339 | 
                           "/ul/li[contains(concat(' ', normalize-space(@class), ' '), ' contains_branch ')]" .
  | 
        
        
            | 
            | 
           340 | 
                           "[p[contains(concat(' ', normalize-space(@class), ' '), ' branch ')]" .
  | 
        
        
            | 
            | 
           341 | 
                           "/*[contains(normalize-space(.), " . $nodetextliteral .")]]" .
  | 
        
        
            | 
            | 
           342 | 
                           "|" .
  | 
        
        
            | 
            | 
           343 | 
                           "//div[contains(concat(' ', normalize-space(@class), ' '), ' card-text ')]/div" .
  | 
        
        
            | 
            | 
           344 | 
                           "/ul[contains(concat(' ', normalize-space(@class), ' '), ' block_tree ')]" .
  | 
        
        
            | 
            | 
           345 | 
                           "/li[p[contains(concat(' ', normalize-space(@class), ' '), ' branch ')]" .
  | 
        
        
            | 
            | 
           346 | 
                           "/*[contains(normalize-space(.), " . $nodetextliteral .")]]";
  | 
        
        
            | 
            | 
           347 | 
              | 
        
        
            | 
            | 
           348 | 
                   $node = $this->find('xpath', $xpath, $exception);
  | 
        
        
            | 
            | 
           349 | 
              | 
        
        
            | 
            | 
           350 | 
                   return $node;
  | 
        
        
            | 
            | 
           351 | 
               }
  | 
        
        
            | 
            | 
           352 | 
              | 
        
        
            | 
            | 
           353 | 
               /**
  | 
        
        
            | 
            | 
           354 | 
                * Helper function to get sub-navigation node.
  | 
        
        
            | 
            | 
           355 | 
                *
  | 
        
        
            | 
            | 
           356 | 
                * @throws ExpectationException if note not found.
  | 
        
        
            | 
            | 
           357 | 
                * @param string $nodetext node to find.
  | 
        
        
            | 
            | 
           358 | 
                * @param NodeElement $parentnode parent navigation node.
  | 
        
        
            | 
            | 
           359 | 
                * @return NodeElement.
  | 
        
        
            | 
            | 
           360 | 
                */
  | 
        
        
            | 
            | 
           361 | 
               protected function get_navigation_node($nodetext, $parentnode = null) {
  | 
        
        
            | 
            | 
           362 | 
              | 
        
        
            | 
            | 
           363 | 
                   // Avoid problems with quotes.
  | 
        
        
            | 
            | 
           364 | 
                   $nodetextliteral = behat_context_helper::escape($nodetext);
  | 
        
        
            | 
            | 
           365 | 
              | 
        
        
            | 
            | 
           366 | 
                   $xpath = "/ul/li[contains(concat(' ', normalize-space(@class), ' '), ' contains_branch ')]" .
  | 
        
        
            | 
            | 
           367 | 
                       "[child::p[contains(concat(' ', normalize-space(@class), ' '), ' branch ')]" .
  | 
        
        
            | 
            | 
           368 | 
                       "/child::span[normalize-space(.)=" . $nodetextliteral ."]]";
  | 
        
        
            | 
            | 
           369 | 
                   $node = $parentnode->find('xpath', $xpath);
  | 
        
        
            | 
            | 
           370 | 
                   if (!$node) {
  | 
        
        
            | 
            | 
           371 | 
                       $xpath = "/ul/li[contains(concat(' ', normalize-space(@class), ' '), ' contains_branch ')]" .
  | 
        
        
            | 
            | 
           372 | 
                           "[child::p[contains(concat(' ', normalize-space(@class), ' '), ' branch ')]" .
  | 
        
        
            | 
            | 
           373 | 
                           "/child::a[normalize-space(.)=" . $nodetextliteral ."]]";
  | 
        
        
            | 
            | 
           374 | 
                       $node = $parentnode->find('xpath', $xpath);
  | 
        
        
            | 
            | 
           375 | 
                   }
  | 
        
        
            | 
            | 
           376 | 
              | 
        
        
            | 
            | 
           377 | 
                   if (!$node) {
  | 
        
        
            | 
            | 
           378 | 
                       throw new ExpectationException('Sub-navigation node "' . $nodetext . '" not found under "' .
  | 
        
        
            | 
            | 
           379 | 
                           $parentnode->getText() . '"', $this->getSession());
  | 
        
        
            | 
            | 
           380 | 
                   }
  | 
        
        
            | 
            | 
           381 | 
                   return $node;
  | 
        
        
            | 
            | 
           382 | 
               }
  | 
        
        
            | 
            | 
           383 | 
              | 
        
        
            | 
            | 
           384 | 
               /**
  | 
        
        
            | 
            | 
           385 | 
                * Step to open the navigation bar if it is needed.
  | 
        
        
            | 
            | 
           386 | 
                *
  | 
        
        
            | 
            | 
           387 | 
                * The top log in and log out links are hidden when middle or small
  | 
        
        
            | 
            | 
           388 | 
                * size windows (or devices) are used. This step returns a step definition
  | 
        
        
            | 
            | 
           389 | 
                * clicking to expand the navbar if it is hidden.
  | 
        
        
            | 
            | 
           390 | 
                *
  | 
        
        
            | 
            | 
           391 | 
                * @Given /^I expand navigation bar$/
  | 
        
        
            | 
            | 
           392 | 
                */
  | 
        
        
            | 
            | 
           393 | 
               public function get_expand_navbar_step() {
  | 
        
        
            | 
            | 
           394 | 
              | 
        
        
            | 
            | 
           395 | 
                   // Checking if we need to click the navbar button to show the navigation menu, it
  | 
        
        
            | 
            | 
           396 | 
                   // is hidden by default when using clean theme and a medium or small screen size.
  | 
        
        
            | 
            | 
           397 | 
              | 
        
        
            | 
            | 
           398 | 
                   // The DOM and the JS should be all ready and loaded. Running without spinning
  | 
        
        
            | 
            | 
           399 | 
                   // as this is a widely used step and we can not spend time here trying to see
  | 
        
        
            | 
            | 
           400 | 
                   // a DOM node that is not always there (at the moment clean is not even the
  | 
        
        
            | 
            | 
           401 | 
                   // default theme...).
  | 
        
        
            | 
            | 
           402 | 
                   $navbuttonjs = "return (
  | 
        
        
            | 
            | 
           403 | 
                       Y.one('.btn-navbar') &&
  | 
        
        
            | 
            | 
           404 | 
                       Y.one('.btn-navbar').getComputedStyle('display') !== 'none'
  | 
        
        
            | 
            | 
           405 | 
                   )";
  | 
        
        
            | 
            | 
           406 | 
              | 
        
        
            | 
            | 
           407 | 
                   // Adding an extra click we need to show the 'Log in' link.
  | 
        
        
            | 
            | 
           408 | 
                   if (!$this->evaluate_script($navbuttonjs)) {
  | 
        
        
            | 
            | 
           409 | 
                       return false;
  | 
        
        
            | 
            | 
           410 | 
                   }
  | 
        
        
            | 
            | 
           411 | 
              | 
        
        
            | 
            | 
           412 | 
                   $this->execute('behat_general::i_click_on', array(".btn-navbar", "css_element"));
  | 
        
        
            | 
            | 
           413 | 
               }
  | 
        
        
            | 
            | 
           414 | 
              | 
        
        
            | 
            | 
           415 | 
               /**
  | 
        
        
            | 
            | 
           416 | 
                * Go to current page setting item
  | 
        
        
            | 
            | 
           417 | 
                *
  | 
        
        
            | 
            | 
           418 | 
                * This can be used on front page, course, category or modules pages.
  | 
        
        
            | 
            | 
           419 | 
                *
  | 
        
        
            | 
            | 
           420 | 
                * @Given /^I navigate to "(?P<nodetext_string>(?:[^"]|\\")*)" in current page administration$/
  | 
        
        
            | 
            | 
           421 | 
                *
  | 
        
        
            | 
            | 
           422 | 
                * @throws ExpectationException
  | 
        
        
            | 
            | 
           423 | 
                * @param string $nodetext navigation node to click, may contain path, for example "Reports > Overview"
  | 
        
        
            | 
            | 
           424 | 
                * @return void
  | 
        
        
            | 
            | 
           425 | 
                */
  | 
        
        
            | 
            | 
           426 | 
               public function i_navigate_to_in_current_page_administration($nodetext) {
  | 
        
        
            | 
            | 
           427 | 
                   $nodelist = array_map('trim', explode('>', $nodetext));
  | 
        
        
            | 
            | 
           428 | 
                   $this->select_from_administration_menu($nodelist);
  | 
        
        
            | 
            | 
           429 | 
               }
  | 
        
        
            | 
            | 
           430 | 
              | 
        
        
            | 
            | 
           431 | 
               /**
  | 
        
        
            | 
            | 
           432 | 
                * Checks that current page administration contains text
  | 
        
        
            | 
            | 
           433 | 
                *
  | 
        
        
            | 
            | 
           434 | 
                * @Given /^"(?P<element_string>(?:[^"]|\\")*)" "(?P<selector_string>[^"]*)" should exist in current page administration$/
  | 
        
        
            | 
            | 
           435 | 
                *
  | 
        
        
            | 
            | 
           436 | 
                * @throws ExpectationException
  | 
        
        
            | 
            | 
           437 | 
                * @param string $element The locator of the specified selector.
  | 
        
        
            | 
            | 
           438 | 
                *     This may be a path, for example "Subscription mode > Forced subscription"
  | 
        
        
            | 
            | 
           439 | 
                * @param string $selectortype The selector type (link or text)
  | 
        
        
            | 
            | 
           440 | 
                * @return void
  | 
        
        
            | 
            | 
           441 | 
                */
  | 
        
        
            | 
            | 
           442 | 
               public function should_exist_in_current_page_administration($element, $selectortype) {
  | 
        
        
            | 
            | 
           443 | 
                   $nodes = array_map('trim', explode('>', $element));
  | 
        
        
            | 
            | 
           444 | 
                   $nodetext = end($nodes);
  | 
        
        
            | 
            | 
           445 | 
              | 
        
        
            | 
            | 
           446 | 
                   // Find administration menu.
  | 
        
        
            | 
            | 
           447 | 
                   if (!$menuxpath = $this->find_page_action_menu()) {
  | 
        
        
            | 
            | 
           448 | 
                       $menuxpath = $this->find_header_administration_menu() ?: $this->find_page_administration_menu(true);
  | 
        
        
            | 
            | 
           449 | 
                   }
  | 
        
        
            | 
            | 
           450 | 
              | 
        
        
            | 
            | 
           451 | 
                   $this->toggle_page_administration_menu($menuxpath);
  | 
        
        
            | 
            | 
           452 | 
                   $this->execute('behat_general::should_exist_in_the', [$nodetext, $selectortype, $menuxpath, 'xpath_element']);
  | 
        
        
            | 
            | 
           453 | 
                   $this->toggle_page_administration_menu($menuxpath);
  | 
        
        
            | 
            | 
           454 | 
               }
  | 
        
        
            | 
            | 
           455 | 
              | 
        
        
            | 
            | 
           456 | 
               /**
  | 
        
        
            | 
            | 
           457 | 
                * Checks that current page administration contains text
  | 
        
        
            | 
            | 
           458 | 
                *
  | 
        
        
            | 
            | 
           459 | 
                * @Given /^"(?P<element_string>(?:[^"]|\\")*)" "(?P<selector_string>[^"]*)" should not exist in current page administration$/
  | 
        
        
            | 
            | 
           460 | 
                *
  | 
        
        
            | 
            | 
           461 | 
                * @throws ExpectationException
  | 
        
        
            | 
            | 
           462 | 
                * @param string $element The locator of the specified selector.
  | 
        
        
            | 
            | 
           463 | 
                *     This may be a path, for example "Subscription mode > Forced subscription"
  | 
        
        
            | 
            | 
           464 | 
                * @param string $selectortype The selector type (link or text)
  | 
        
        
            | 
            | 
           465 | 
                * @return void
  | 
        
        
            | 
            | 
           466 | 
                */
  | 
        
        
            | 
            | 
           467 | 
               public function should_not_exist_in_current_page_administration($element, $selectortype) {
  | 
        
        
            | 
            | 
           468 | 
                   $nodes = array_map('trim', explode('>', $element));
  | 
        
        
            | 
            | 
           469 | 
                   $nodetext = end($nodes);
  | 
        
        
            | 
            | 
           470 | 
              | 
        
        
            | 
            | 
           471 | 
                   // Find administration menu.
  | 
        
        
            | 
            | 
           472 | 
                   $menuxpath = $this->find_header_administration_menu() ?: $this->find_page_administration_menu();
  | 
        
        
            | 
            | 
           473 | 
                   if (!$menuxpath) {
  | 
        
        
            | 
            | 
           474 | 
                       // Menu not found, exit.
  | 
        
        
            | 
            | 
           475 | 
                       return;
  | 
        
        
            | 
            | 
           476 | 
                   }
  | 
        
        
            | 
            | 
           477 | 
              | 
        
        
            | 
            | 
           478 | 
                   $this->toggle_page_administration_menu($menuxpath);
  | 
        
        
            | 
            | 
           479 | 
                   $this->execute('behat_general::should_not_exist_in_the', [$nodetext, $selectortype, $menuxpath, 'xpath_element']);
  | 
        
        
            | 
            | 
           480 | 
                   $this->toggle_page_administration_menu($menuxpath);
  | 
        
        
            | 
            | 
           481 | 
               }
  | 
        
        
            | 
            | 
           482 | 
              | 
        
        
            | 
            | 
           483 | 
               /**
  | 
        
        
            | 
            | 
           484 | 
                * Go to site administration item
  | 
        
        
            | 
            | 
           485 | 
                *
  | 
        
        
            | 
            | 
           486 | 
                * @Given /^I navigate to "(?P<nodetext_string>(?:[^"]|\\")*)" in site administration$/
  | 
        
        
            | 
            | 
           487 | 
                *
  | 
        
        
            | 
            | 
           488 | 
                * @throws ExpectationException
  | 
        
        
            | 
            | 
           489 | 
                * @param string $nodetext navigation node to click, may contain path, for example "Reports > Overview"
  | 
        
        
            | 
            | 
           490 | 
                * @return void
  | 
        
        
            | 
            | 
           491 | 
                */
  | 
        
        
            | 
            | 
           492 | 
               public function i_navigate_to_in_site_administration($nodetext) {
  | 
        
        
            | 
            | 
           493 | 
                   $nodelist = array_map('trim', explode('>', $nodetext));
  | 
        
        
            | 
            | 
           494 | 
                   $this->i_select_from_primary_navigation(get_string('administrationsite'));
  | 
        
        
            | 
            | 
           495 | 
                   $this->select_on_administration_page($nodelist);
  | 
        
        
            | 
            | 
           496 | 
               }
  | 
        
        
            | 
            | 
           497 | 
              | 
        
        
            | 
            | 
           498 | 
               /**
  | 
        
        
            | 
            | 
           499 | 
                * Opens the current users profile page in edit mode.
  | 
        
        
            | 
            | 
           500 | 
                *
  | 
        
        
            | 
            | 
           501 | 
                * @Given /^I open my profile in edit mode$/
  | 
        
        
            | 
            | 
           502 | 
                * @throws coding_exception
  | 
        
        
            | 
            | 
           503 | 
                * @return void
  | 
        
        
            | 
            | 
           504 | 
                */
  | 
        
        
            | 
            | 
           505 | 
               public function i_open_my_profile_in_edit_mode() {
  | 
        
        
            | 
            | 
           506 | 
                   global $USER;
  | 
        
        
            | 
            | 
           507 | 
              | 
        
        
            | 
            | 
           508 | 
                   $user = $this->get_session_user();
  | 
        
        
            | 
            | 
           509 | 
                   $globuser = $USER;
  | 
        
        
            | 
            | 
           510 | 
                   $USER = $user; // We need this set to the behat session user so we can call isloggedin.
  | 
        
        
            | 
            | 
           511 | 
              | 
        
        
            | 
            | 
           512 | 
                   $systemcontext = context_system::instance();
  | 
        
        
            | 
            | 
           513 | 
              | 
        
        
            | 
            | 
           514 | 
                   $bodynode = $this->find('xpath', 'body');
  | 
        
        
            | 
            | 
           515 | 
                   $bodyclass = $bodynode->getAttribute('class');
  | 
        
        
            | 
            | 
           516 | 
                   $matches = [];
  | 
        
        
            | 
            | 
           517 | 
                   if (preg_match('/(?<=^course-|\scourse-)\d+/', $bodyclass, $matches) && !empty($matches)) {
  | 
        
        
            | 
            | 
           518 | 
                       $courseid = intval($matches[0]);
  | 
        
        
            | 
            | 
           519 | 
                   } else {
  | 
        
        
            | 
            | 
           520 | 
                       $courseid = SITEID;
  | 
        
        
            | 
            | 
           521 | 
                   }
  | 
        
        
            | 
            | 
           522 | 
              | 
        
        
            | 
            | 
           523 | 
                   if (isloggedin() && !isguestuser($user) && !is_mnet_remote_user($user)) {
  | 
        
        
            | 
            | 
           524 | 
                       if (is_siteadmin($user) ||  has_capability('moodle/user:update', $systemcontext)) {
  | 
        
        
            | 
            | 
           525 | 
                           $url = new moodle_url('/user/editadvanced.php', array('id' => $user->id, 'course' => SITEID,
  | 
        
        
            | 
            | 
           526 | 
                               'returnto' => 'profile'));
  | 
        
        
            | 
            | 
           527 | 
                       } else if (has_capability('moodle/user:editownprofile', $systemcontext)) {
  | 
        
        
            | 
            | 
           528 | 
                           $userauthplugin = false;
  | 
        
        
            | 
            | 
           529 | 
                           if (!empty($user->auth)) {
  | 
        
        
            | 
            | 
           530 | 
                               $userauthplugin = get_auth_plugin($user->auth);
  | 
        
        
            | 
            | 
           531 | 
                           }
  | 
        
        
            | 
            | 
           532 | 
                           if ($userauthplugin && $userauthplugin->can_edit_profile()) {
  | 
        
        
            | 
            | 
           533 | 
                               $url = $userauthplugin->edit_profile_url();
  | 
        
        
            | 
            | 
           534 | 
                               if (empty($url)) {
  | 
        
        
            | 
            | 
           535 | 
                                   if (empty($course)) {
  | 
        
        
            | 
            | 
           536 | 
                                       $url = new moodle_url('/user/edit.php', array('id' => $user->id, 'returnto' => 'profile'));
  | 
        
        
            | 
            | 
           537 | 
                                   } else {
  | 
        
        
            | 
            | 
           538 | 
                                       $url = new moodle_url('/user/edit.php', array('id' => $user->id, 'course' => $courseid,
  | 
        
        
            | 
            | 
           539 | 
                                           'returnto' => 'profile'));
  | 
        
        
            | 
            | 
           540 | 
                                   }
  | 
        
        
            | 
            | 
           541 | 
                               }
  | 
        
        
            | 
            | 
           542 | 
              | 
        
        
            | 
            | 
           543 | 
                           }
  | 
        
        
            | 
            | 
           544 | 
                       }
  | 
        
        
            | 
            | 
           545 | 
                       $this->execute('behat_general::i_visit', [$url]);
  | 
        
        
            | 
            | 
           546 | 
                   }
  | 
        
        
            | 
            | 
           547 | 
              | 
        
        
            | 
            | 
           548 | 
                   // Restore global user variable.
  | 
        
        
            | 
            | 
           549 | 
                   $USER = $globuser;
  | 
        
        
            | 
            | 
           550 | 
               }
  | 
        
        
            | 
            | 
           551 | 
              | 
        
        
            | 
            | 
           552 | 
               /**
  | 
        
        
            | 
            | 
           553 | 
                * Open a given page, belonging to a plugin or core component.
  | 
        
        
            | 
            | 
           554 | 
                *
  | 
        
        
            | 
            | 
           555 | 
                * The page-type are interpreted by each plugin to work out the
  | 
        
        
            | 
            | 
           556 | 
                * corresponding URL. See the resolve_url method in each class like
  | 
        
        
            | 
            | 
           557 | 
                * behat_mod_forum. That method should document which page types are
  | 
        
        
            | 
            | 
           558 | 
                * recognised, and how the name identifies them.
  | 
        
        
            | 
            | 
           559 | 
                *
  | 
        
        
            | 
            | 
           560 | 
                * For pages belonging to core, the 'core > ' bit is omitted.
  | 
        
        
            | 
            | 
           561 | 
                *
  | 
        
        
            | 
            | 
           562 | 
                * @When /^I am on the (?<page>[^ "]*) page$/
  | 
        
        
            | 
            | 
           563 | 
                * @When /^I am on the "(?<page>[^"]*)" page$/
  | 
        
        
            | 
            | 
           564 | 
                *
  | 
        
        
            | 
            | 
           565 | 
                * @param string $page the component and page name.
  | 
        
        
            | 
            | 
           566 | 
                *      E.g. 'Admin notifications' or 'core_user > Preferences'.
  | 
        
        
            | 
            | 
           567 | 
                * @throws Exception if the specified page cannot be determined.
  | 
        
        
            | 
            | 
           568 | 
                */
  | 
        
        
            | 
            | 
           569 | 
               public function i_am_on_page(string $page) {
  | 
        
        
            | 
            | 
           570 | 
                   $this->execute('behat_general::i_visit', [$this->resolve_page_helper($page)]);
  | 
        
        
            | 
            | 
           571 | 
               }
  | 
        
        
            | 
            | 
           572 | 
              | 
        
        
            | 
            | 
           573 | 
               /**
  | 
        
        
            | 
            | 
           574 | 
                * Open a given page logged in as a given user.
  | 
        
        
            | 
            | 
           575 | 
                *
  | 
        
        
            | 
            | 
           576 | 
                * This is like the combination
  | 
        
        
            | 
            | 
           577 | 
                *   When I log in as "..."
  | 
        
        
            | 
            | 
           578 | 
                *   And I am on the "..." page
  | 
        
        
            | 
            | 
           579 | 
                * but with the advantage that you go straight to the desired page, without
  | 
        
        
            | 
            | 
           580 | 
                * having to wait for the Dashboard to load.
  | 
        
        
            | 
            | 
           581 | 
                *
  | 
        
        
            | 
            | 
           582 | 
                * @When /^I am on the (?<page>[^ "]*) page logged in as (?<username>[^ "]*)$/
  | 
        
        
            | 
            | 
           583 | 
                * @When /^I am on the "(?<page>[^"]*)" page logged in as (?<username>[^ "]*)$/
  | 
        
        
            | 
            | 
           584 | 
                * @When /^I am on the (?<page>[^ "]*) page logged in as "(?<username>[^ "]*)"$/
  | 
        
        
            | 
            | 
           585 | 
                * @When /^I am on the "(?<page>[^"]*)" page logged in as "(?<username>[^ "]*)"$/
  | 
        
        
            | 
            | 
           586 | 
                *
  | 
        
        
            | 
            | 
           587 | 
                * @param string $page the type of page. E.g. 'Admin notifications' or 'core_user > Preferences'.
  | 
        
        
            | 
            | 
           588 | 
                * @param string $username the name of the user to log in as. E.g. 'admin'.
  | 
        
        
            | 
            | 
           589 | 
                * @throws Exception if the specified page cannot be determined.
  | 
        
        
            | 
            | 
           590 | 
                */
  | 
        
        
            | 
            | 
           591 | 
               public function i_am_on_page_logged_in_as(string $page, string $username) {
  | 
        
        
            | 
            | 
           592 | 
                   self::execute('behat_auth::i_log_in_as', [$username, $this->resolve_page_helper($page)]);
  | 
        
        
            | 
            | 
           593 | 
               }
  | 
        
        
            | 
            | 
           594 | 
              | 
        
        
            | 
            | 
           595 | 
               /**
  | 
        
        
            | 
            | 
           596 | 
                * Helper used by i_am_on_page() and i_am_on_page_logged_in_as().
  | 
        
        
            | 
            | 
           597 | 
                *
  | 
        
        
            | 
            | 
           598 | 
                * @param string $page the type of page. E.g. 'Admin notifications' or 'core_user > Preferences'.
  | 
        
        
            | 
            | 
           599 | 
                * @return moodle_url the corresponding URL.
  | 
        
        
            | 
            | 
           600 | 
                */
  | 
        
        
            | 
            | 
           601 | 
               protected function resolve_page_helper(string $page): moodle_url {
  | 
        
        
            | 
            | 
           602 | 
                   list($component, $name) = $this->parse_page_name($page);
  | 
        
        
            | 
            | 
           603 | 
                   if ($component === 'core') {
  | 
        
        
            | 
            | 
           604 | 
                       return $this->resolve_core_page_url($name);
  | 
        
        
            | 
            | 
           605 | 
                   } else {
  | 
        
        
            | 
            | 
           606 | 
                       $context = behat_context_helper::get('behat_' . $component);
  | 
        
        
            | 
            | 
           607 | 
                       return $context->resolve_page_url($name);
  | 
        
        
            | 
            | 
           608 | 
                   }
  | 
        
        
            | 
            | 
           609 | 
               }
  | 
        
        
            | 
            | 
           610 | 
              | 
        
        
            | 
            | 
           611 | 
               /**
  | 
        
        
            | 
            | 
           612 | 
                * Parse a full page name like 'Admin notifications' or 'core_user > Preferences'.
  | 
        
        
            | 
            | 
           613 | 
                *
  | 
        
        
            | 
            | 
           614 | 
                * E.g. parsing 'mod_quiz > View' gives ['mod_quiz', 'View'].
  | 
        
        
            | 
            | 
           615 | 
                *
  | 
        
        
            | 
            | 
           616 | 
                * @param string $page the full page name
  | 
        
        
            | 
            | 
           617 | 
                * @return array with two elements, component and page name.
  | 
        
        
            | 
            | 
           618 | 
                */
  | 
        
        
            | 
            | 
           619 | 
               protected function parse_page_name(string $page): array {
  | 
        
        
            | 
            | 
           620 | 
                   $dividercount = substr_count($page, ' > ');
  | 
        
        
            | 
            | 
           621 | 
                   if ($dividercount === 0) {
  | 
        
        
            | 
            | 
           622 | 
                       return ['core', $page];
  | 
        
        
            | 
            | 
           623 | 
                   } else if ($dividercount >= 1) {
  | 
        
        
            | 
            | 
           624 | 
                       [$component, $name] = explode(' > ', $page, 2);
  | 
        
        
            | 
            | 
           625 | 
                       if ($component === 'core') {
  | 
        
        
            | 
            | 
           626 | 
                           throw new coding_exception('Do not specify the component "core > ..." for core pages.');
  | 
        
        
            | 
            | 
           627 | 
                       }
  | 
        
        
            | 
            | 
           628 | 
                       return [$component, $name];
  | 
        
        
            | 
            | 
           629 | 
                   } else {
  | 
        
        
            | 
            | 
           630 | 
                       throw new coding_exception('The page name must be in the form ' .
  | 
        
        
            | 
            | 
           631 | 
                               '"{page-name}" for core pages, or "{component} > {page-name}" ' .
  | 
        
        
            | 
            | 
           632 | 
                               'for pages belonging to other components. ' .
  | 
        
        
            | 
            | 
           633 | 
                               'For example "Admin notifications" or "mod_quiz > View".');
  | 
        
        
            | 
            | 
           634 | 
                   }
  | 
        
        
            | 
            | 
           635 | 
               }
  | 
        
        
            | 
            | 
           636 | 
              | 
        
        
            | 
            | 
           637 | 
               /**
  | 
        
        
            | 
            | 
           638 | 
                * Open a given instance of a page, belonging to a plugin or core component.
  | 
        
        
            | 
            | 
           639 | 
                *
  | 
        
        
            | 
            | 
           640 | 
                * The instance identifier and page-type are interpreted by each plugin to
  | 
        
        
            | 
            | 
           641 | 
                * work out the corresponding URL. See the resolve_page_instance_url method
  | 
        
        
            | 
            | 
           642 | 
                * in each class like behat_mod_forum. That method should document which page
  | 
        
        
            | 
            | 
           643 | 
                * types are recognised, and how the name identifies them.
  | 
        
        
            | 
            | 
           644 | 
                *
  | 
        
        
            | 
            | 
           645 | 
                * For pages belonging to core, the 'core > ' bit is omitted.
  | 
        
        
            | 
            | 
           646 | 
                *
  | 
        
        
            | 
            | 
           647 | 
                * @When /^I am on the (?<identifier>[^ "]*) (?<type>[^ "]*) page$/
  | 
        
        
            | 
            | 
           648 | 
                * @When /^I am on the "(?<identifier>[^"]*)" "(?<type>[^"]*)" page$/
  | 
        
        
            | 
            | 
           649 | 
                * @When /^I am on the (?<identifier>[^ "]*) "(?<type>[^"]*)" page$/
  | 
        
        
            | 
            | 
           650 | 
                * @When /^I am on the "(?<identifier>[^"]*)" (?<type>[^ "]*) page$/
  | 
        
        
            | 
            | 
           651 | 
                *
  | 
        
        
            | 
            | 
           652 | 
                * @param string $identifier identifies the particular page. E.g. 'Test quiz'.
  | 
        
        
            | 
            | 
           653 | 
                * @param string $type the component and page type. E.g. 'mod_quiz > View'.
  | 
        
        
            | 
            | 
           654 | 
                * @throws Exception if the specified page cannot be determined.
  | 
        
        
            | 
            | 
           655 | 
                */
  | 
        
        
            | 
            | 
           656 | 
               public function i_am_on_page_instance(string $identifier, string $type) {
  | 
        
        
            | 
            | 
           657 | 
                   $this->execute('behat_general::i_visit', [$this->resolve_page_instance_helper($identifier, $type)]);
  | 
        
        
            | 
            | 
           658 | 
               }
  | 
        
        
            | 
            | 
           659 | 
              | 
        
        
            | 
            | 
           660 | 
               /**
  | 
        
        
            | 
            | 
           661 | 
                * Open a given page logged in as a given user.
  | 
        
        
            | 
            | 
           662 | 
                *
  | 
        
        
            | 
            | 
           663 | 
                * This is like the combination
  | 
        
        
            | 
            | 
           664 | 
                *   When I log in as "..."
  | 
        
        
            | 
            | 
           665 | 
                *   And I am on the "..." "..." page
  | 
        
        
            | 
            | 
           666 | 
                * but with the advantage that you go straight to the desired page, without
  | 
        
        
            | 
            | 
           667 | 
                * having to wait for the Dashboard to load.
  | 
        
        
            | 
            | 
           668 | 
                *
  | 
        
        
            | 
            | 
           669 | 
                * @When /^I am on the (?<identifier>[^ "]*) (?<type>[^ "]*) page logged in as (?<username>[^ "]*)$/
  | 
        
        
            | 
            | 
           670 | 
                * @When /^I am on the "(?<identifier>[^"]*)" "(?<type>[^"]*)" page logged in as (?<username>[^ "]*)$/
  | 
        
        
            | 
            | 
           671 | 
                * @When /^I am on the (?<identifier>[^ "]*) "(?<type>[^"]*)" page logged in as (?<username>[^ "]*)$/
  | 
        
        
            | 
            | 
           672 | 
                * @When /^I am on the "(?<identifier>[^"]*)" (?<type>[^ "]*) page logged in as (?<username>[^ "]*)$/
  | 
        
        
            | 
            | 
           673 | 
                * @When /^I am on the (?<identifier>[^ "]*) (?<type>[^ "]*) page logged in as "(?<username>[^"]*)"$/
  | 
        
        
            | 
            | 
           674 | 
                * @When /^I am on the "(?<identifier>[^"]*)" "(?<type>[^"]*)" page logged in as "(?<username>[^"]*)"$/
  | 
        
        
            | 
            | 
           675 | 
                * @When /^I am on the (?<identifier>[^ "]*) "(?<type>[^"]*)" page logged in as "(?<username>[^"]*)"$/
  | 
        
        
            | 
            | 
           676 | 
                * @When /^I am on the "(?<identifier>[^"]*)" (?<type>[^ "]*) page logged in as "(?<username>[^"]*)"$/
  | 
        
        
            | 
            | 
           677 | 
                *
  | 
        
        
            | 
            | 
           678 | 
                * @param string $identifier identifies the particular page. E.g. 'Test quiz'.
  | 
        
        
            | 
            | 
           679 | 
                * @param string $type the component and page type. E.g. 'mod_quiz > View'.
  | 
        
        
            | 
            | 
           680 | 
                * @param string $username the name of the user to log in as. E.g. 'student'.
  | 
        
        
            | 
            | 
           681 | 
                * @throws Exception if the specified page cannot be determined.
  | 
        
        
            | 
            | 
           682 | 
                */
  | 
        
        
            | 
            | 
           683 | 
               public function i_am_on_page_instance_logged_in_as(string $identifier,
  | 
        
        
            | 
            | 
           684 | 
                       string $type, string $username) {
  | 
        
        
            | 
            | 
           685 | 
                   self::execute('behat_auth::i_log_in_as',
  | 
        
        
            | 
            | 
           686 | 
                           [$username, $this->resolve_page_instance_helper($identifier, $type)]);
  | 
        
        
            | 
            | 
           687 | 
               }
  | 
        
        
            | 
            | 
           688 | 
              | 
        
        
            | 
            | 
           689 | 
               /**
  | 
        
        
            | 
            | 
           690 | 
                * Helper used by i_am_on_page() and i_am_on_page_logged_in_as().
  | 
        
        
            | 
            | 
           691 | 
                *
  | 
        
        
            | 
            | 
           692 | 
                * @param string $identifier identifies the particular page. E.g. 'Test quiz'.
  | 
        
        
            | 
            | 
           693 | 
                * @param string $pagetype the component and page type. E.g. 'mod_quiz > View'.
  | 
        
        
            | 
            | 
           694 | 
                * @return moodle_url the corresponding URL.
  | 
        
        
            | 
            | 
           695 | 
                */
  | 
        
        
            | 
            | 
           696 | 
               protected function resolve_page_instance_helper(string $identifier, string $pagetype): moodle_url {
  | 
        
        
            | 
            | 
           697 | 
                   list($component, $type) = $this->parse_page_name($pagetype);
  | 
        
        
            | 
            | 
           698 | 
                   if ($component === 'core') {
  | 
        
        
            | 
            | 
           699 | 
                       return $this->resolve_core_page_instance_url($type, $identifier);
  | 
        
        
            | 
            | 
           700 | 
                   } else {
  | 
        
        
            | 
            | 
           701 | 
                       $context = behat_context_helper::get('behat_' . $component);
  | 
        
        
            | 
            | 
           702 | 
                       return $context->resolve_page_instance_url($type, $identifier);
  | 
        
        
            | 
            | 
           703 | 
                   }
  | 
        
        
            | 
            | 
           704 | 
               }
  | 
        
        
            | 
            | 
           705 | 
              | 
        
        
            | 
            | 
           706 | 
               /**
  | 
        
        
            | 
            | 
           707 | 
                * Convert core page names to URLs for steps like 'When I am on the "[page name]" page'.
  | 
        
        
            | 
            | 
           708 | 
                *
  | 
        
        
            | 
            | 
           709 | 
                * Recognised page names are:
  | 
        
        
            | 
            | 
           710 | 
                * | Homepage            | Homepage (normally dashboard).                                 |
  | 
        
        
            | 
            | 
           711 | 
                * | Admin notifications | Admin notification screen.                                     |
  | 
        
        
            | 
            | 
           712 | 
                *
  | 
        
        
            | 
            | 
           713 | 
                * @param string $name identifies which identifies this page, e.g. 'Homepage', 'Admin notifications'.
  | 
        
        
            | 
            | 
           714 | 
                * @return moodle_url the corresponding URL.
  | 
        
        
            | 
            | 
           715 | 
                * @throws Exception with a meaningful error message if the specified page cannot be found.
  | 
        
        
            | 
            | 
           716 | 
                */
  | 
        
        
            | 
            | 
           717 | 
               protected function resolve_core_page_url(string $name): moodle_url {
  | 
        
        
            | 
            | 
           718 | 
                   switch ($name) {
  | 
        
        
            | 
            | 
           719 | 
                       case 'Homepage':
  | 
        
        
            | 
            | 
           720 | 
                           return new moodle_url('/');
  | 
        
        
            | 
            | 
           721 | 
              | 
        
        
            | 
            | 
           722 | 
                       case 'My courses':
  | 
        
        
            | 
            | 
           723 | 
                           return new moodle_url('/my/courses.php');
  | 
        
        
            | 
            | 
           724 | 
              | 
        
        
            | 
            | 
           725 | 
                       case 'Admin notifications':
  | 
        
        
            | 
            | 
           726 | 
                           return new moodle_url('/admin/');
  | 
        
        
            | 
            | 
           727 | 
              | 
        
        
           | 11 | 
           efrain | 
           728 | 
                       case 'Content bank':
  | 
        
        
            | 
            | 
           729 | 
                           return new moodle_url('/contentbank/');
  | 
        
        
            | 
            | 
           730 | 
              | 
        
        
           | 1 | 
           efrain | 
           731 | 
                       case 'My private files':
  | 
        
        
            | 
            | 
           732 | 
                           return new moodle_url('/user/files.php');
  | 
        
        
            | 
            | 
           733 | 
              | 
        
        
            | 
            | 
           734 | 
                       case 'System logs report':
  | 
        
        
            | 
            | 
           735 | 
                           return new moodle_url('/report/log/index.php');
  | 
        
        
            | 
            | 
           736 | 
              | 
        
        
            | 
            | 
           737 | 
                       case 'Profile':
  | 
        
        
            | 
            | 
           738 | 
                           return new moodle_url('/user/view.php');
  | 
        
        
            | 
            | 
           739 | 
              | 
        
        
            | 
            | 
           740 | 
                       case 'Profile advanced editing':
  | 
        
        
            | 
            | 
           741 | 
                           return new moodle_url('/user/editadvanced.php', ['returnto' => 'profile']);
  | 
        
        
            | 
            | 
           742 | 
              | 
        
        
            | 
            | 
           743 | 
                       case 'Profile editing':
  | 
        
        
            | 
            | 
           744 | 
                           return new moodle_url('/user/edit.php', ['returnto' => 'profile']);
  | 
        
        
            | 
            | 
           745 | 
              | 
        
        
            | 
            | 
           746 | 
                       default:
  | 
        
        
            | 
            | 
           747 | 
                           throw new Exception('Unrecognised core page type "' . $name . '."');
  | 
        
        
            | 
            | 
           748 | 
                   }
  | 
        
        
            | 
            | 
           749 | 
               }
  | 
        
        
            | 
            | 
           750 | 
              | 
        
        
            | 
            | 
           751 | 
               /**
  | 
        
        
            | 
            | 
           752 | 
                * Convert page names to URLs for steps like 'When I am on the "[identifier]" "[page type]" page'.
  | 
        
        
            | 
            | 
           753 | 
                *
  | 
        
        
            | 
            | 
           754 | 
                * Recognised page names are:
  | 
        
        
            | 
            | 
           755 | 
                * | Page type                       | Identifier meaning        | description                                                      |
  | 
        
        
            | 
            | 
           756 | 
                * | Category                        | category idnumber         | List of courses in that category.                                |
  | 
        
        
            | 
            | 
           757 | 
                * | Course                          | course shortname          | Main course home pag                                             |
  | 
        
        
            | 
            | 
           758 | 
                * | Course editing                  | course shortname          | Edit settings page for the course                                |
  | 
        
        
            | 
            | 
           759 | 
                * | Activity                        | activity idnumber         | Start page for that activity                                     |
  | 
        
        
            | 
            | 
           760 | 
                * | Activity editing                | activity idnumber         | Edit settings page for that activity                             |
  | 
        
        
            | 
            | 
           761 | 
                * | [modname] Activity              | activity name or idnumber | Start page for that activity                                     |
  | 
        
        
            | 
            | 
           762 | 
                * | [modname] Activity editing      | activity name or idnumber | Edit settings page for that activity                             |
  | 
        
        
            | 
            | 
           763 | 
                * | Backup                          | course shortname          | Course to backup                                                 |
  | 
        
        
            | 
            | 
           764 | 
                * | Import                          | course shortname          | Course import from                                               |
  | 
        
        
            | 
            | 
           765 | 
                * | Restore                         | course shortname          | Course to restore from                                           |
  | 
        
        
            | 
            | 
           766 | 
                * | Reset                           | course shortname          | Course to reset                                                  |
  | 
        
        
            | 
            | 
           767 | 
                * | Course copy                     | course shortname          | Course to copy                                                   |
  | 
        
        
            | 
            | 
           768 | 
                * | Groups                          | course shortname          | Groups page for the course                                       |
  | 
        
        
            | 
            | 
           769 | 
                * | Groups overview                 | course shortname          | Groups overview page for the course                              |
  | 
        
        
            | 
            | 
           770 | 
                * | Groupings                       | course shortname          | Groupings page for the course                                    |
  | 
        
        
            | 
            | 
           771 | 
                * | Permissions                     | course shortname          | Permissions page for the course                                  |
  | 
        
        
            | 
            | 
           772 | 
                * | Enrolment methods               | course shortname          | Enrolment methods for the course                                 |
  | 
        
        
            | 
            | 
           773 | 
                * | Enrolled users                  | course shortname          | The main participants page                                       |
  | 
        
        
            | 
            | 
           774 | 
                * | Other users                     | course shortname          | The course other users page                                      |
  | 
        
        
            | 
            | 
           775 | 
                * | Course profile                  | course shortname          | The current user's profile for this course                       |
  | 
        
        
            | 
            | 
           776 | 
                * | Course profile editing          | course shortname          | The current user's profile editing page for this course          |
  | 
        
        
            | 
            | 
           777 | 
                * | Course profile advanced editing | course shortname          | The current user's advanced profile editing page for this course |
  | 
        
        
            | 
            | 
           778 | 
                *
  | 
        
        
            | 
            | 
           779 | 
                * Examples:
  | 
        
        
            | 
            | 
           780 | 
                *
  | 
        
        
            | 
            | 
           781 | 
                * When I am on the "Welcome to ECON101" "forum activity" page logged in as student1
  | 
        
        
            | 
            | 
           782 | 
                *
  | 
        
        
            | 
            | 
           783 | 
                * @param string $type identifies which type of page this is, e.g. 'Category page'.
  | 
        
        
            | 
            | 
           784 | 
                * @param string $identifier identifies the particular page, e.g. 'test-cat'.
  | 
        
        
            | 
            | 
           785 | 
                * @return moodle_url the corresponding URL.
  | 
        
        
            | 
            | 
           786 | 
                * @throws Exception with a meaningful error message if the specified page cannot be found.
  | 
        
        
            | 
            | 
           787 | 
                */
  | 
        
        
            | 
            | 
           788 | 
               protected function resolve_core_page_instance_url(string $type, string $identifier): moodle_url {
  | 
        
        
            | 
            | 
           789 | 
                   $type = strtolower($type);
  | 
        
        
            | 
            | 
           790 | 
                   $coursenotfoundexception = new Exception(
  | 
        
        
            | 
            | 
           791 | 
                       "The specified course with shortname, fullname, or idnumber '{$identifier}' does not exist",
  | 
        
        
            | 
            | 
           792 | 
                   );
  | 
        
        
            | 
            | 
           793 | 
              | 
        
        
            | 
            | 
           794 | 
                   switch ($type) {
  | 
        
        
            | 
            | 
           795 | 
                       case 'category':
  | 
        
        
            | 
            | 
           796 | 
                           $categoryid = $this->get_category_id($identifier);
  | 
        
        
            | 
            | 
           797 | 
                           if (!$categoryid) {
  | 
        
        
            | 
            | 
           798 | 
                               throw new Exception('The specified category with idnumber "' . $identifier . '" does not exist');
  | 
        
        
            | 
            | 
           799 | 
                           }
  | 
        
        
            | 
            | 
           800 | 
                           return new moodle_url('/course/index.php', ['categoryid' => $categoryid]);
  | 
        
        
            | 
            | 
           801 | 
              | 
        
        
            | 
            | 
           802 | 
                       case 'course editing':
  | 
        
        
            | 
            | 
           803 | 
                           $courseid = $this->get_course_id($identifier);
  | 
        
        
            | 
            | 
           804 | 
                           if (!$courseid) {
  | 
        
        
            | 
            | 
           805 | 
                               throw $coursenotfoundexception;
  | 
        
        
            | 
            | 
           806 | 
                           }
  | 
        
        
            | 
            | 
           807 | 
                           return new moodle_url('/course/edit.php', ['id' => $courseid]);
  | 
        
        
            | 
            | 
           808 | 
              | 
        
        
            | 
            | 
           809 | 
                       case 'course':
  | 
        
        
            | 
            | 
           810 | 
                           $courseid = $this->get_course_id($identifier);
  | 
        
        
            | 
            | 
           811 | 
                           if (!$courseid) {
  | 
        
        
            | 
            | 
           812 | 
                               throw $coursenotfoundexception;
  | 
        
        
            | 
            | 
           813 | 
                           }
  | 
        
        
            | 
            | 
           814 | 
                           return new moodle_url('/course/view.php', ['id' => $courseid]);
  | 
        
        
            | 
            | 
           815 | 
              | 
        
        
            | 
            | 
           816 | 
                       case 'activity':
  | 
        
        
            | 
            | 
           817 | 
                           $cm = $this->get_course_module_for_identifier($identifier);
  | 
        
        
            | 
            | 
           818 | 
                           if (!$cm) {
  | 
        
        
            | 
            | 
           819 | 
                               throw new Exception('The specified activity with idnumber "' . $identifier . '" does not exist');
  | 
        
        
            | 
            | 
           820 | 
                           }
  | 
        
        
            | 
            | 
           821 | 
                           return $cm->url;
  | 
        
        
            | 
            | 
           822 | 
              | 
        
        
            | 
            | 
           823 | 
                       case 'activity editing':
  | 
        
        
            | 
            | 
           824 | 
                           $cm = $this->get_course_module_for_identifier($identifier);
  | 
        
        
            | 
            | 
           825 | 
                           if (!$cm) {
  | 
        
        
            | 
            | 
           826 | 
                               throw new Exception('The specified activity with idnumber "' . $identifier . '" does not exist');
  | 
        
        
            | 
            | 
           827 | 
                           }
  | 
        
        
            | 
            | 
           828 | 
                           return new moodle_url('/course/modedit.php', [
  | 
        
        
            | 
            | 
           829 | 
                               'update' => $cm->id,
  | 
        
        
            | 
            | 
           830 | 
                           ]);
  | 
        
        
            | 
            | 
           831 | 
                       case 'backup':
  | 
        
        
            | 
            | 
           832 | 
                           $courseid = $this->get_course_id($identifier);
  | 
        
        
            | 
            | 
           833 | 
                           if (!$courseid) {
  | 
        
        
            | 
            | 
           834 | 
                               throw $coursenotfoundexception;
  | 
        
        
            | 
            | 
           835 | 
                           }
  | 
        
        
            | 
            | 
           836 | 
                           return new moodle_url('/backup/backup.php', ['id' => $courseid]);
  | 
        
        
            | 
            | 
           837 | 
                       case 'import':
  | 
        
        
            | 
            | 
           838 | 
                           $courseid = $this->get_course_id($identifier);
  | 
        
        
            | 
            | 
           839 | 
                           if (!$courseid) {
  | 
        
        
            | 
            | 
           840 | 
                               throw $coursenotfoundexception;
  | 
        
        
            | 
            | 
           841 | 
                           }
  | 
        
        
            | 
            | 
           842 | 
                           return new moodle_url('/backup/import.php', ['id' => $courseid]);
  | 
        
        
            | 
            | 
           843 | 
                       case 'restore':
  | 
        
        
            | 
            | 
           844 | 
                           $courseid = $this->get_course_id($identifier);
  | 
        
        
            | 
            | 
           845 | 
                           if (!$courseid) {
  | 
        
        
            | 
            | 
           846 | 
                               throw $coursenotfoundexception;
  | 
        
        
            | 
            | 
           847 | 
                           }
  | 
        
        
            | 
            | 
           848 | 
                           $context = context_course::instance($courseid);
  | 
        
        
            | 
            | 
           849 | 
                           return new moodle_url('/backup/restorefile.php', ['contextid' => $context->id]);
  | 
        
        
            | 
            | 
           850 | 
                       case 'reset':
  | 
        
        
            | 
            | 
           851 | 
                           $courseid = $this->get_course_id($identifier);
  | 
        
        
            | 
            | 
           852 | 
                           if (!$courseid) {
  | 
        
        
            | 
            | 
           853 | 
                               throw $coursenotfoundexception;
  | 
        
        
            | 
            | 
           854 | 
                           }
  | 
        
        
            | 
            | 
           855 | 
                           return new moodle_url('/course/reset.php', ['id' => $courseid]);
  | 
        
        
            | 
            | 
           856 | 
                       case 'course copy':
  | 
        
        
            | 
            | 
           857 | 
                           $courseid = $this->get_course_id($identifier);
  | 
        
        
            | 
            | 
           858 | 
                           if (!$courseid) {
  | 
        
        
            | 
            | 
           859 | 
                               throw $coursenotfoundexception;
  | 
        
        
            | 
            | 
           860 | 
                           }
  | 
        
        
            | 
            | 
           861 | 
                           return new moodle_url('/backup/copy.php', ['id' => $courseid]);
  | 
        
        
            | 
            | 
           862 | 
                       case 'groups':
  | 
        
        
            | 
            | 
           863 | 
                           $courseid = $this->get_course_id($identifier);
  | 
        
        
            | 
            | 
           864 | 
                           if (!$courseid) {
  | 
        
        
            | 
            | 
           865 | 
                               throw $coursenotfoundexception;
  | 
        
        
            | 
            | 
           866 | 
                           }
  | 
        
        
            | 
            | 
           867 | 
                           return new moodle_url('/group/index.php', ['id' => $courseid]);
  | 
        
        
            | 
            | 
           868 | 
                       case 'groups overview':
  | 
        
        
            | 
            | 
           869 | 
                           $courseid = $this->get_course_id($identifier);
  | 
        
        
            | 
            | 
           870 | 
                           if (!$courseid) {
  | 
        
        
            | 
            | 
           871 | 
                               throw $coursenotfoundexception;
  | 
        
        
            | 
            | 
           872 | 
                           }
  | 
        
        
            | 
            | 
           873 | 
                           return new moodle_url('/group/overview.php', ['id' => $courseid]);
  | 
        
        
            | 
            | 
           874 | 
                       case 'groupings':
  | 
        
        
            | 
            | 
           875 | 
                           $courseid = $this->get_course_id($identifier);
  | 
        
        
            | 
            | 
           876 | 
                           if (!$courseid) {
  | 
        
        
            | 
            | 
           877 | 
                               throw $coursenotfoundexception;
  | 
        
        
            | 
            | 
           878 | 
                           }
  | 
        
        
            | 
            | 
           879 | 
                           return new moodle_url('/group/groupings.php', ['id' => $courseid]);
  | 
        
        
            | 
            | 
           880 | 
                       case 'permissions':
  | 
        
        
            | 
            | 
           881 | 
                           $courseid = $this->get_course_id($identifier);
  | 
        
        
            | 
            | 
           882 | 
                           if (!$courseid) {
  | 
        
        
            | 
            | 
           883 | 
                               throw $coursenotfoundexception;
  | 
        
        
            | 
            | 
           884 | 
                           }
  | 
        
        
            | 
            | 
           885 | 
                           $context = context_course::instance($courseid);
  | 
        
        
            | 
            | 
           886 | 
                           return new moodle_url('/admin/roles/permissions.php', ['contextid' => $context->id]);
  | 
        
        
            | 
            | 
           887 | 
                       case 'enrolment methods':
  | 
        
        
            | 
            | 
           888 | 
                           $courseid = $this->get_course_id($identifier);
  | 
        
        
            | 
            | 
           889 | 
                           if (!$courseid) {
  | 
        
        
            | 
            | 
           890 | 
                               throw $coursenotfoundexception;
  | 
        
        
            | 
            | 
           891 | 
                           }
  | 
        
        
            | 
            | 
           892 | 
                           return new moodle_url('/enrol/instances.php', ['id' => $courseid]);
  | 
        
        
            | 
            | 
           893 | 
                       case 'enrolled users':
  | 
        
        
            | 
            | 
           894 | 
                           $courseid = $this->get_course_id($identifier);
  | 
        
        
            | 
            | 
           895 | 
                           if (!$courseid) {
  | 
        
        
            | 
            | 
           896 | 
                               throw $coursenotfoundexception;
  | 
        
        
            | 
            | 
           897 | 
                           }
  | 
        
        
            | 
            | 
           898 | 
                           return new moodle_url('/user/index.php', ['id' => $courseid]);
  | 
        
        
            | 
            | 
           899 | 
                       case 'other users':
  | 
        
        
            | 
            | 
           900 | 
                           $courseid = $this->get_course_id($identifier);
  | 
        
        
            | 
            | 
           901 | 
                           if (!$courseid) {
  | 
        
        
            | 
            | 
           902 | 
                               throw $coursenotfoundexception;
  | 
        
        
            | 
            | 
           903 | 
                           }
  | 
        
        
            | 
            | 
           904 | 
                           return new moodle_url('/enrol/otherusers.php', ['id' => $courseid]);
  | 
        
        
            | 
            | 
           905 | 
                       case 'renameroles':
  | 
        
        
            | 
            | 
           906 | 
                           $courseid = $this->get_course_id($identifier);
  | 
        
        
            | 
            | 
           907 | 
                           if (!$courseid) {
  | 
        
        
            | 
            | 
           908 | 
                               throw $coursenotfoundexception;
  | 
        
        
            | 
            | 
           909 | 
                           }
  | 
        
        
            | 
            | 
           910 | 
                           return new moodle_url('/enrol/renameroles.php', ['id' => $courseid]);
  | 
        
        
            | 
            | 
           911 | 
              | 
        
        
            | 
            | 
           912 | 
                       case 'course profile':
  | 
        
        
            | 
            | 
           913 | 
                           $courseid = $this->get_course_id($identifier);
  | 
        
        
            | 
            | 
           914 | 
                           if (!$courseid) {
  | 
        
        
            | 
            | 
           915 | 
                               throw $coursenotfoundexception;
  | 
        
        
            | 
            | 
           916 | 
                           }
  | 
        
        
            | 
            | 
           917 | 
                           return new moodle_url('/user/user.php', ['course' => $courseid]);
  | 
        
        
            | 
            | 
           918 | 
              | 
        
        
            | 
            | 
           919 | 
                       case 'course profile editing':
  | 
        
        
            | 
            | 
           920 | 
                           $courseid = $this->get_course_id($identifier);
  | 
        
        
            | 
            | 
           921 | 
                           if (!$courseid) {
  | 
        
        
            | 
            | 
           922 | 
                               throw $coursenotfoundexception;
  | 
        
        
            | 
            | 
           923 | 
                           }
  | 
        
        
            | 
            | 
           924 | 
                           return new moodle_url('/user/edit.php', [
  | 
        
        
            | 
            | 
           925 | 
                               'course' => $courseid,
  | 
        
        
            | 
            | 
           926 | 
                               'returnto' => 'profile',
  | 
        
        
            | 
            | 
           927 | 
                           ]);
  | 
        
        
            | 
            | 
           928 | 
              | 
        
        
            | 
            | 
           929 | 
                       case 'course profile advanced editing':
  | 
        
        
            | 
            | 
           930 | 
                           $courseid = $this->get_course_id($identifier);
  | 
        
        
            | 
            | 
           931 | 
                           if (!$courseid) {
  | 
        
        
            | 
            | 
           932 | 
                               throw $coursenotfoundexception;
  | 
        
        
            | 
            | 
           933 | 
                           }
  | 
        
        
            | 
            | 
           934 | 
                           return new moodle_url('/user/editadvanced.php', [
  | 
        
        
            | 
            | 
           935 | 
                               'course' => $courseid,
  | 
        
        
            | 
            | 
           936 | 
                               'returnto' => 'profile',
  | 
        
        
            | 
            | 
           937 | 
                           ]);
  | 
        
        
            | 
            | 
           938 | 
                   }
  | 
        
        
            | 
            | 
           939 | 
              | 
        
        
           | 1441 | 
           ariadna | 
           940 | 
                   // This next section handles page types starting with an activity name. For example:
  | 
        
        
            | 
            | 
           941 | 
                   // "forum activity" or "quiz activity editing".
  | 
        
        
           | 1 | 
           efrain | 
           942 | 
                   $parts = explode(' ', $type);
  | 
        
        
            | 
            | 
           943 | 
                   if (count($parts) > 1) {
  | 
        
        
           | 1441 | 
           ariadna | 
           944 | 
                       $modname = $parts[0];
  | 
        
        
           | 1 | 
           efrain | 
           945 | 
                       if ($parts[1] === 'activity') {
  | 
        
        
            | 
            | 
           946 | 
                           $cm = $this->get_cm_by_activity_name($modname, $identifier);
  | 
        
        
            | 
            | 
           947 | 
              | 
        
        
            | 
            | 
           948 | 
                           if (count($parts) == 2) {
  | 
        
        
            | 
            | 
           949 | 
                               // View page.
  | 
        
        
            | 
            | 
           950 | 
                               return new moodle_url($cm->url);
  | 
        
        
            | 
            | 
           951 | 
                           }
  | 
        
        
            | 
            | 
           952 | 
              | 
        
        
            | 
            | 
           953 | 
                           if ($parts[2] === 'editing') {
  | 
        
        
            | 
            | 
           954 | 
                               // Edit settings page.
  | 
        
        
            | 
            | 
           955 | 
                               return new moodle_url('/course/modedit.php', ['update' => $cm->id]);
  | 
        
        
            | 
            | 
           956 | 
                           }
  | 
        
        
            | 
            | 
           957 | 
              | 
        
        
            | 
            | 
           958 | 
                           if ($parts[2] === 'roles') {
  | 
        
        
            | 
            | 
           959 | 
                               // Locally assigned roles page.
  | 
        
        
            | 
            | 
           960 | 
                               return new moodle_url('/admin/roles/assign.php', ['contextid' => $cm->context->id]);
  | 
        
        
            | 
            | 
           961 | 
                           }
  | 
        
        
            | 
            | 
           962 | 
              | 
        
        
            | 
            | 
           963 | 
                           if ($parts[2] === 'permissions') {
  | 
        
        
            | 
            | 
           964 | 
                               // Permissions page.
  | 
        
        
            | 
            | 
           965 | 
                               return new moodle_url('/admin/roles/permissions.php', ['contextid' => $cm->context->id]);
  | 
        
        
            | 
            | 
           966 | 
                           }
  | 
        
        
           | 1441 | 
           ariadna | 
           967 | 
              | 
        
        
            | 
            | 
           968 | 
                       } else if ($parts[1] === 'index' && count($parts) == 2) {
  | 
        
        
            | 
            | 
           969 | 
                           $courseid = $this->get_course_id($identifier);
  | 
        
        
            | 
            | 
           970 | 
                           if (!$courseid) {
  | 
        
        
            | 
            | 
           971 | 
                               throw $coursenotfoundexception;
  | 
        
        
            | 
            | 
           972 | 
                           }
  | 
        
        
            | 
            | 
           973 | 
                           return new moodle_url("/mod/$modname/index.php", ['id' => $courseid]);
  | 
        
        
           | 1 | 
           efrain | 
           974 | 
                       }
  | 
        
        
            | 
            | 
           975 | 
                   }
  | 
        
        
            | 
            | 
           976 | 
              | 
        
        
            | 
            | 
           977 | 
                   throw new Exception('Unrecognised core page type "' . $type . '."');
  | 
        
        
            | 
            | 
           978 | 
               }
  | 
        
        
            | 
            | 
           979 | 
              | 
        
        
            | 
            | 
           980 | 
               /**
  | 
        
        
            | 
            | 
           981 | 
                * Opens a new tab with given name on the same URL as current page and switches to it.
  | 
        
        
            | 
            | 
           982 | 
                *
  | 
        
        
            | 
            | 
           983 | 
                * @param string $name Tab name that can be used for switching later (no whitespace)
  | 
        
        
            | 
            | 
           984 | 
                * @When /^I open a tab named "(?<name>[^"]*)" on the current page$/
  | 
        
        
            | 
            | 
           985 | 
                */
  | 
        
        
            | 
            | 
           986 | 
               public function i_open_a_tab_on_the_current_page(string $name): void {
  | 
        
        
            | 
            | 
           987 | 
                   $this->open_tab($name, 'location.href');
  | 
        
        
            | 
            | 
           988 | 
               }
  | 
        
        
            | 
            | 
           989 | 
              | 
        
        
            | 
            | 
           990 | 
               /**
  | 
        
        
            | 
            | 
           991 | 
                * Opens a new tab with given name on specified page, and switches to it.
  | 
        
        
            | 
            | 
           992 | 
                *
  | 
        
        
            | 
            | 
           993 | 
                * @param string $name Tab name that can be used for switching later (no whitespace)
  | 
        
        
            | 
            | 
           994 | 
                * @param string $page Page name
  | 
        
        
            | 
            | 
           995 | 
                * @When /^I open a tab named "(?<name>[^"]*)" on the "(?<page>[^"]*)" page$/
  | 
        
        
            | 
            | 
           996 | 
                */
  | 
        
        
            | 
            | 
           997 | 
               public function i_open_a_tab_on_the_page(string $name, string $page): void {
  | 
        
        
            | 
            | 
           998 | 
                   if ($page === 'current') {
  | 
        
        
            | 
            | 
           999 | 
                       $jstarget = 'location.href';
  | 
        
        
            | 
            | 
           1000 | 
                   } else {
  | 
        
        
            | 
            | 
           1001 | 
                       $jstarget = '"' . addslashes_js($this->resolve_page_helper($page)->out(false)) . '"';
  | 
        
        
            | 
            | 
           1002 | 
                   }
  | 
        
        
            | 
            | 
           1003 | 
                   $this->open_tab($name, $jstarget);
  | 
        
        
            | 
            | 
           1004 | 
               }
  | 
        
        
            | 
            | 
           1005 | 
              | 
        
        
            | 
            | 
           1006 | 
               /**
  | 
        
        
            | 
            | 
           1007 | 
                * Opens a new tab with given name (on specified page), and switches to it.
  | 
        
        
            | 
            | 
           1008 | 
                *
  | 
        
        
            | 
            | 
           1009 | 
                * @param string $name Tab name that can be used for switching later (no whitespace)
  | 
        
        
            | 
            | 
           1010 | 
                * @param string $identifier Page identifier
  | 
        
        
            | 
            | 
           1011 | 
                * @param string $page Page type
  | 
        
        
            | 
            | 
           1012 | 
                * @When /^I open a tab named "(?<name>[^"]*)" on the "(?<identifier>[^"]*)" "(?<page>[^"]*)" page$/
  | 
        
        
            | 
            | 
           1013 | 
                */
  | 
        
        
            | 
            | 
           1014 | 
               public function i_open_a_tab_on_the_page_instance(string $name, string $identifier, string $page): void {
  | 
        
        
            | 
            | 
           1015 | 
                   $this->open_tab($name, '"' . addslashes_js(
  | 
        
        
            | 
            | 
           1016 | 
                       $this->resolve_page_instance_helper($identifier, $page)->out(false)) . '"');
  | 
        
        
            | 
            | 
           1017 | 
               }
  | 
        
        
            | 
            | 
           1018 | 
              | 
        
        
            | 
            | 
           1019 | 
               /**
  | 
        
        
            | 
            | 
           1020 | 
                * Opens a new tab at the given target URL.
  | 
        
        
            | 
            | 
           1021 | 
                *
  | 
        
        
            | 
            | 
           1022 | 
                * @param string $name Name for tab
  | 
        
        
            | 
            | 
           1023 | 
                * @param string $jstarget Target in JavaScript syntax, i.e. if a string, must be quoted
  | 
        
        
            | 
            | 
           1024 | 
                */
  | 
        
        
            | 
            | 
           1025 | 
               protected function open_tab(string $name, string $jstarget): void {
  | 
        
        
            | 
            | 
           1026 | 
                   // Tab names aren't allowed spaces, and our JavaScript below doesn't do any escaping.
  | 
        
        
            | 
            | 
           1027 | 
                   if (clean_param($name, PARAM_ALPHANUMEXT) !== $name) {
  | 
        
        
            | 
            | 
           1028 | 
                       throw new Exception('Tab name may not contain whitespace or special characters: "' . $name . '"');
  | 
        
        
            | 
            | 
           1029 | 
                   }
  | 
        
        
            | 
            | 
           1030 | 
              | 
        
        
            | 
            | 
           1031 | 
                   // Normally you can't open a tab unless in response to a user action, but presumably Behat
  | 
        
        
            | 
            | 
           1032 | 
                   // is exempt from this restriction, because it works to just open it directly.
  | 
        
        
            | 
            | 
           1033 | 
                   $this->execute_script('window.open(' . $jstarget . ', "' . $name . '");');
  | 
        
        
            | 
            | 
           1034 | 
                   $this->execute('behat_general::switch_to_window', [$name]);
  | 
        
        
            | 
            | 
           1035 | 
               }
  | 
        
        
            | 
            | 
           1036 | 
              | 
        
        
            | 
            | 
           1037 | 
               /**
  | 
        
        
            | 
            | 
           1038 | 
                * Opens the course homepage. (Consider using 'I am on the "shortname" "Course" page' step instead.)
  | 
        
        
            | 
            | 
           1039 | 
                *
  | 
        
        
            | 
            | 
           1040 | 
                * @Given /^I am on "(?P<coursefullname_string>(?:[^"]|\\")*)" course homepage$/
  | 
        
        
            | 
            | 
           1041 | 
                * @throws coding_exception
  | 
        
        
            | 
            | 
           1042 | 
                * @param string $coursefullname The full name of the course.
  | 
        
        
            | 
            | 
           1043 | 
                * @return void
  | 
        
        
            | 
            | 
           1044 | 
                */
  | 
        
        
            | 
            | 
           1045 | 
               public function i_am_on_course_homepage($coursefullname) {
  | 
        
        
            | 
            | 
           1046 | 
                   $courseid = $this->get_course_id($coursefullname);
  | 
        
        
            | 
            | 
           1047 | 
                   $url = new moodle_url('/course/view.php', ['id' => $courseid]);
  | 
        
        
            | 
            | 
           1048 | 
                   $this->execute('behat_general::i_visit', [$url]);
  | 
        
        
            | 
            | 
           1049 | 
               }
  | 
        
        
            | 
            | 
           1050 | 
              | 
        
        
            | 
            | 
           1051 | 
               /**
  | 
        
        
            | 
            | 
           1052 | 
                * Open the course homepage with editing mode enabled.
  | 
        
        
            | 
            | 
           1053 | 
                *
  | 
        
        
            | 
            | 
           1054 | 
                * @param string $coursefullname The course full name of the course.
  | 
        
        
            | 
            | 
           1055 | 
                */
  | 
        
        
            | 
            | 
           1056 | 
               public function i_am_on_course_homepage_with_editing_mode_on($coursefullname) {
  | 
        
        
            | 
            | 
           1057 | 
                   $this->i_am_on_course_homepage_with_editing_mode_set_to($coursefullname, 'on');
  | 
        
        
            | 
            | 
           1058 | 
               }
  | 
        
        
            | 
            | 
           1059 | 
              | 
        
        
            | 
            | 
           1060 | 
               /**
  | 
        
        
            | 
            | 
           1061 | 
                * Open the course homepage with editing mode set to either on, or off.
  | 
        
        
            | 
            | 
           1062 | 
                *
  | 
        
        
            | 
            | 
           1063 | 
                * @Given I am on :coursefullname course homepage with editing mode :onoroff
  | 
        
        
            | 
            | 
           1064 | 
                * @throws coding_exception
  | 
        
        
            | 
            | 
           1065 | 
                * @param string $coursefullname The course full name of the course.
  | 
        
        
            | 
            | 
           1066 | 
                * @param string $onoroff Whehter to switch editing on, or off.
  | 
        
        
            | 
            | 
           1067 | 
                */
  | 
        
        
            | 
            | 
           1068 | 
               public function i_am_on_course_homepage_with_editing_mode_set_to(string $coursefullname, string $onoroff): void {
  | 
        
        
            | 
            | 
           1069 | 
                   if ($onoroff !== 'on' && $onoroff !== 'off') {
  | 
        
        
            | 
            | 
           1070 | 
                       throw new coding_exception("Unknown editing mode '{$onoroff}'. Accepted values are 'on' and 'off'");
  | 
        
        
            | 
            | 
           1071 | 
                   }
  | 
        
        
            | 
            | 
           1072 | 
              | 
        
        
            | 
            | 
           1073 | 
                   $courseid = $this->get_course_id($coursefullname);
  | 
        
        
            | 
            | 
           1074 | 
                   $context = context_course::instance($courseid);
  | 
        
        
            | 
            | 
           1075 | 
                   $courseurl = new moodle_url('/course/view.php', ['id' => $courseid]);
  | 
        
        
            | 
            | 
           1076 | 
              | 
        
        
            | 
            | 
           1077 | 
                   $editmodeurl = new moodle_url('/editmode.php', [
  | 
        
        
            | 
            | 
           1078 | 
                       'context' => $context->id,
  | 
        
        
            | 
            | 
           1079 | 
                       'pageurl' => $courseurl->out(true),
  | 
        
        
            | 
            | 
           1080 | 
                       'setmode' => ($onoroff === 'on' ? 1 : 0),
  | 
        
        
            | 
            | 
           1081 | 
                   ]);
  | 
        
        
            | 
            | 
           1082 | 
                   $this->execute('behat_general::i_visit', [$editmodeurl]);
  | 
        
        
            | 
            | 
           1083 | 
               }
  | 
        
        
            | 
            | 
           1084 | 
              | 
        
        
            | 
            | 
           1085 | 
               /**
  | 
        
        
            | 
            | 
           1086 | 
                * Opens the flat navigation drawer if it is not already open
  | 
        
        
            | 
            | 
           1087 | 
                *
  | 
        
        
            | 
            | 
           1088 | 
                * @When /^I open flat navigation drawer$/
  | 
        
        
            | 
            | 
           1089 | 
                * @throws ElementNotFoundException Thrown by behat_base::find
  | 
        
        
            | 
            | 
           1090 | 
                */
  | 
        
        
            | 
            | 
           1091 | 
               public function i_open_flat_navigation_drawer() {
  | 
        
        
            | 
            | 
           1092 | 
                   if (!$this->running_javascript()) {
  | 
        
        
            | 
            | 
           1093 | 
                       // Navigation drawer is always open without JS.
  | 
        
        
            | 
            | 
           1094 | 
                       return;
  | 
        
        
            | 
            | 
           1095 | 
                   }
  | 
        
        
            | 
            | 
           1096 | 
                   $xpath = "//button[contains(@data-action,'toggle-drawer')]";
  | 
        
        
            | 
            | 
           1097 | 
                   $node = $this->find('xpath', $xpath);
  | 
        
        
            | 
            | 
           1098 | 
                   $expanded = $node->getAttribute('aria-expanded');
  | 
        
        
            | 
            | 
           1099 | 
                   if ($expanded === 'false') {
  | 
        
        
            | 
            | 
           1100 | 
                       $this->execute('behat_general::i_click_on', [$node, 'NodeElement']);
  | 
        
        
            | 
            | 
           1101 | 
                       $this->ensure_node_attribute_is_set($node, 'aria-expanded', 'true');
  | 
        
        
            | 
            | 
           1102 | 
                   }
  | 
        
        
            | 
            | 
           1103 | 
               }
  | 
        
        
            | 
            | 
           1104 | 
              | 
        
        
            | 
            | 
           1105 | 
               /**
  | 
        
        
            | 
            | 
           1106 | 
                * Closes the flat navigation drawer if it is open (does nothing if JS disabled)
  | 
        
        
            | 
            | 
           1107 | 
                *
  | 
        
        
            | 
            | 
           1108 | 
                * @When /^I close flat navigation drawer$/
  | 
        
        
            | 
            | 
           1109 | 
                * @throws ElementNotFoundException Thrown by behat_base::find
  | 
        
        
            | 
            | 
           1110 | 
                */
  | 
        
        
            | 
            | 
           1111 | 
               public function i_close_flat_navigation_drawer() {
  | 
        
        
            | 
            | 
           1112 | 
                   if (!$this->running_javascript()) {
  | 
        
        
            | 
            | 
           1113 | 
                       // Navigation drawer can not be closed without JS.
  | 
        
        
            | 
            | 
           1114 | 
                       return;
  | 
        
        
            | 
            | 
           1115 | 
                   }
  | 
        
        
            | 
            | 
           1116 | 
                   $xpath = "//button[contains(@data-action,'toggle-drawer')]";
  | 
        
        
            | 
            | 
           1117 | 
                   $node = $this->find('xpath', $xpath);
  | 
        
        
            | 
            | 
           1118 | 
                   $expanded = $node->getAttribute('aria-expanded');
  | 
        
        
            | 
            | 
           1119 | 
                   if ($expanded === 'true') {
  | 
        
        
            | 
            | 
           1120 | 
                       $this->execute('behat_general::i_click_on', [$node, 'NodeElement']);
  | 
        
        
            | 
            | 
           1121 | 
                   }
  | 
        
        
            | 
            | 
           1122 | 
               }
  | 
        
        
            | 
            | 
           1123 | 
              | 
        
        
            | 
            | 
           1124 | 
               /**
  | 
        
        
            | 
            | 
           1125 | 
                * Clicks link with specified id|title|alt|text in the primary navigation
  | 
        
        
            | 
            | 
           1126 | 
                *
  | 
        
        
            | 
            | 
           1127 | 
                * @When /^I select "(?P<link_string>(?:[^"]|\\")*)" from primary navigation$/
  | 
        
        
            | 
            | 
           1128 | 
                * @throws ElementNotFoundException Thrown by behat_base::find
  | 
        
        
            | 
            | 
           1129 | 
                * @param string $link
  | 
        
        
            | 
            | 
           1130 | 
                */
  | 
        
        
            | 
            | 
           1131 | 
               public function i_select_from_primary_navigation(string $link) {
  | 
        
        
            | 
            | 
           1132 | 
                   $this->execute('behat_general::i_click_on_in_the',
  | 
        
        
            | 
            | 
           1133 | 
                       [$link, 'link', '.primary-navigation .moremenu.navigation', 'css_element']
  | 
        
        
            | 
            | 
           1134 | 
                   );
  | 
        
        
            | 
            | 
           1135 | 
               }
  | 
        
        
            | 
            | 
           1136 | 
              | 
        
        
            | 
            | 
           1137 | 
               /**
  | 
        
        
            | 
            | 
           1138 | 
                * Clicks link with specified id|title|alt|text in the secondary navigation
  | 
        
        
            | 
            | 
           1139 | 
                *
  | 
        
        
            | 
            | 
           1140 | 
                * @When I select :link from secondary navigation
  | 
        
        
            | 
            | 
           1141 | 
                * @throws ElementNotFoundException Thrown by behat_base::find
  | 
        
        
            | 
            | 
           1142 | 
                * @param string $link
  | 
        
        
            | 
            | 
           1143 | 
                */
  | 
        
        
            | 
            | 
           1144 | 
               public function i_select_from_secondary_navigation(string $link) {
  | 
        
        
            | 
            | 
           1145 | 
                   $this->execute('behat_general::i_click_on_in_the',
  | 
        
        
            | 
            | 
           1146 | 
                       [$link, 'link', '.secondary-navigation .moremenu.navigation', 'css_element']
  | 
        
        
            | 
            | 
           1147 | 
                   );
  | 
        
        
            | 
            | 
           1148 | 
               }
  | 
        
        
            | 
            | 
           1149 | 
              | 
        
        
            | 
            | 
           1150 | 
               /**
  | 
        
        
            | 
            | 
           1151 | 
                * If we are not on the course main page, click on the course link in the navbar
  | 
        
        
            | 
            | 
           1152 | 
                */
  | 
        
        
            | 
            | 
           1153 | 
               protected function go_to_main_course_page() {
  | 
        
        
            | 
            | 
           1154 | 
                   $url = $this->getSession()->getCurrentUrl();
  | 
        
        
            | 
            | 
           1155 | 
                   if (!preg_match('|/course/view.php\?id=[\d]+$|', $url)) {
  | 
        
        
            | 
            | 
           1156 | 
                       $node = $this->find('xpath',
  | 
        
        
            | 
            | 
           1157 | 
                           '//header//div[@id=\'page-navbar\']//a[contains(@href,\'/course/view.php?id=\')]'
  | 
        
        
            | 
            | 
           1158 | 
                       );
  | 
        
        
            | 
            | 
           1159 | 
                       $this->execute('behat_general::i_click_on', [$node, 'NodeElement']);
  | 
        
        
            | 
            | 
           1160 | 
                   }
  | 
        
        
            | 
            | 
           1161 | 
               }
  | 
        
        
            | 
            | 
           1162 | 
              | 
        
        
            | 
            | 
           1163 | 
               /**
  | 
        
        
            | 
            | 
           1164 | 
                * Finds and clicks a link on the admin page (site administration or course administration)
  | 
        
        
            | 
            | 
           1165 | 
                *
  | 
        
        
            | 
            | 
           1166 | 
                * @param array $nodelist
  | 
        
        
            | 
            | 
           1167 | 
                */
  | 
        
        
            | 
            | 
           1168 | 
               protected function select_on_administration_page($nodelist) {
  | 
        
        
            | 
            | 
           1169 | 
                   $parentnodes = $nodelist;
  | 
        
        
            | 
            | 
           1170 | 
                   $lastnode = array_pop($parentnodes);
  | 
        
        
           | 1441 | 
           ariadna | 
           1171 | 
                   $xpath = '//div[@id=\'region-main\']';
  | 
        
        
           | 1 | 
           efrain | 
           1172 | 
              | 
        
        
            | 
            | 
           1173 | 
                   // Check if there is a separate tab for this submenu of the page. If found go to it.
  | 
        
        
            | 
            | 
           1174 | 
                   if ($parentnodes) {
  | 
        
        
            | 
            | 
           1175 | 
                       $tabname = behat_context_helper::escape($parentnodes[0]);
  | 
        
        
            | 
            | 
           1176 | 
                       $tabxpath = '//ul[@role=\'tablist\']/li/a[contains(normalize-space(.), ' . $tabname . ')]';
  | 
        
        
            | 
            | 
           1177 | 
                       $menubarxpath = '//ul[@role=\'menubar\']/li/a[contains(normalize-space(.), ' . $tabname . ')]';
  | 
        
        
            | 
            | 
           1178 | 
                       $linkname = behat_context_helper::escape(get_string('moremenu'));
  | 
        
        
            | 
            | 
           1179 | 
                       $menubarmorexpath = '//ul[contains(@class,\'more-nav\')]/li/a[contains(normalize-space(.), ' . $linkname . ')]';
  | 
        
        
            | 
            | 
           1180 | 
                       $tabnode = $this->getSession()->getPage()->find('xpath', $tabxpath);
  | 
        
        
            | 
            | 
           1181 | 
                       $menunode = $this->getSession()->getPage()->find('xpath', $menubarxpath);
  | 
        
        
            | 
            | 
           1182 | 
                       $menubuttons = $this->getSession()->getPage()->findAll('xpath', $menubarmorexpath);
  | 
        
        
            | 
            | 
           1183 | 
                       if ($tabnode || $menunode) {
  | 
        
        
            | 
            | 
           1184 | 
                           $node = is_object($tabnode) ? $tabnode : $menunode;
  | 
        
        
            | 
            | 
           1185 | 
                           if ($this->running_javascript()) {
  | 
        
        
            | 
            | 
           1186 | 
                               $this->execute('behat_general::i_click_on', [$node, 'NodeElement']);
  | 
        
        
            | 
            | 
           1187 | 
                               // Click on the tab and add 'active' tab to the xpath.
  | 
        
        
            | 
            | 
           1188 | 
                               $xpath .= '//div[contains(@class,\'active\')]';
  | 
        
        
            | 
            | 
           1189 | 
                           } else {
  | 
        
        
            | 
            | 
           1190 | 
                               // Add the tab content selector to the xpath.
  | 
        
        
            | 
            | 
           1191 | 
                               $tabid = behat_context_helper::escape(ltrim($node->getAttribute('href'), '#'));
  | 
        
        
            | 
            | 
           1192 | 
                               $xpath .= '//div[@id = ' . $tabid . ']';
  | 
        
        
            | 
            | 
           1193 | 
                           }
  | 
        
        
            | 
            | 
           1194 | 
                           array_shift($parentnodes);
  | 
        
        
            | 
            | 
           1195 | 
                       } else if (count($menubuttons) > 0) {
  | 
        
        
            | 
            | 
           1196 | 
                           try {
  | 
        
        
            | 
            | 
           1197 | 
                               $menubuttons[0]->isVisible();
  | 
        
        
            | 
            | 
           1198 | 
                               try {
  | 
        
        
            | 
            | 
           1199 | 
                                   $this->execute('behat_general::i_click_on', [$menubuttons[1], 'NodeElement']);
  | 
        
        
            | 
            | 
           1200 | 
                               } catch (Exception $e) {
  | 
        
        
            | 
            | 
           1201 | 
                                   $this->execute('behat_general::i_click_on', [$menubuttons[0], 'NodeElement']);
  | 
        
        
            | 
            | 
           1202 | 
                               }
  | 
        
        
            | 
            | 
           1203 | 
                               $moreitemxpath = '//ul[@data-region=\'moredropdown\']/li/a[contains(normalize-space(.), ' . $tabname . ')]';
  | 
        
        
            | 
            | 
           1204 | 
                               if ($morenode = $this->getSession()->getPage()->find('xpath', $moreitemxpath)) {
  | 
        
        
            | 
            | 
           1205 | 
                                   $this->execute('behat_general::i_click_on', [$morenode, 'NodeElement']);
  | 
        
        
            | 
            | 
           1206 | 
                                   $xpath .= '//div[contains(@class,\'active\')]';
  | 
        
        
            | 
            | 
           1207 | 
                                   array_shift($parentnodes);
  | 
        
        
            | 
            | 
           1208 | 
                               }
  | 
        
        
            | 
            | 
           1209 | 
                           } catch (Exception $e) {
  | 
        
        
            | 
            | 
           1210 | 
                           }
  | 
        
        
            | 
            | 
           1211 | 
                       }
  | 
        
        
            | 
            | 
           1212 | 
                   }
  | 
        
        
            | 
            | 
           1213 | 
              | 
        
        
            | 
            | 
           1214 | 
                   // Find a section with the parent name in it.
  | 
        
        
            | 
            | 
           1215 | 
                   if ($parentnodes) {
  | 
        
        
            | 
            | 
           1216 | 
                       // Find the section on the page (links may be repeating in different sections).
  | 
        
        
            | 
            | 
           1217 | 
                       $section = behat_context_helper::escape($parentnodes[0]);
  | 
        
        
            | 
            | 
           1218 | 
                       $xpath .= '//div[@class=\'row\' and contains(.,'.$section.')]';
  | 
        
        
            | 
            | 
           1219 | 
                   }
  | 
        
        
            | 
            | 
           1220 | 
              | 
        
        
            | 
            | 
           1221 | 
                   // Find a link and click on it.
  | 
        
        
            | 
            | 
           1222 | 
                   $linkname = behat_context_helper::escape($lastnode);
  | 
        
        
            | 
            | 
           1223 | 
                   $xpathlink = $xpathbutton = $xpath;
  | 
        
        
            | 
            | 
           1224 | 
                   $xpathlink .= '//a[contains(normalize-space(.), ' . $linkname . ')]';
  | 
        
        
            | 
            | 
           1225 | 
                   $xpathbutton .= '//button[contains(normalize-space(.), ' . $linkname . ')]';
  | 
        
        
            | 
            | 
           1226 | 
                   if ($node = $this->getSession()->getPage()->find('xpath', $xpathbutton)) {
  | 
        
        
            | 
            | 
           1227 | 
                       $this->execute('behat_general::i_click_on', [$node, 'NodeElement']);
  | 
        
        
            | 
            | 
           1228 | 
                   } else if (!$node = $this->getSession()->getPage()->find('xpath', $xpathlink)) {
  | 
        
        
            | 
            | 
           1229 | 
                        throw new ElementNotFoundException($this->getSession(), 'Link "' . join(' > ', $nodelist) . '"');
  | 
        
        
            | 
            | 
           1230 | 
                   } else {
  | 
        
        
            | 
            | 
           1231 | 
                       $this->execute('behat_general::i_click_on', [$node, 'NodeElement']);
  | 
        
        
            | 
            | 
           1232 | 
                   }
  | 
        
        
            | 
            | 
           1233 | 
               }
  | 
        
        
            | 
            | 
           1234 | 
              | 
        
        
            | 
            | 
           1235 | 
               /**
  | 
        
        
            | 
            | 
           1236 | 
                * Locates the administration menu in the <header> element and returns its xpath
  | 
        
        
            | 
            | 
           1237 | 
                *
  | 
        
        
            | 
            | 
           1238 | 
                * @param bool $mustexist if specified throws an exception if menu is not found
  | 
        
        
            | 
            | 
           1239 | 
                * @return null|string
  | 
        
        
            | 
            | 
           1240 | 
                */
  | 
        
        
            | 
            | 
           1241 | 
               protected function find_header_administration_menu($mustexist = false) {
  | 
        
        
            | 
            | 
           1242 | 
                   $menuxpath = '//div[contains(@class,\'secondary-navigation\')]//nav[contains(@class,\'moremenu\')]';
  | 
        
        
            | 
            | 
           1243 | 
              | 
        
        
            | 
            | 
           1244 | 
                   if ($mustexist) {
  | 
        
        
            | 
            | 
           1245 | 
                       $exception = new ElementNotFoundException($this->getSession(), 'Page header administration menu');
  | 
        
        
            | 
            | 
           1246 | 
                       $this->find('xpath', $menuxpath, $exception);
  | 
        
        
            | 
            | 
           1247 | 
                   } else if (!$this->getSession()->getPage()->find('xpath', $menuxpath)) {
  | 
        
        
            | 
            | 
           1248 | 
                       return null;
  | 
        
        
            | 
            | 
           1249 | 
                   }
  | 
        
        
            | 
            | 
           1250 | 
                   return $menuxpath;
  | 
        
        
            | 
            | 
           1251 | 
               }
  | 
        
        
            | 
            | 
           1252 | 
              | 
        
        
            | 
            | 
           1253 | 
               /**
  | 
        
        
            | 
            | 
           1254 | 
                * Locates the administration menu on the page (but not in the header) and returns its xpath
  | 
        
        
            | 
            | 
           1255 | 
                *
  | 
        
        
            | 
            | 
           1256 | 
                * @param bool $mustexist if specified throws an exception if menu is not found
  | 
        
        
            | 
            | 
           1257 | 
                * @return null|string
  | 
        
        
            | 
            | 
           1258 | 
                */
  | 
        
        
            | 
            | 
           1259 | 
               protected function find_page_administration_menu($mustexist = false) {
  | 
        
        
            | 
            | 
           1260 | 
                   $menuxpath = '//div[@id=\'region-main-settings-menu\']';
  | 
        
        
            | 
            | 
           1261 | 
                   if ($mustexist) {
  | 
        
        
            | 
            | 
           1262 | 
                       $exception = new ElementNotFoundException($this->getSession(), 'Page administration menu');
  | 
        
        
            | 
            | 
           1263 | 
                       $this->find('xpath', $menuxpath, $exception);
  | 
        
        
            | 
            | 
           1264 | 
                   } else if (!$this->getSession()->getPage()->find('xpath', $menuxpath)) {
  | 
        
        
            | 
            | 
           1265 | 
                       return null;
  | 
        
        
            | 
            | 
           1266 | 
                   }
  | 
        
        
            | 
            | 
           1267 | 
                   return $menuxpath;
  | 
        
        
            | 
            | 
           1268 | 
               }
  | 
        
        
            | 
            | 
           1269 | 
              | 
        
        
            | 
            | 
           1270 | 
               /**
  | 
        
        
            | 
            | 
           1271 | 
                * Locates the action menu on the page (but not in the header) and returns its xpath
  | 
        
        
            | 
            | 
           1272 | 
                *
  | 
        
        
            | 
            | 
           1273 | 
                * @param null|bool $mustexist if specified throws an exception if menu is not found
  | 
        
        
            | 
            | 
           1274 | 
                * @return null|string
  | 
        
        
            | 
            | 
           1275 | 
                */
  | 
        
        
            | 
            | 
           1276 | 
               protected function find_page_action_menu($mustexist = false) {
  | 
        
        
            | 
            | 
           1277 | 
                   $menuxpath = '//div[@id=\'action-menu-0-menubar\']';
  | 
        
        
            | 
            | 
           1278 | 
              | 
        
        
            | 
            | 
           1279 | 
                   if ($mustexist) {
  | 
        
        
            | 
            | 
           1280 | 
                       $exception = new ElementNotFoundException($this->getSession(), 'Page check');
  | 
        
        
            | 
            | 
           1281 | 
                       $this->find('xpath', $menuxpath, $exception);
  | 
        
        
            | 
            | 
           1282 | 
                   } else if (!$this->getSession()->getPage()->find('xpath', $menuxpath)) {
  | 
        
        
            | 
            | 
           1283 | 
                       return null;
  | 
        
        
            | 
            | 
           1284 | 
                   }
  | 
        
        
            | 
            | 
           1285 | 
                   return $menuxpath;
  | 
        
        
            | 
            | 
           1286 | 
               }
  | 
        
        
            | 
            | 
           1287 | 
              | 
        
        
            | 
            | 
           1288 | 
               /**
  | 
        
        
            | 
            | 
           1289 | 
                * Toggles administration menu
  | 
        
        
            | 
            | 
           1290 | 
                *
  | 
        
        
            | 
            | 
           1291 | 
                * @param string $menuxpath (optional) xpath to the page administration menu if already known
  | 
        
        
            | 
            | 
           1292 | 
                */
  | 
        
        
            | 
            | 
           1293 | 
               protected function toggle_page_administration_menu($menuxpath = null) {
  | 
        
        
            | 
            | 
           1294 | 
                   if (!$menuxpath) {
  | 
        
        
            | 
            | 
           1295 | 
                       $menuxpath = $this->find_header_administration_menu() ?: $this->find_page_administration_menu();
  | 
        
        
            | 
            | 
           1296 | 
                   }
  | 
        
        
            | 
            | 
           1297 | 
                   if ($menuxpath && $this->running_javascript()) {
  | 
        
        
           | 1441 | 
           ariadna | 
           1298 | 
                       $node = $this->find('xpath', $menuxpath . '//a[@data-bs-toggle=\'dropdown\']');
  | 
        
        
           | 1 | 
           efrain | 
           1299 | 
                       if ($node->isVisible()) {
  | 
        
        
            | 
            | 
           1300 | 
                           $this->execute('behat_general::i_click_on', [$node, 'NodeElement']);
  | 
        
        
            | 
            | 
           1301 | 
                       }
  | 
        
        
            | 
            | 
           1302 | 
                   }
  | 
        
        
            | 
            | 
           1303 | 
               }
  | 
        
        
            | 
            | 
           1304 | 
              | 
        
        
            | 
            | 
           1305 | 
               /**
  | 
        
        
            | 
            | 
           1306 | 
                * Finds a page edit cog and select an item from it
  | 
        
        
            | 
            | 
           1307 | 
                *
  | 
        
        
            | 
            | 
           1308 | 
                * If the page edit cog is in the page header and the item is not found there, click "More..." link
  | 
        
        
            | 
            | 
           1309 | 
                * and find the item on the course/frontpage administration page
  | 
        
        
            | 
            | 
           1310 | 
                *
  | 
        
        
            | 
            | 
           1311 | 
                * @param array $nodelist
  | 
        
        
            | 
            | 
           1312 | 
                * @throws ElementNotFoundException
  | 
        
        
            | 
            | 
           1313 | 
                */
  | 
        
        
            | 
            | 
           1314 | 
               protected function select_from_administration_menu($nodelist) {
  | 
        
        
            | 
            | 
           1315 | 
                   // Find administration menu.
  | 
        
        
            | 
            | 
           1316 | 
                   if ($menuxpath = $this->find_header_administration_menu()) {
  | 
        
        
            | 
            | 
           1317 | 
                       $isheader = true;
  | 
        
        
            | 
            | 
           1318 | 
                   } else if ($menuxpath = $this->find_page_action_menu(true)) {
  | 
        
        
            | 
            | 
           1319 | 
                       $isheader = false;
  | 
        
        
            | 
            | 
           1320 | 
                   } else {
  | 
        
        
            | 
            | 
           1321 | 
                       $menuxpath = $this->find_page_administration_menu(true);
  | 
        
        
            | 
            | 
           1322 | 
                       $isheader = false;
  | 
        
        
            | 
            | 
           1323 | 
                   }
  | 
        
        
            | 
            | 
           1324 | 
              | 
        
        
            | 
            | 
           1325 | 
                   $this->execute('behat_navigation::toggle_page_administration_menu', [$menuxpath]);
  | 
        
        
            | 
            | 
           1326 | 
              | 
        
        
            | 
            | 
           1327 | 
                   $firstnode = $nodelist[0];
  | 
        
        
            | 
            | 
           1328 | 
                   $firstlinkname = behat_context_helper::escape($firstnode);
  | 
        
        
            | 
            | 
           1329 | 
                   $firstlink = $this->getSession()->getPage()->find('xpath',
  | 
        
        
            | 
            | 
           1330 | 
                       $menuxpath . '//a[contains(normalize-space(.), ' . $firstlinkname . ')]'
  | 
        
        
            | 
            | 
           1331 | 
                   );
  | 
        
        
            | 
            | 
           1332 | 
              | 
        
        
            | 
            | 
           1333 | 
                   if (!$isheader || count($nodelist) == 1) {
  | 
        
        
            | 
            | 
           1334 | 
                       $lastnode = end($nodelist);
  | 
        
        
            | 
            | 
           1335 | 
                       $linkname = behat_context_helper::escape($lastnode);
  | 
        
        
            | 
            | 
           1336 | 
                       $link = $this->getSession()->getPage()->find('xpath', $menuxpath . '//a[contains(normalize-space(.), ' . $linkname . ')]');
  | 
        
        
            | 
            | 
           1337 | 
                       if ($link) {
  | 
        
        
            | 
            | 
           1338 | 
                           $this->execute('behat_general::i_click_on', [$link, 'NodeElement']);
  | 
        
        
            | 
            | 
           1339 | 
                           return;
  | 
        
        
            | 
            | 
           1340 | 
                       }
  | 
        
        
            | 
            | 
           1341 | 
                   } else if ($firstlink) {
  | 
        
        
            | 
            | 
           1342 | 
                       $this->execute('behat_general::i_click_on', [$firstlink, 'NodeElement']);
  | 
        
        
            | 
            | 
           1343 | 
                       array_splice($nodelist, 0, 1);
  | 
        
        
            | 
            | 
           1344 | 
                       $this->select_on_administration_page($nodelist);
  | 
        
        
            | 
            | 
           1345 | 
                       return;
  | 
        
        
            | 
            | 
           1346 | 
                   }
  | 
        
        
            | 
            | 
           1347 | 
              | 
        
        
            | 
            | 
           1348 | 
                   if ($isheader) {
  | 
        
        
            | 
            | 
           1349 | 
                       // Front page administration will have subnodes under "More...".
  | 
        
        
            | 
            | 
           1350 | 
                       $linkname = behat_context_helper::escape(get_string('morenavigationlinks'));
  | 
        
        
            | 
            | 
           1351 | 
                       $link = $this->getSession()->getPage()->find('xpath',
  | 
        
        
            | 
            | 
           1352 | 
                           $menuxpath . '//a[contains(normalize-space(.), ' . $linkname . ')]'
  | 
        
        
            | 
            | 
           1353 | 
                       );
  | 
        
        
            | 
            | 
           1354 | 
                       // Course administration will have subnodes under "Course administration".
  | 
        
        
            | 
            | 
           1355 | 
                       $courselinkname = behat_context_helper::escape(get_string('courseadministration'));
  | 
        
        
            | 
            | 
           1356 | 
                       $courselink = $this->getSession()->getPage()->find('xpath',
  | 
        
        
            | 
            | 
           1357 | 
                           $menuxpath . '//a[contains(normalize-space(.), ' . $courselinkname . ')]'
  | 
        
        
            | 
            | 
           1358 | 
                       );
  | 
        
        
            | 
            | 
           1359 | 
                       if ($link) {
  | 
        
        
            | 
            | 
           1360 | 
                           $this->execute('behat_general::i_click_on', [$link, 'NodeElement']);
  | 
        
        
            | 
            | 
           1361 | 
                           $this->select_on_administration_page($nodelist);
  | 
        
        
            | 
            | 
           1362 | 
                           return;
  | 
        
        
            | 
            | 
           1363 | 
                       } else if ($courselink) {
  | 
        
        
            | 
            | 
           1364 | 
                           $this->execute('behat_general::i_click_on', [$courselink, 'NodeElement']);
  | 
        
        
            | 
            | 
           1365 | 
                           $this->select_on_administration_page($nodelist);
  | 
        
        
            | 
            | 
           1366 | 
                           return;
  | 
        
        
            | 
            | 
           1367 | 
                       }
  | 
        
        
            | 
            | 
           1368 | 
                   }
  | 
        
        
            | 
            | 
           1369 | 
              | 
        
        
            | 
            | 
           1370 | 
                   throw new ElementNotFoundException($this->getSession(),
  | 
        
        
            | 
            | 
           1371 | 
                           'Link "' . join(' > ', $nodelist) . '" in the current page edit menu"');
  | 
        
        
            | 
            | 
           1372 | 
               }
  | 
        
        
            | 
            | 
           1373 | 
              | 
        
        
            | 
            | 
           1374 | 
               /**
  | 
        
        
            | 
            | 
           1375 | 
                * Visit a fixture page for testing stuff that is not available in core.
  | 
        
        
            | 
            | 
           1376 | 
                *
  | 
        
        
            | 
            | 
           1377 | 
                * Please always, to prevent unwanted requests, protect behat fixture files with:
  | 
        
        
            | 
            | 
           1378 | 
                *     defined('BEHAT_SITE_RUNNING') || die();
  | 
        
        
            | 
            | 
           1379 | 
                *
  | 
        
        
            | 
            | 
           1380 | 
                * @Given /^I am on fixture page "(?P<url_string>(?:[^"]|\\")*)"$/
  | 
        
        
            | 
            | 
           1381 | 
                * @param string $url local path to fixture page
  | 
        
        
            | 
            | 
           1382 | 
                */
  | 
        
        
            | 
            | 
           1383 | 
               public function i_am_on_fixture_page($url) {
  | 
        
        
            | 
            | 
           1384 | 
                   $fixtureregex = '|^/[a-z0-9_\-/]*/tests/behat/fixtures/[a-z0-9_\-]*\.php$|';
  | 
        
        
            | 
            | 
           1385 | 
                   if (!preg_match($fixtureregex, $url)) {
  | 
        
        
            | 
            | 
           1386 | 
                       throw new coding_exception("URL {$url} is not a fixture URL");
  | 
        
        
            | 
            | 
           1387 | 
                   }
  | 
        
        
            | 
            | 
           1388 | 
                   $this->execute('behat_general::i_visit', [$url]);
  | 
        
        
            | 
            | 
           1389 | 
               }
  | 
        
        
            | 
            | 
           1390 | 
              | 
        
        
            | 
            | 
           1391 | 
               /**
  | 
        
        
            | 
            | 
           1392 | 
                * First checks to see if we are on this page via the breadcrumb. If not we then attempt to follow the link name given.
  | 
        
        
            | 
            | 
           1393 | 
                *
  | 
        
        
            | 
            | 
           1394 | 
                * @param  string $pagename Name of the breadcrumb item to check and follow.
  | 
        
        
            | 
            | 
           1395 | 
                * @Given /^I follow the breadcrumb "(?P<url_string>(?:[^"]|\\")*)"$/
  | 
        
        
            | 
            | 
           1396 | 
                */
  | 
        
        
            | 
            | 
           1397 | 
               public function go_to_breadcrumb_location(string $pagename): void {
  | 
        
        
            | 
            | 
           1398 | 
                   $link = $this->getSession()->getPage()->find(
  | 
        
        
            | 
            | 
           1399 | 
                           'xpath',
  | 
        
        
            | 
            | 
           1400 | 
                           "//nav[@aria-label='Navigation bar']/ol/li[last()][contains(normalize-space(.), '" . $pagename . "')]"
  | 
        
        
            | 
            | 
           1401 | 
                   );
  | 
        
        
            | 
            | 
           1402 | 
                   if (!$link) {
  | 
        
        
            | 
            | 
           1403 | 
                       $this->execute("behat_general::i_click_on_in_the", [$pagename, 'link', 'page', 'region']);
  | 
        
        
            | 
            | 
           1404 | 
                   }
  | 
        
        
            | 
            | 
           1405 | 
               }
  | 
        
        
            | 
            | 
           1406 | 
              | 
        
        
            | 
            | 
           1407 | 
               /**
  | 
        
        
            | 
            | 
           1408 | 
                * Checks whether an item exists in the user menu.
  | 
        
        
            | 
            | 
           1409 | 
                *
  | 
        
        
            | 
            | 
           1410 | 
                * @Given :itemtext :selectortype should exist in the user menu
  | 
        
        
            | 
            | 
           1411 | 
                * @Given :itemtext :selectortype should :not exist in the user menu
  | 
        
        
            | 
            | 
           1412 | 
                *
  | 
        
        
            | 
            | 
           1413 | 
                * @throws ElementNotFoundException
  | 
        
        
            | 
            | 
           1414 | 
                * @param string $itemtext The menu item to find
  | 
        
        
            | 
            | 
           1415 | 
                * @param string $selectortype The selector type
  | 
        
        
            | 
            | 
           1416 | 
                * @param string|null $not Instructs to checks whether the element does not exist in the user menu, if defined
  | 
        
        
            | 
            | 
           1417 | 
                * @return void
  | 
        
        
            | 
            | 
           1418 | 
                */
  | 
        
        
            | 
            | 
           1419 | 
               public function should_exist_in_user_menu($itemtext, $selectortype, $not = null) {
  | 
        
        
            | 
            | 
           1420 | 
                   $callfunction = is_null($not) ? 'should_exist_in_the' : 'should_not_exist_in_the';
  | 
        
        
            | 
            | 
           1421 | 
                   $this->execute("behat_general::{$callfunction}",
  | 
        
        
            | 
            | 
           1422 | 
                       [$itemtext, $selectortype, $this->get_user_menu_xpath(), 'xpath_element']);
  | 
        
        
            | 
            | 
           1423 | 
               }
  | 
        
        
            | 
            | 
           1424 | 
              | 
        
        
            | 
            | 
           1425 | 
               /**
  | 
        
        
            | 
            | 
           1426 | 
                * Checks whether an item exists in a given user submenu.
  | 
        
        
            | 
            | 
           1427 | 
                *
  | 
        
        
            | 
            | 
           1428 | 
                * @Given :itemtext :selectortype should exist in the :submenuname user submenu
  | 
        
        
            | 
            | 
           1429 | 
                * @Given :itemtext :selectortype should :not exist in the :submenuname user submenu
  | 
        
        
            | 
            | 
           1430 | 
                *
  | 
        
        
            | 
            | 
           1431 | 
                * @throws ElementNotFoundException
  | 
        
        
            | 
            | 
           1432 | 
                * @param string $itemtext The submenu item to find
  | 
        
        
            | 
            | 
           1433 | 
                * @param string $selectortype The selector type
  | 
        
        
            | 
            | 
           1434 | 
                * @param string $submenuname The name of the submenu
  | 
        
        
            | 
            | 
           1435 | 
                * @param string|null $not Instructs to checks whether the element does not exist in the user menu, if defined
  | 
        
        
            | 
            | 
           1436 | 
                * @return void
  | 
        
        
            | 
            | 
           1437 | 
                */
  | 
        
        
            | 
            | 
           1438 | 
               public function should_exist_in_user_submenu($itemtext, $selectortype, $submenuname, $not = null) {
  | 
        
        
            | 
            | 
           1439 | 
                   $callfunction = is_null($not) ? 'should_exist_in_the' : 'should_not_exist_in_the';
  | 
        
        
            | 
            | 
           1440 | 
                   $this->execute("behat_general::{$callfunction}",
  | 
        
        
            | 
            | 
           1441 | 
                       [$itemtext, $selectortype, $this->get_user_submenu_xpath($submenuname), 'xpath_element']);
  | 
        
        
            | 
            | 
           1442 | 
               }
  | 
        
        
            | 
            | 
           1443 | 
              | 
        
        
            | 
            | 
           1444 | 
               /**
  | 
        
        
            | 
            | 
           1445 | 
                * Checks whether a given user submenu is visible.
  | 
        
        
            | 
            | 
           1446 | 
                *
  | 
        
        
            | 
            | 
           1447 | 
                * @Then /^I should see "(?P<submenu_string>[^"]*)" user submenu$/
  | 
        
        
            | 
            | 
           1448 | 
                *
  | 
        
        
            | 
            | 
           1449 | 
                * @throws ElementNotFoundException
  | 
        
        
            | 
            | 
           1450 | 
                * @throws ExpectationException
  | 
        
        
            | 
            | 
           1451 | 
                * @param string $submenuname The name of the submenu
  | 
        
        
            | 
            | 
           1452 | 
                * @return void
  | 
        
        
            | 
            | 
           1453 | 
                */
  | 
        
        
            | 
            | 
           1454 | 
               public function i_should_see_user_submenu($submenuname) {
  | 
        
        
            | 
            | 
           1455 | 
                   $this->execute('behat_general::should_be_visible',
  | 
        
        
            | 
            | 
           1456 | 
                       array($this->get_user_submenu_xpath($submenuname), 'xpath_element'));
  | 
        
        
            | 
            | 
           1457 | 
               }
  | 
        
        
            | 
            | 
           1458 | 
              | 
        
        
            | 
            | 
           1459 | 
               /**
  | 
        
        
            | 
            | 
           1460 | 
                * Return the xpath for the user menu element.
  | 
        
        
            | 
            | 
           1461 | 
                *
  | 
        
        
            | 
            | 
           1462 | 
                * @return string The xpath
  | 
        
        
            | 
            | 
           1463 | 
                */
  | 
        
        
            | 
            | 
           1464 | 
               protected function get_user_menu_xpath() {
  | 
        
        
            | 
            | 
           1465 | 
                   return "//div[contains(concat(' ', @class, ' '),  ' usermenu ')]" .
  | 
        
        
            | 
            | 
           1466 | 
                       "//div[contains(concat(' ', @class, ' '), ' dropdown-menu ')]" .
  | 
        
        
            | 
            | 
           1467 | 
                       "//div[@id='carousel-item-main']";
  | 
        
        
            | 
            | 
           1468 | 
               }
  | 
        
        
            | 
            | 
           1469 | 
              | 
        
        
            | 
            | 
           1470 | 
               /**
  | 
        
        
            | 
            | 
           1471 | 
                * Return the xpath for a given user submenu element.
  | 
        
        
            | 
            | 
           1472 | 
                *
  | 
        
        
            | 
            | 
           1473 | 
                * @param string $submenuname The name of the submenu
  | 
        
        
            | 
            | 
           1474 | 
                * @return string The xpath
  | 
        
        
            | 
            | 
           1475 | 
                */
  | 
        
        
            | 
            | 
           1476 | 
               protected function get_user_submenu_xpath($submenuname) {
  | 
        
        
            | 
            | 
           1477 | 
                   return "//div[contains(concat(' ', @class, ' '),  ' usermenu ')]" .
  | 
        
        
            | 
            | 
           1478 | 
                       "//div[contains(concat(' ', @class, ' '), ' dropdown-menu ')]" .
  | 
        
        
            | 
            | 
           1479 | 
                       "//div[contains(concat(' ', @class, ' '), ' submenu ')][@aria-label='" . $submenuname . "']";
  | 
        
        
            | 
            | 
           1480 | 
               }
  | 
        
        
            | 
            | 
           1481 | 
              | 
        
        
            | 
            | 
           1482 | 
               /**
  | 
        
        
            | 
            | 
           1483 | 
                * Returns whether the user can edit the current page.
  | 
        
        
            | 
            | 
           1484 | 
                *
  | 
        
        
            | 
            | 
           1485 | 
                * @return bool
  | 
        
        
            | 
            | 
           1486 | 
                */
  | 
        
        
            | 
            | 
           1487 | 
               protected function is_editing_on() {
  | 
        
        
            | 
            | 
           1488 | 
                   $body = $this->find('xpath', "//body", false, false, 0);
  | 
        
        
            | 
            | 
           1489 | 
                   return $body->hasClass('editing');
  | 
        
        
            | 
            | 
           1490 | 
               }
  | 
        
        
            | 
            | 
           1491 | 
              | 
        
        
            | 
            | 
           1492 | 
               /**
  | 
        
        
            | 
            | 
           1493 | 
                * Turns editing mode on.
  | 
        
        
            | 
            | 
           1494 | 
                * @Given I switch editing mode on
  | 
        
        
            | 
            | 
           1495 | 
                * @Given I turn editing mode on
  | 
        
        
            | 
            | 
           1496 | 
                */
  | 
        
        
            | 
            | 
           1497 | 
               public function i_turn_editing_mode_on() {
  | 
        
        
            | 
            | 
           1498 | 
                   $this->execute('behat_forms::i_set_the_field_to', [get_string('editmode'), 1]);
  | 
        
        
            | 
            | 
           1499 | 
              | 
        
        
            | 
            | 
           1500 | 
                   if (!$this->running_javascript()) {
  | 
        
        
            | 
            | 
           1501 | 
                       $this->execute('behat_general::i_click_on', [
  | 
        
        
            | 
            | 
           1502 | 
                           get_string('setmode', 'core'),
  | 
        
        
            | 
            | 
           1503 | 
                           'button',
  | 
        
        
            | 
            | 
           1504 | 
                       ]);
  | 
        
        
            | 
            | 
           1505 | 
                   }
  | 
        
        
            | 
            | 
           1506 | 
              | 
        
        
            | 
            | 
           1507 | 
                   if (!$this->is_editing_on()) {
  | 
        
        
            | 
            | 
           1508 | 
                       throw new ExpectationException('The edit mode could not be turned on', $this->getSession());
  | 
        
        
            | 
            | 
           1509 | 
                   }
  | 
        
        
            | 
            | 
           1510 | 
               }
  | 
        
        
            | 
            | 
           1511 | 
              | 
        
        
            | 
            | 
           1512 | 
               /**
  | 
        
        
            | 
            | 
           1513 | 
                * Turns editing mode off.
  | 
        
        
            | 
            | 
           1514 | 
                * @Given I switch editing mode off
  | 
        
        
            | 
            | 
           1515 | 
                * @Given I turn editing mode off
  | 
        
        
            | 
            | 
           1516 | 
                */
  | 
        
        
            | 
            | 
           1517 | 
               public function i_turn_editing_mode_off() {
  | 
        
        
            | 
            | 
           1518 | 
                   $this->execute('behat_forms::i_set_the_field_to', [get_string('editmode'), 0]);
  | 
        
        
            | 
            | 
           1519 | 
              | 
        
        
            | 
            | 
           1520 | 
                   if (!$this->running_javascript()) {
  | 
        
        
            | 
            | 
           1521 | 
                       $this->execute('behat_general::i_click_on', [
  | 
        
        
            | 
            | 
           1522 | 
                           get_string('setmode', 'core'),
  | 
        
        
            | 
            | 
           1523 | 
                           'button',
  | 
        
        
            | 
            | 
           1524 | 
                       ]);
  | 
        
        
            | 
            | 
           1525 | 
                   }
  | 
        
        
            | 
            | 
           1526 | 
              | 
        
        
            | 
            | 
           1527 | 
                   if ($this->is_editing_on()) {
  | 
        
        
            | 
            | 
           1528 | 
                       throw new ExpectationException('The edit mode could not be turned off', $this->getSession());
  | 
        
        
            | 
            | 
           1529 | 
                   }
  | 
        
        
            | 
            | 
           1530 | 
               }
  | 
        
        
            | 
            | 
           1531 | 
              | 
        
        
            | 
            | 
           1532 | 
               /**
  | 
        
        
            | 
            | 
           1533 | 
                * The named item should exist in the named dropdown.
  | 
        
        
            | 
            | 
           1534 | 
                *
  | 
        
        
            | 
            | 
           1535 | 
                * @Then /^the "(?P<item_string>[^"]*)" item should (?P<not_bool>not )?exist in the "(?P<dropdown_string>[^"]*)" dropdown$/
  | 
        
        
            | 
            | 
           1536 | 
                * @Then /^the "(?P<item_string>[^"]*)" item should (?P<not_bool>not )?exist in the "(?P<dropdown_string>[^"]*)" dropdown of the "(?P<container_string>[^"]*)" "(?P<containertype_string>[^"]*)"$/
  | 
        
        
            | 
            | 
           1537 | 
                * @param string $item The text on the dropdown menu item
  | 
        
        
            | 
            | 
           1538 | 
                * @param bool $not Whether to negate this search
  | 
        
        
            | 
            | 
           1539 | 
                * @param string $dropdown The name of the dropdown
  | 
        
        
            | 
            | 
           1540 | 
                * @param string $container The name of the container
  | 
        
        
            | 
            | 
           1541 | 
                * @param string $containertype The type of the container
  | 
        
        
            | 
            | 
           1542 | 
                */
  | 
        
        
            | 
            | 
           1543 | 
               public function should_exist_in_dropdown(
  | 
        
        
            | 
            | 
           1544 | 
                   string $item,
  | 
        
        
            | 
            | 
           1545 | 
                   bool $not,
  | 
        
        
            | 
            | 
           1546 | 
                   string $dropdown,
  | 
        
        
           | 1441 | 
           ariadna | 
           1547 | 
                   ?string $container = null,
  | 
        
        
            | 
            | 
           1548 | 
                   ?string $containertype = null,
  | 
        
        
           | 1 | 
           efrain | 
           1549 | 
               ): void {
  | 
        
        
            | 
            | 
           1550 | 
                   $containernode = null;
  | 
        
        
            | 
            | 
           1551 | 
                   if ($container && $containertype) {
  | 
        
        
            | 
            | 
           1552 | 
                       $containernode = $this->find(
  | 
        
        
            | 
            | 
           1553 | 
                           selector: $containertype,
  | 
        
        
            | 
            | 
           1554 | 
                           locator: $container,
  | 
        
        
            | 
            | 
           1555 | 
                           node: null,
  | 
        
        
            | 
            | 
           1556 | 
                       );
  | 
        
        
            | 
            | 
           1557 | 
                   }
  | 
        
        
            | 
            | 
           1558 | 
                   $this->should_exist_in_dropdown_in(
  | 
        
        
            | 
            | 
           1559 | 
                       item: $item,
  | 
        
        
            | 
            | 
           1560 | 
                       dropdown: $dropdown,
  | 
        
        
            | 
            | 
           1561 | 
                       container: $containernode,
  | 
        
        
            | 
            | 
           1562 | 
                       not: $not,
  | 
        
        
            | 
            | 
           1563 | 
                   );
  | 
        
        
            | 
            | 
           1564 | 
               }
  | 
        
        
            | 
            | 
           1565 | 
              | 
        
        
            | 
            | 
           1566 | 
               /**
  | 
        
        
            | 
            | 
           1567 | 
                * Helper to check whether an item exists in a dropdown.
  | 
        
        
            | 
            | 
           1568 | 
                *
  | 
        
        
            | 
            | 
           1569 | 
                * @param string $item The text of the item to look for
  | 
        
        
            | 
            | 
           1570 | 
                * @param string $dropdown The name of the dropdown
  | 
        
        
            | 
            | 
           1571 | 
                * @param null|NodeElement $container The container to look within
  | 
        
        
            | 
            | 
           1572 | 
                */
  | 
        
        
            | 
            | 
           1573 | 
               public function should_exist_in_dropdown_in(
  | 
        
        
            | 
            | 
           1574 | 
                   string $item,
  | 
        
        
            | 
            | 
           1575 | 
                   string $dropdown,
  | 
        
        
            | 
            | 
           1576 | 
                   null|NodeElement $container,
  | 
        
        
            | 
            | 
           1577 | 
                   bool $not,
  | 
        
        
            | 
            | 
           1578 | 
               ): void {
  | 
        
        
            | 
            | 
           1579 | 
                   $dropdownnode = $this->find(
  | 
        
        
            | 
            | 
           1580 | 
                       selector: 'named_partial',
  | 
        
        
            | 
            | 
           1581 | 
                       locator: ['dropdown', $dropdown],
  | 
        
        
            | 
            | 
           1582 | 
                       node: $container ?? false,
  | 
        
        
            | 
            | 
           1583 | 
                   );
  | 
        
        
            | 
            | 
           1584 | 
              | 
        
        
            | 
            | 
           1585 | 
                   if ($not) {
  | 
        
        
            | 
            | 
           1586 | 
                       try {
  | 
        
        
            | 
            | 
           1587 | 
                           $this->find(
  | 
        
        
            | 
            | 
           1588 | 
                               selector: 'named_partial',
  | 
        
        
            | 
            | 
           1589 | 
                               locator: ['dropdown_item', $item],
  | 
        
        
            | 
            | 
           1590 | 
                               node: $dropdownnode,
  | 
        
        
            | 
            | 
           1591 | 
                           );
  | 
        
        
            | 
            | 
           1592 | 
              | 
        
        
            | 
            | 
           1593 | 
                           throw new ExpectationException(
  | 
        
        
            | 
            | 
           1594 | 
                               "The '{$item}' dropdown item was found in the '{$dropdown}' selector",
  | 
        
        
            | 
            | 
           1595 | 
                               $this->getSession(),
  | 
        
        
            | 
            | 
           1596 | 
                           );
  | 
        
        
            | 
            | 
           1597 | 
                       } catch (ElementNotFoundException $e) {
  | 
        
        
            | 
            | 
           1598 | 
                           return;
  | 
        
        
            | 
            | 
           1599 | 
                       }
  | 
        
        
            | 
            | 
           1600 | 
                   } else {
  | 
        
        
            | 
            | 
           1601 | 
                       $this->find(
  | 
        
        
            | 
            | 
           1602 | 
                           selector: 'named_partial',
  | 
        
        
            | 
            | 
           1603 | 
                           locator: ['dropdown_item', $item],
  | 
        
        
            | 
            | 
           1604 | 
                           node: $dropdownnode,
  | 
        
        
            | 
            | 
           1605 | 
                       );
  | 
        
        
            | 
            | 
           1606 | 
                   }
  | 
        
        
            | 
            | 
           1607 | 
               }
  | 
        
        
            | 
            | 
           1608 | 
              | 
        
        
            | 
            | 
           1609 | 
               /**
  | 
        
        
            | 
            | 
           1610 | 
                * Close the block drawer if it is open.
  | 
        
        
            | 
            | 
           1611 | 
                *
  | 
        
        
            | 
            | 
           1612 | 
                * This is necessary as in Behat the block drawer is open at each page load (disregarding user's settings)
  | 
        
        
            | 
            | 
           1613 | 
                * As the block drawer is positioned at the front of some contextual dialogs on the grade report for example.
  | 
        
        
            | 
            | 
           1614 | 
                * @Given I close block drawer if open
  | 
        
        
            | 
            | 
           1615 | 
                * @return void
  | 
        
        
            | 
            | 
           1616 | 
                */
  | 
        
        
            | 
            | 
           1617 | 
               public function i_close_block_drawer_if_open() {
  | 
        
        
            | 
            | 
           1618 | 
                   if ($this->running_javascript()) {
  | 
        
        
            | 
            | 
           1619 | 
                       $xpath = "//button[contains(@data-action,'closedrawer')][contains(@data-placement,'left')]";
  | 
        
        
            | 
            | 
           1620 | 
                       $node = $this->getSession()->getPage()->find('xpath', $xpath);
  | 
        
        
            | 
            | 
           1621 | 
                       if ($node && $node->isVisible()) {
  | 
        
        
            | 
            | 
           1622 | 
                           $ishidden = $node->getAttribute('aria-hidden-tab-index');
  | 
        
        
            | 
            | 
           1623 | 
                           if (!$ishidden) {
  | 
        
        
            | 
            | 
           1624 | 
                               $this->execute('behat_general::i_click_on', [$node, 'NodeElement']);
  | 
        
        
            | 
            | 
           1625 | 
                           }
  | 
        
        
            | 
            | 
           1626 | 
                       }
  | 
        
        
            | 
            | 
           1627 | 
                   }
  | 
        
        
            | 
            | 
           1628 | 
               }
  | 
        
        
            | 
            | 
           1629 | 
              | 
        
        
            | 
            | 
           1630 | 
               /**
  | 
        
        
            | 
            | 
           1631 | 
                * I close the block drawer and keep it closed.
  | 
        
        
            | 
            | 
           1632 | 
                *
  | 
        
        
            | 
            | 
           1633 | 
                * @Given I keep block drawer closed
  | 
        
        
            | 
            | 
           1634 | 
                * @return void
  | 
        
        
            | 
            | 
           1635 | 
                */
  | 
        
        
            | 
            | 
           1636 | 
               public function i_keep_block_drawer_closed() {
  | 
        
        
            | 
            | 
           1637 | 
                   set_user_preference('behat_keep_drawer_closed', 1);
  | 
        
        
            | 
            | 
           1638 | 
                   $this->i_close_block_drawer_if_open();
  | 
        
        
            | 
            | 
           1639 | 
               }
  | 
        
        
           | 1441 | 
           ariadna | 
           1640 | 
              | 
        
        
            | 
            | 
           1641 | 
               /**
  | 
        
        
            | 
            | 
           1642 | 
                * Checks if a navigation menu item is active.
  | 
        
        
            | 
            | 
           1643 | 
                *
  | 
        
        
            | 
            | 
           1644 | 
                * @Then menu item :navigationmenuitem should be active
  | 
        
        
            | 
            | 
           1645 | 
                * @param string $navigationmenuitem The navigation menu item name.
  | 
        
        
            | 
            | 
           1646 | 
                */
  | 
        
        
            | 
            | 
           1647 | 
               public function menu_item_should_be_active(string $navigationmenuitem): void {
  | 
        
        
            | 
            | 
           1648 | 
                   $elementselector = "//*//a/following-sibling::*//a[contains(text(), '$navigationmenuitem') and @aria-current='true']";
  | 
        
        
            | 
            | 
           1649 | 
                   $params = [$elementselector, "xpath_element"];
  | 
        
        
            | 
            | 
           1650 | 
                   $this->execute("behat_general::should_exist", $params);
  | 
        
        
            | 
            | 
           1651 | 
               }
  | 
        
        
            | 
            | 
           1652 | 
              | 
        
        
            | 
            | 
           1653 | 
               /**
  | 
        
        
            | 
            | 
           1654 | 
                * Checks if a navigation menu item is not active
  | 
        
        
            | 
            | 
           1655 | 
                *
  | 
        
        
            | 
            | 
           1656 | 
                * @Then menu item :navigationmenuitem should not be active
  | 
        
        
            | 
            | 
           1657 | 
                * @param string $navigationmenuitem The navigation menu item name.
  | 
        
        
            | 
            | 
           1658 | 
                */
  | 
        
        
            | 
            | 
           1659 | 
               public function menu_item_should_not_be_active(string $navigationmenuitem): void {
  | 
        
        
            | 
            | 
           1660 | 
                   $elementselector = "//*//a/following-sibling::*//a[contains(text(), '$navigationmenuitem') and @aria-current='true']";
  | 
        
        
            | 
            | 
           1661 | 
                   $params = [$elementselector, "xpath_element"];
  | 
        
        
            | 
            | 
           1662 | 
                   $this->execute("behat_general::should_not_exist", $params);
  | 
        
        
            | 
            | 
           1663 | 
               }
  | 
        
        
            | 
            | 
           1664 | 
              | 
        
        
            | 
            | 
           1665 | 
               /**
  | 
        
        
            | 
            | 
           1666 | 
                * Sets a link to no longer navigate when selected.
  | 
        
        
            | 
            | 
           1667 | 
                *
  | 
        
        
            | 
            | 
           1668 | 
                * @When /^I update the href of the "(?P<locator_string>[^"]*)" "(?P<selector_string>[^"]*)" link to "(?P<href_string>[^"]*)"$/
  | 
        
        
            | 
            | 
           1669 | 
                * @param string $locator The locator to use
  | 
        
        
            | 
            | 
           1670 | 
                * @param string $selector selector type
  | 
        
        
            | 
            | 
           1671 | 
                * @param string $href The value
  | 
        
        
            | 
            | 
           1672 | 
                */
  | 
        
        
            | 
            | 
           1673 | 
               public function i_update_the_link_to_go_nowhere(
  | 
        
        
            | 
            | 
           1674 | 
                   string $locator,
  | 
        
        
            | 
            | 
           1675 | 
                   string $selector,
  | 
        
        
            | 
            | 
           1676 | 
                   string $href,
  | 
        
        
            | 
            | 
           1677 | 
               ): void {
  | 
        
        
            | 
            | 
           1678 | 
                   $this->require_javascript();
  | 
        
        
            | 
            | 
           1679 | 
                   $xpath = $this->find(
  | 
        
        
            | 
            | 
           1680 | 
                       selector: $selector,
  | 
        
        
            | 
            | 
           1681 | 
                       locator: $locator,
  | 
        
        
            | 
            | 
           1682 | 
                   )->getXpath();
  | 
        
        
            | 
            | 
           1683 | 
                   $script = <<<JS
  | 
        
        
            | 
            | 
           1684 | 
                       var result = document.evaluate("{$xpath}", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
  | 
        
        
            | 
            | 
           1685 | 
                       var link = result.singleNodeValue;
  | 
        
        
            | 
            | 
           1686 | 
              | 
        
        
            | 
            | 
           1687 | 
                       if (link) {
  | 
        
        
            | 
            | 
           1688 | 
                           link.setAttribute('href', '{$href}');
  | 
        
        
            | 
            | 
           1689 | 
                       } else {
  | 
        
        
            | 
            | 
           1690 | 
                           throw new Error('No element found with the XPath: ' + "$selector");
  | 
        
        
            | 
            | 
           1691 | 
                       }
  | 
        
        
            | 
            | 
           1692 | 
                   JS;
  | 
        
        
            | 
            | 
           1693 | 
              | 
        
        
            | 
            | 
           1694 | 
                   $this->getSession()->executeScript($script);
  | 
        
        
            | 
            | 
           1695 | 
               }
  | 
        
        
           | 1 | 
           efrain | 
           1696 | 
           }
  |