Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 310 and 311] [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]

Navigation steps definitions.

Copyright: 2012 David MonllaĆ³
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 1072 lines (47 kb)
Included or required: 2 times
Referenced: 0 times
Includes or requires: 1 file
 lib/behat/behat_base.php

Defines 1 class


Class: behat_navigation  - X-Ref

Steps definitions to navigate through the navigation tree nodes.

get_node_text_node($text, $branch = false, $collapsed = null, $exception = null)   X-Ref
Helper function to get a navigation nodes text element given its text from within the navigation block.

This function finds the node with the given text from within the navigation block.
It checks to make sure the node is visible, and then returns it.

param: string $text
param: bool $branch Set this true if you're only interested in the node if its a branch.
param: null|bool $collapsed Set this to true or false if you want the node to either be collapsed or not.
param: null|string|Exception|false $exception The exception to throw if the node is not found.
return: \Behat\Mink\Element\NodeElement

navigation_node_should_be_expandable($nodetext)   X-Ref
Returns true if the navigation node with the given text is expandable.

param: string $nodetext
return: bool

navigation_node_should_not_be_expandable($nodetext)   X-Ref
Returns true if the navigation node with the given text is not expandable.

param: string $nodetext
return: bool

i_follow_in_the_user_menu($nodetext)   X-Ref
Click on an entry in the user menu.

param: string $nodetext

i_expand_node($nodetext)   X-Ref
Expands the selected node of the navigation tree that matches the text.

param: string $nodetext
return: bool|void

i_collapse_node($nodetext)   X-Ref
Collapses the selected node of the navigation tree that matches the text.

param: string $nodetext
return: bool|void

find_node_in_navigation($nodetext, $parentnodes, $nodetype = 'link')   X-Ref
Finds a node in the Navigation or Administration tree

param: string $nodetext
param: array $parentnodes
param: string $nodetype node type (link or text)
return: NodeElement|null

select_node_in_navigation($nodetext, $parentnodes)   X-Ref
Finds a node in the Navigation or Administration tree and clicks on it.

param: string $nodetext
param: array $parentnodes

get_top_navigation_node($nodetext)   X-Ref
Helper function to get top navigation node in tree.

param: string $nodetext name of top navigation node in tree.
return: NodeElement

get_navigation_node($nodetext, $parentnode = null)   X-Ref
Helper function to get sub-navigation node.

param: string $nodetext node to find.
param: NodeElement $parentnode parent navigation node.
return: NodeElement.

get_expand_navbar_step()   X-Ref
Step to open the navigation bar if it is needed.

The top log in and log out links are hidden when middle or small
size windows (or devices) are used. This step returns a step definition
clicking to expand the navbar if it is hidden.


i_navigate_to_in_current_page_administration($nodetext)   X-Ref
Go to current page setting item

This can be used on front page, course, category or modules pages.

param: string $nodetext navigation node to click, may contain path, for example "Reports > Overview"
return: void

should_exist_in_current_page_administration($element, $selectortype)   X-Ref
Checks that current page administration contains text

param: string $element The locator of the specified selector.
param: string $selectortype The selector type (link or text)
return: void

should_not_exist_in_current_page_administration($element, $selectortype)   X-Ref
Checks that current page administration contains text

param: string $element The locator of the specified selector.
param: string $selectortype The selector type (link or text)
return: void

i_navigate_to_in_site_administration($nodetext)   X-Ref
Go to site administration item

param: string $nodetext navigation node to click, may contain path, for example "Reports > Overview"
return: void

i_open_my_profile_in_edit_mode()   X-Ref
Opens the current users profile page in edit mode.

return: void

i_am_on_page(string $page)   X-Ref
Open a given page, belonging to a plugin or core component.

The page-type are interpreted by each plugin to work out the
corresponding URL. See the resolve_url method in each class like
behat_mod_forum. That method should document which page types are
recognised, and how the name identifies them.

For pages belonging to core, the 'core > ' bit is omitted.

param: string $page the component and page name.

i_am_on_page_logged_in_as(string $page, string $username)   X-Ref
Open a given page logged in as a given user.

This is like the combination
When I log in as "..."
And I am on the "..." page
but with the advantage that you go straight to the desired page, without
having to wait for the Dashboard to load.

param: string $page the type of page. E.g. 'Admin notifications' or 'core_user > Preferences'.
param: string $username the name of the user to log in as. E.g. 'admin'.

resolve_page_helper(string $page)   X-Ref
Helper used by i_am_on_page() and i_am_on_page_logged_in_as().

param: string $page the type of page. E.g. 'Admin notifications' or 'core_user > Preferences'.
return: moodle_url the corresponding URL.

parse_page_name(string $page)   X-Ref
Parse a full page name like 'Admin notifications' or 'core_user > Preferences'.

E.g. parsing 'mod_quiz > View' gives ['mod_quiz', 'View'].

param: string $page the full page name
return: array with two elements, component and page name.

i_am_on_page_instance(string $identifier, string $type)   X-Ref
Open a given instance of a page, belonging to a plugin or core component.

The instance identifier and page-type are interpreted by each plugin to
work out the corresponding URL. See the resolve_page_instance_url method
in each class like behat_mod_forum. That method should document which page
types are recognised, and how the name identifies them.

For pages belonging to core, the 'core > ' bit is omitted.

param: string $identifier identifies the particular page. E.g. 'Test quiz'.
param: string $type the component and page type. E.g. 'mod_quiz > View'.

i_am_on_page_instance_logged_in_as(string $identifier,string $type, string $username)   X-Ref
Open a given page logged in as a given user.

This is like the combination
When I log in as "..."
And I am on the "..." "..." page
but with the advantage that you go straight to the desired page, without
having to wait for the Dashboard to load.

param: string $identifier identifies the particular page. E.g. 'Test quiz'.
param: string $type the component and page type. E.g. 'mod_quiz > View'.
param: string $username the name of the user to log in as. E.g. 'student'.

resolve_page_instance_helper(string $identifier, string $pagetype)   X-Ref
Helper used by i_am_on_page() and i_am_on_page_logged_in_as().

param: string $identifier identifies the particular page. E.g. 'Test quiz'.
param: string $pagetype the component and page type. E.g. 'mod_quiz > View'.
return: moodle_url the corresponding URL.

resolve_core_page_url(string $name)   X-Ref
Convert core page names to URLs for steps like 'When I am on the "[page name]" page'.

Recognised page names are:
| Homepage            | Homepage (normally dashboard).                                 |
| Admin notifications | Admin notification screen.                                     |

param: string $name identifies which identifies this page, e.g. 'Homepage', 'Admin notifications'.
return: moodle_url the corresponding URL.

resolve_core_page_instance_url(string $type, string $identifier)   X-Ref
Convert page names to URLs for steps like 'When I am on the "[identifier]" "[page type]" page'.

Recognised page names are:
| Page type                  | Identifier meaning        | description                          |
| Category                   | category idnumber         | List of courses in that category.    |
| Course                     | course shortname          | Main course home pag                 |
| Course editing             | course shortname          | Edit settings page for the course    |
| Activity                   | activity idnumber         | Start page for that activity         |
| Activity editing           | activity idnumber         | Edit settings page for that activity |
| [modname] Activity         | activity name or idnumber | Start page for that activity         |
| [modname] Activity editing | activity name or idnumber | Edit settings page for that activity |

Examples:

When I am on the "Welcome to ECON101" "forum activity" page logged in as student1

param: string $type identifies which type of page this is, e.g. 'Category page'.
param: string $identifier identifies the particular page, e.g. 'test-cat'.
return: moodle_url the corresponding URL.

i_am_on_course_homepage($coursefullname)   X-Ref
Opens the course homepage. (Consider using 'I am on the "shortname" "Course" page' step instead.)

param: string $coursefullname The full name of the course.
return: void

i_am_on_course_homepage_with_editing_mode_on($coursefullname)   X-Ref
Open the course homepage with editing mode enabled.

param: string $coursefullname The course full name of the course.
return: void

i_open_flat_navigation_drawer()   X-Ref
Opens the flat navigation drawer if it is not already open


i_close_flat_navigation_drawer()   X-Ref
Closes the flat navigation drawer if it is open (does nothing if JS disabled)


i_select_from_flat_navigation_drawer($link)   X-Ref
Clicks link with specified id|title|alt|text in the flat navigation drawer.

param: string $link

go_to_main_course_page()   X-Ref
If we are not on the course main page, click on the course link in the navbar


select_on_administration_page($nodelist)   X-Ref
Finds and clicks a link on the admin page (site administration or course administration)

param: array $nodelist

find_header_administration_menu($mustexist = false)   X-Ref
Locates the administration menu in the <header> element and returns its xpath

param: bool $mustexist if specified throws an exception if menu is not found
return: null|string

find_page_administration_menu($mustexist = false)   X-Ref
Locates the administration menu on the page (but not in the header) and returns its xpath

param: bool $mustexist if specified throws an exception if menu is not found
return: null|string

toggle_page_administration_menu($menuxpath = null)   X-Ref
Toggles administration menu

param: string $menuxpath (optional) xpath to the page administration menu if already known

select_from_administration_menu($nodelist)   X-Ref
Finds a page edit cog and select an item from it

If the page edit cog is in the page header and the item is not found there, click "More..." link
and find the item on the course/frontpage administration page

param: array $nodelist

i_am_on_fixture_page($url)   X-Ref
Visit a fixture page for testing stuff that is not available in core.

Please always, to prevent unwanted requests, protect behat fixture files with:
defined('BEHAT_SITE_RUNNING') || die();

param: string $url local path to fixture page