Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
Public Member Functions | Public Attributes | Protected Member Functions | List of all members
behat_theme_classic_behat_navigation Class Reference
Inheritance diagram for behat_theme_classic_behat_navigation:
behat_navigation behat_base behat_session_interface

Public Member Functions

 get_expand_navbar_step ()
 Step to open the navigation bar if it is needed. More...
 
 getSession ($name=null)
 Returns the Mink session. More...
 
 i_am_on_course_homepage ($coursefullname)
 Opens the course homepage. More...
 
 i_am_on_course_homepage_with_editing_mode_on ($coursefullname)
 Open the course homepage with editing mode enabled. More...
 
 i_am_on_fixture_page ($url)
 Visit a fixture page for testing stuff that is not available in core. More...
 
 i_am_on_page (string $page)
 Open a given page, belonging to a plugin or core component. More...
 
 i_am_on_page_instance (string $identifier, string $type)
 Open a given instance of a page, belonging to a plugin or core component. More...
 
 i_am_on_page_instance_logged_in_as (string $identifier, string $type, string $username)
 Open a given page logged in as a given user. More...
 
 i_am_on_page_logged_in_as (string $page, string $username)
 Open a given page logged in as a given user. More...
 
 i_close_flat_navigation_drawer ()
 Closes the flat navigation drawer if it is open (does nothing if JS disabled) More...
 
 i_collapse_node ($nodetext)
 Collapses the selected node of the navigation tree that matches the text. More...
 
 i_expand_node ($nodetext)
 Expands the selected node of the navigation tree that matches the text. More...
 
 i_follow_in_the_user_menu ($nodetext)
 Click on an entry in the user menu. More...
 
 i_navigate_to_in_current_page_administration ($nodetext)
 Navigate to an item in a current page administration menu. More...
 
 i_navigate_to_in_site_administration ($nodetext)
 Navigate to an item within the site administration menu. More...
 
 i_open_flat_navigation_drawer ()
 Opens the flat navigation drawer if it is not already open. More...
 
 i_open_my_profile_in_edit_mode ()
 Opens the current users profile page in edit mode. More...
 
 i_select_from_flat_navigation_drawer ($link)
 Clicks link with specified id|title|alt|text in the flat navigation drawer. More...
 
 navigation_node_should_be_expandable ($nodetext)
 Returns true if the navigation node with the given text is expandable. More...
 
 navigation_node_should_not_be_expandable ($nodetext)
 Returns true if the navigation node with the given text is not expandable. More...
 
 page_administration_does_not_exist ()
 Check that the page administration menu does not exist on the page. More...
 
 page_administration_exists ()
 Check that the page administration menu exists on the page. More...
 
 should_exist_in_current_page_administration ($element, $selectortype)
 Check that current page administration contains an element. More...
 
 should_not_exist_in_current_page_administration ($element, $selectortype)
 Check that current page administration does not contains an element. More...
 

Public Attributes

const EXTENDED_TIMEOUT = 10
 And extended timeout for specific cases. More...
 
const PAGE_READY_JS
 The JS code to check that the page is ready. More...
 
const REDUCED_TIMEOUT = 2
 Small timeout. More...
 
const TIMEOUT = 6
 The timeout for each Behat step (load page, wait for an element to load...). More...
 

Protected Member Functions

 find_header_administration_menu ($mustexist=false)
 Locates the administration menu in the <header> element and returns its xpath. More...
 
 find_node_in_navigation ($nodetext, $parentnodes, $nodetype='link')
 Finds a node in the Navigation or Administration tree. More...
 
 find_page_administration_menu ($mustexist=false)
 Locate the administration menu on the page (but not in the header) and return its xpath. More...
 
 get_navigation_node ($nodetext, $parentnode=null)
 Helper function to get sub-navigation node. More...
 
 get_node_text_node ($text, $branch=false, $collapsed=null, $exception=null)
 Helper function to get a navigation nodes text element given its text from within the navigation block. More...
 
 get_top_navigation_node ($nodetext)
 Helper function to get top navigation node in the tree. More...
 
 go_to_main_course_page ()
 If we are not on the course main page, click on the course link in the navbar.
 
 parse_page_name (string $page)
 Parse a full page name like 'Admin notifications' or 'core_user > Preferences'. More...
 
 resolve_core_page_instance_url (string $type, string $identifier)
 Convert page names to URLs for steps like 'When I am on the "[identifier]" "[page type]" page'. More...
 
 resolve_core_page_url (string $name)
 Convert core page names to URLs for steps like 'When I am on the "[page name]" page'. More...
 
 resolve_page_helper (string $page)
 Helper used by i_am_on_page() and i_am_on_page_logged_in_as(). More...
 
 resolve_page_instance_helper (string $identifier, string $pagetype)
 Helper used by i_am_on_page() and i_am_on_page_logged_in_as(). More...
 
 select_from_administration_menu ($nodelist)
 Finds a page edit cog and select an item from it. More...
 
 select_node_in_navigation ($nodetext, $parentnodes)
 Finds a node in the Navigation or Administration tree and clicks on it. More...
 
 select_on_administration_page ($nodelist)
 Finds and clicks a link on the admin page (site administration or course administration) More...
 
 toggle_page_administration_menu ($menuxpath=null)
 Toggles administration menu. More...
 

Member Function Documentation

◆ find_header_administration_menu()

behat_navigation::find_header_administration_menu (   $mustexist = false)
protectedinherited

Locates the administration menu in the <header> element and returns its xpath.

Parameters
bool$mustexistif specified throws an exception if menu is not found
Return values
null|string

◆ find_node_in_navigation()

behat_navigation::find_node_in_navigation (   $nodetext,
  $parentnodes,
  $nodetype = 'link' 
)
protectedinherited

Finds a node in the Navigation or Administration tree.

Parameters
string$nodetext
array$parentnodes
string$nodetypenode type (link or text)
Return values
NodeElement|null
Exceptions
ExpectationExceptionwhen one of the parent nodes is not found

◆ find_page_administration_menu()

behat_theme_classic_behat_navigation::find_page_administration_menu (   $mustexist = false)
protected

Locate the administration menu on the page (but not in the header) and return its xpath.

Exceptions
ElementNotFoundException
Parameters
bool$mustexistIf true, throws an exception if menu is not found
Return values
null|string

Reimplemented from behat_navigation.

◆ get_expand_navbar_step()

behat_navigation::get_expand_navbar_step ( )
inherited

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.

@Given /^I expand navigation bar$/

◆ get_navigation_node()

behat_navigation::get_navigation_node (   $nodetext,
  $parentnode = null 
)
protectedinherited

Helper function to get sub-navigation node.

Exceptions
ExpectationExceptionif note not found.
Parameters
string$nodetextnode to find.
NodeElement$parentnodeparent navigation node.
Return values
NodeElement.

◆ get_node_text_node()

behat_navigation::get_node_text_node (   $text,
  $branch = false,
  $collapsed = null,
  $exception = null 
)
protectedinherited

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.

Parameters
string$text
bool$branchSet this true if you're only interested in the node if its a branch.
null | bool$collapsedSet this to true or false if you want the node to either be collapsed or not. If its left as null then we don't worry about it.
null | string | Exception | false$exceptionThe exception to throw if the node is not found.
Return values
Behat::Mink::Element::NodeElement

◆ get_top_navigation_node()

behat_theme_classic_behat_navigation::get_top_navigation_node (   $nodetext)
protected

Helper function to get top navigation node in the tree.

Exceptions
ExpectationExceptionif node not found.
Parameters
string$nodetextname of top navigation node in tree.
Return values
NodeElement

Reimplemented from behat_navigation.

◆ getSession()

behat_session_interface::getSession (   $name = null)
inherited

Returns the Mink session.

Parameters
string | null$namename of the session OR active session will be used
Return values
Behat::Mink::Session

Implemented in behat_form_field.

◆ i_am_on_course_homepage()

behat_navigation::i_am_on_course_homepage (   $coursefullname)
inherited

Opens the course homepage.

(Consider using 'I am on the "shortname" "Course" page' step instead.)

@Given /^I am on "(?P<coursefullname_string>(?:[^"]|::")*)" course homepage$/

Exceptions
coding_exception
Parameters
string$coursefullnameThe full name of the course.
Return values
void

◆ i_am_on_course_homepage_with_editing_mode_on()

behat_navigation::i_am_on_course_homepage_with_editing_mode_on (   $coursefullname)
inherited

Open the course homepage with editing mode enabled.

@Given /^I am on "(?P<coursefullname_string>(?:[^"]|::")*)" course homepage with editing mode on$/

Exceptions
coding_exception
Parameters
string$coursefullnameThe course full name of the course.
Return values
void

◆ i_am_on_fixture_page()

behat_navigation::i_am_on_fixture_page (   $url)
inherited

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

@Given /^I am on fixture page "(?P<url_string>(?:[^"]|::")*)"$/

Parameters
string$urllocal path to fixture page

◆ i_am_on_page()

behat_navigation::i_am_on_page ( string  $page)
inherited

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.

@When /^I am on the (?<page>[^ "]*) page$/ @When /^I am on the "(?<page>[^"]*)" page$/

Parameters
string$pagethe component and page name. E.g. 'Admin notifications' or 'core_user > Preferences'.
Exceptions
Exceptionif the specified page cannot be determined.

◆ i_am_on_page_instance()

behat_navigation::i_am_on_page_instance ( string  $identifier,
string  $type 
)
inherited

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.

@When /^I am on the (?<identifier>[^ "]*) (?<type>[^ "]*) page$/ @When /^I am on the "(?<identifier>[^"]*)" "(?<type>[^"]*)" page$/ @When /^I am on the (?<identifier>[^ "]*) "(?<type>[^"]*)" page$/ @When /^I am on the "(?<identifier>[^"]*)" (?<type>[^ "]*) page$/

Parameters
string$identifieridentifies the particular page. E.g. 'Test quiz'.
string$typethe component and page type. E.g. 'mod_quiz > View'.
Exceptions
Exceptionif the specified page cannot be determined.

◆ i_am_on_page_instance_logged_in_as()

behat_navigation::i_am_on_page_instance_logged_in_as ( string  $identifier,
string  $type,
string  $username 
)
inherited

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.

@When /^I am on the (?<identifier>[^ "]*) (?<type>[^ "]*) page logged in as (?<username>[^ "]*)$/ @When /^I am on the "(?<identifier>[^"]*)" "(?<type>[^"]*)" page logged in as (?<username>[^ "]*)$/ @When /^I am on the (?<identifier>[^ "]*) "(?<type>[^"]*)" page logged in as (?<username>[^ "]*)$/ @When /^I am on the "(?<identifier>[^"]*)" (?<type>[^ "]*) page logged in as (?<username>[^ "]*)$/ @When /^I am on the (?<identifier>[^ "]*) (?<type>[^ "]*) page logged in as "(?<username>[^"]*)"$/ @When /^I am on the "(?<identifier>[^"]*)" "(?<type>[^"]*)" page logged in as "(?<username>[^"]*)"$/ @When /^I am on the (?<identifier>[^ "]*) "(?<type>[^"]*)" page logged in as "(?<username>[^"]*)"$/ @When /^I am on the "(?<identifier>[^"]*)" (?<type>[^ "]*) page logged in as "(?<username>[^"]*)"$/

Parameters
string$identifieridentifies the particular page. E.g. 'Test quiz'.
string$typethe component and page type. E.g. 'mod_quiz > View'.
string$usernamethe name of the user to log in as. E.g. 'student'.
Exceptions
Exceptionif the specified page cannot be determined.

◆ i_am_on_page_logged_in_as()

behat_navigation::i_am_on_page_logged_in_as ( string  $page,
string  $username 
)
inherited

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.

@When /^I am on the (?<page>[^ "]*) page logged in as (?<username>[^ "]*)$/ @When /^I am on the "(?<page>[^"]*)" page logged in as (?<username>[^ "]*)$/ @When /^I am on the (?<page>[^ "]*) page logged in as "(?<username>[^ "]*)"$/ @When /^I am on the "(?<page>[^"]*)" page logged in as "(?<username>[^ "]*)"$/

Parameters
string$pagethe type of page. E.g. 'Admin notifications' or 'core_user > Preferences'.
string$usernamethe name of the user to log in as. E.g. 'admin'.
Exceptions
Exceptionif the specified page cannot be determined.

◆ i_close_flat_navigation_drawer()

behat_navigation::i_close_flat_navigation_drawer ( )
inherited

Closes the flat navigation drawer if it is open (does nothing if JS disabled)

@When /^I close flat navigation drawer$/

Exceptions
ElementNotFoundExceptionThrown by behat_base::find

◆ i_collapse_node()

behat_navigation::i_collapse_node (   $nodetext)
inherited

Collapses the selected node of the navigation tree that matches the text.

@Given /^I collapse "(?P<nodetext_string>(?:[^"]|::")*)" node$/

Exceptions
ExpectationException
Parameters
string$nodetext
Return values
bool|void

◆ i_expand_node()

behat_navigation::i_expand_node (   $nodetext)
inherited

Expands the selected node of the navigation tree that matches the text.

@Given /^I expand "(?P<nodetext_string>(?:[^"]|::")*)" node$/

Exceptions
ExpectationException
Parameters
string$nodetext
Return values
bool|void

◆ i_follow_in_the_user_menu()

behat_navigation::i_follow_in_the_user_menu (   $nodetext)
inherited

Click on an entry in the user menu.

@Given /^I follow "(?P<nodetext_string>(?:[^"]|::")*)" in the user menu$/

Parameters
string$nodetext

◆ i_navigate_to_in_current_page_administration()

behat_theme_classic_behat_navigation::i_navigate_to_in_current_page_administration (   $nodetext)

Navigate to an item in a current page administration menu.

Exceptions
ExpectationException
Parameters
string$nodetextThe navigation node/path to follow, eg "Course administration > Edit settings"
Return values
void

Reimplemented from behat_navigation.

◆ i_navigate_to_in_site_administration()

behat_theme_classic_behat_navigation::i_navigate_to_in_site_administration (   $nodetext)

Navigate to an item within the site administration menu.

Exceptions
ExpectationException
Parameters
string$nodetextThe navigation node/path to follow, excluding "Site administration" itself, eg "Grades > Scales"
Return values
void

Reimplemented from behat_navigation.

◆ i_open_flat_navigation_drawer()

behat_navigation::i_open_flat_navigation_drawer ( )
inherited

Opens the flat navigation drawer if it is not already open.

@When /^I open flat navigation drawer$/

Exceptions
ElementNotFoundExceptionThrown by behat_base::find

◆ i_open_my_profile_in_edit_mode()

behat_navigation::i_open_my_profile_in_edit_mode ( )
inherited

Opens the current users profile page in edit mode.

@Given /^I open my profile in edit mode$/

Exceptions
coding_exception
Return values
void

◆ i_select_from_flat_navigation_drawer()

behat_navigation::i_select_from_flat_navigation_drawer (   $link)
inherited

Clicks link with specified id|title|alt|text in the flat navigation drawer.

@When /^I select "(?P<link_string>(?:[^"]|::")*)" from flat navigation drawer$/

Exceptions
ElementNotFoundExceptionThrown by behat_base::find
Parameters
string$link

◆ navigation_node_should_be_expandable()

behat_navigation::navigation_node_should_be_expandable (   $nodetext)
inherited

Returns true if the navigation node with the given text is expandable.

@Given /^navigation node "([^"]*)" should be expandable$/

Exceptions
ExpectationException
Parameters
string$nodetext
Return values
bool

◆ navigation_node_should_not_be_expandable()

behat_navigation::navigation_node_should_not_be_expandable (   $nodetext)
inherited

Returns true if the navigation node with the given text is not expandable.

@Given /^navigation node "([^"]*)" should not be expandable$/

Exceptions
ExpectationException
Parameters
string$nodetext
Return values
bool

◆ page_administration_does_not_exist()

behat_theme_classic_behat_navigation::page_administration_does_not_exist ( )

Check that the page administration menu does not exist on the page.

This confirms the absence of the menu, which unauthorised users should not have access to. @Given /^I should not see the page administration menu$/

Exceptions
ExpectationException
Return values
void

◆ page_administration_exists()

behat_theme_classic_behat_navigation::page_administration_exists ( )

Check that the page administration menu exists on the page.

This confirms the existence of the menu, which authorised users should have access to. @Given /^I should see the page administration menu$/

Exceptions
ExpectationException
Return values
void

◆ parse_page_name()

behat_navigation::parse_page_name ( string  $page)
protectedinherited

Parse a full page name like 'Admin notifications' or 'core_user > Preferences'.

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

Parameters
string$pagethe full page name
Return values
arraywith two elements, component and page name.

◆ resolve_core_page_instance_url()

behat_navigation::resolve_core_page_instance_url ( string  $type,
string  $identifier 
)
protectedinherited

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

Parameters
string$typeidentifies which type of page this is, e.g. 'Category page'.
string$identifieridentifies the particular page, e.g. 'test-cat'.
Return values
moodle_urlthe corresponding URL.
Exceptions
Exceptionwith a meaningful error message if the specified page cannot be found.

◆ resolve_core_page_url()

behat_navigation::resolve_core_page_url ( string  $name)
protectedinherited

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

Parameters
string$nameidentifies which identifies this page, e.g. 'Homepage', 'Admin notifications'.
Return values
moodle_urlthe corresponding URL.
Exceptions
Exceptionwith a meaningful error message if the specified page cannot be found.

◆ resolve_page_helper()

behat_navigation::resolve_page_helper ( string  $page)
protectedinherited

Helper used by i_am_on_page() and i_am_on_page_logged_in_as().

Parameters
string$pagethe type of page. E.g. 'Admin notifications' or 'core_user > Preferences'.
Return values
moodle_urlthe corresponding URL.

◆ resolve_page_instance_helper()

behat_navigation::resolve_page_instance_helper ( string  $identifier,
string  $pagetype 
)
protectedinherited

Helper used by i_am_on_page() and i_am_on_page_logged_in_as().

Parameters
string$identifieridentifies the particular page. E.g. 'Test quiz'.
string$pagetypethe component and page type. E.g. 'mod_quiz > View'.
Return values
moodle_urlthe corresponding URL.

◆ select_from_administration_menu()

behat_navigation::select_from_administration_menu (   $nodelist)
protectedinherited

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

Parameters
array$nodelist
Exceptions
ElementNotFoundException

◆ select_node_in_navigation()

behat_navigation::select_node_in_navigation (   $nodetext,
  $parentnodes 
)
protectedinherited

Finds a node in the Navigation or Administration tree and clicks on it.

Parameters
string$nodetext
array$parentnodes
Exceptions
ExpectationException

◆ select_on_administration_page()

behat_navigation::select_on_administration_page (   $nodelist)
protectedinherited

Finds and clicks a link on the admin page (site administration or course administration)

Parameters
array$nodelist

◆ should_exist_in_current_page_administration()

behat_theme_classic_behat_navigation::should_exist_in_current_page_administration (   $element,
  $selectortype 
)

Check that current page administration contains an element.

Exceptions
ElementNotFoundException
Parameters
string$elementThe locator of the specified selector. This may be a path, for example "Subscription mode > Forced subscription"
string$selectortypeThe selector type (link or text)
Return values
void

Reimplemented from behat_navigation.

◆ should_not_exist_in_current_page_administration()

behat_theme_classic_behat_navigation::should_not_exist_in_current_page_administration (   $element,
  $selectortype 
)

Check that current page administration does not contains an element.

Exceptions
ExpectationException
Parameters
string$elementThe locator of the specified selector. This may be a path, for example "Subscription mode > Forced subscription"
string$selectortypeThe selector type (link or text)
Return values
void

Reimplemented from behat_navigation.

◆ toggle_page_administration_menu()

behat_navigation::toggle_page_administration_menu (   $menuxpath = null)
protectedinherited

Toggles administration menu.

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

Member Data Documentation

◆ EXTENDED_TIMEOUT

const behat_session_interface::EXTENDED_TIMEOUT = 10
inherited

And extended timeout for specific cases.

Deprecated:
since Moodle 3.7 MDL-64979 - please use get_extended_timeout() instead
Todo:
MDL-64982 This will be deleted in Moodle 3.11
See also
behat_base::get_extended_timeout()

◆ PAGE_READY_JS

const behat_session_interface::PAGE_READY_JS
inherited
Initial value:
= "document.readyState === 'complete' && " .
"(typeof M !== 'object' || typeof M.util !== 'object' || " .
"typeof M.util.pending_js === 'undefined' || M.util.pending_js.length === 0)"

The JS code to check that the page is ready.

The document must be complete and either M.util.pending_js must be empty, or it must not be defined at all.

◆ REDUCED_TIMEOUT

const behat_session_interface::REDUCED_TIMEOUT = 2
inherited

Small timeout.

A reduced timeout for cases where self::TIMEOUT is too much and a simple $this->getSession()->getPage()->find() could not be enough.

Deprecated:
since Moodle 3.7 MDL-64979 - please use get_reduced_timeout() instead
Todo:
MDL-64982 This will be deleted in Moodle 3.11
See also
behat_base::get_reduced_timeout()

◆ TIMEOUT

const behat_session_interface::TIMEOUT = 6
inherited

The timeout for each Behat step (load page, wait for an element to load...).

Deprecated:
since Moodle 3.7 MDL-64979 - please use get_timeout() instead
Todo:
MDL-64982 This will be deleted in Moodle 3.11
See also
behat_base::get_timeout()

The documentation for this class was generated from the following file: