Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

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

Navigation steps definitions.

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

Defines 1 class

behat_navigation:: (50 methods):
  i_should_see_is_active_in_navigation()
  get_node_text_node()
  navigation_node_should_be_expandable()
  navigation_node_should_not_be_expandable()
  i_follow_in_the_user_menu()
  i_expand_node()
  i_collapse_node()
  find_node_in_navigation()
  select_node_in_navigation()
  get_top_navigation_node()
  get_navigation_node()
  get_expand_navbar_step()
  i_navigate_to_in_current_page_administration()
  should_exist_in_current_page_administration()
  should_not_exist_in_current_page_administration()
  i_navigate_to_in_site_administration()
  i_open_my_profile_in_edit_mode()
  i_am_on_page()
  i_am_on_page_logged_in_as()
  resolve_page_helper()
  parse_page_name()
  i_am_on_page_instance()
  i_am_on_page_instance_logged_in_as()
  resolve_page_instance_helper()
  resolve_core_page_url()
  resolve_core_page_instance_url()
  i_am_on_course_homepage()
  i_am_on_course_homepage_with_editing_mode_on()
  i_am_on_course_homepage_with_editing_mode_set_to()
  i_open_flat_navigation_drawer()
  i_close_flat_navigation_drawer()
  i_select_from_primary_navigation()
  i_select_from_secondary_navigation()
  go_to_main_course_page()
  select_on_administration_page()
  find_header_administration_menu()
  find_page_administration_menu()
  find_page_action_menu()
  toggle_page_administration_menu()
  select_from_administration_menu()
  i_am_on_fixture_page()
  go_to_breadcrumb_location()
  should_exist_in_user_menu()
  should_exist_in_user_submenu()
  i_should_see_user_submenu()
  get_user_menu_xpath()
  get_user_submenu_xpath()
  is_editing_on()
  i_turn_editing_mode_on()
  i_turn_editing_mode_off()


Class: behat_navigation  - X-Ref

Steps definitions to navigate through the navigation tree nodes.

i_should_see_is_active_in_navigation($element)   X-Ref
Checks whether a navigation node is active within the block navigation.

return: void
param: string      $element The name of the nav elemnent to look for.

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.

return: \Behat\Mink\Element\NodeElement
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.

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

return: bool
param: string $nodetext

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

return: bool
param: string $nodetext

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.

return: bool|void
param: string $nodetext

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

return: bool|void
param: string $nodetext

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

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

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.

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

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

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

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.

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

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

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

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

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

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

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

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().

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

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'].

return: array with two elements, component and page name.
param: string $page the full 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().

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

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.                                     |

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

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 page                |
| 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 |
| Backup                     | course shortname          | Course to backup                     |
| Import                     | course shortname          | Course import from                   |
| Restore                    | course shortname          | Course to restore from               |
| Reset                      | course shortname          | Course to reset                      |
| Course copy                | course shortname          | Course to copy                       |
| Groups                     | course shortname          | Groups page for the course           |
| Permissions                | course shortname          | Permissions page for the course      |
| Enrolment methods          | course shortname          | Enrolment methods for the course     |
| Enrolled users             | course shortname          | The main participants page           |
| Other users                | course shortname          | The course other users page          |

Examples:

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

return: moodle_url the corresponding URL.
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'.

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

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

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.

i_am_on_course_homepage_with_editing_mode_set_to(string $coursefullname, string $onoroff)   X-Ref
Open the course homepage with editing mode set to either on, or off.

param: string $coursefullname The course full name of the course.
param: string $onoroff Whehter to switch editing on, or off.

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_primary_navigation(string $link)   X-Ref
Clicks link with specified id|title|alt|text in the primary navigation

param: string $link

i_select_from_secondary_navigation(string $link)   X-Ref
Clicks link with specified id|title|alt|text in the secondary navigation

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

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

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

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

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

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

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

go_to_breadcrumb_location(string $pagename)   X-Ref
First checks to see if we are on this page via the breadcrumb. If not we then attempt to follow the link name given.

param: string $pagename Name of the breadcrumb item to check and follow.

should_exist_in_user_menu($itemtext, $selectortype, $not = null)   X-Ref
Checks whether an item exists in the user menu.

return: void
param: string $itemtext The menu item to find
param: string $selectortype The selector type
param: string|null $not Instructs to checks whether the element does not exist in the user menu, if defined

should_exist_in_user_submenu($itemtext, $selectortype, $submenuname, $not = null)   X-Ref
Checks whether an item exists in a given user submenu.

return: void
param: string $itemtext The submenu item to find
param: string $selectortype The selector type
param: string $submenuname The name of the submenu
param: string|null $not Instructs to checks whether the element does not exist in the user menu, if defined

i_should_see_user_submenu($submenuname)   X-Ref
Checks whether a given user submenu is visible.

return: void
param: string $submenuname The name of the submenu

get_user_menu_xpath()   X-Ref
Return the xpath for the user menu element.

return: string The xpath

get_user_submenu_xpath($submenuname)   X-Ref
Return the xpath for a given user submenu element.

return: string The xpath
param: string $submenuname The name of the submenu

is_editing_on()   X-Ref
Returns whether the user can edit the current page.

return: bool

i_turn_editing_mode_on()   X-Ref
Turns editing mode on.


i_turn_editing_mode_off()   X-Ref
Turns editing mode off.