Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
|
Steps definitions to navigate through the navigation tree nodes. More...
Public Member Functions | |
get_expand_navbar_step () | |
Step to open the navigation bar if it is needed. | |
getSession ($name=null) | |
Returns the Mink session. | |
go_to_breadcrumb_location (string $pagename) | |
First checks to see if we are on this page via the breadcrumb. | |
i_am_on_course_homepage ($coursefullname) | |
Opens the course homepage. | |
i_am_on_course_homepage_with_editing_mode_on ($coursefullname) | |
Open the course homepage with editing mode enabled. | |
i_am_on_course_homepage_with_editing_mode_set_to (string $coursefullname, string $onoroff) | |
Open the course homepage with editing mode set to either on, or off. | |
i_am_on_fixture_page ($url) | |
Visit a fixture page for testing stuff that is not available in core. | |
i_am_on_page (string $page) | |
Open a given page, belonging to a plugin or core component. | |
i_am_on_page_instance (string $identifier, string $type) | |
Open a given instance of a page, belonging to a plugin or core component. | |
i_am_on_page_instance_logged_in_as (string $identifier, string $type, string $username) | |
Open a given page logged in as a given user. | |
i_am_on_page_logged_in_as (string $page, string $username) | |
Open a given page logged in as a given user. | |
i_close_block_drawer_if_open () | |
Close the block drawer if it is open. | |
i_close_flat_navigation_drawer () | |
Closes the flat navigation drawer if it is open (does nothing if JS disabled) | |
i_collapse_node ($nodetext) | |
Collapses the selected node of the navigation tree that matches the text. | |
i_expand_node ($nodetext) | |
Expands the selected node of the navigation tree that matches the text. | |
i_follow_in_the_user_menu ($nodetext) | |
Click on an entry in the user menu. | |
i_keep_block_drawer_closed () | |
I close the block drawer and keep it closed. | |
i_navigate_to_in_current_page_administration ($nodetext) | |
Go to current page setting item. | |
i_navigate_to_in_site_administration ($nodetext) | |
Go to site administration item. | |
i_open_a_tab_on_the_current_page (string $name) | |
Opens a new tab with given name on the same URL as current page and switches to it. | |
i_open_a_tab_on_the_page (string $name, string $page) | |
Opens a new tab with given name on specified page, and switches to it. | |
i_open_a_tab_on_the_page_instance (string $name, string $identifier, string $page) | |
Opens a new tab with given name (on specified page), and switches to it. | |
i_open_flat_navigation_drawer () | |
Opens the flat navigation drawer if it is not already open. | |
i_open_my_profile_in_edit_mode () | |
Opens the current users profile page in edit mode. | |
i_select_from_primary_navigation (string $link) | |
Clicks link with specified id|title|alt|text in the primary navigation. | |
i_select_from_secondary_navigation (string $link) | |
Clicks link with specified id|title|alt|text in the secondary navigation. | |
i_should_see_is_active_in_navigation ($element) | |
Checks whether a navigation node is active within the block navigation. | |
i_should_see_user_submenu ($submenuname) | |
Checks whether a given user submenu is visible. | |
i_turn_editing_mode_off () | |
Turns editing mode off. | |
i_turn_editing_mode_on () | |
Turns editing mode on. | |
navigation_node_should_be_expandable ($nodetext) | |
Returns true if the navigation node with the given text is expandable. | |
navigation_node_should_not_be_expandable ($nodetext) | |
Returns true if the navigation node with the given text is not expandable. | |
should_exist_in_current_page_administration ($element, $selectortype) | |
Checks that current page administration contains text. | |
should_exist_in_user_menu ($itemtext, $selectortype, $not=null) | |
Checks whether an item exists in the user menu. | |
should_exist_in_user_submenu ($itemtext, $selectortype, $submenuname, $not=null) | |
Checks whether an item exists in a given user submenu. | |
should_not_exist_in_current_page_administration ($element, $selectortype) | |
Checks that current page administration contains text. | |
Public Attributes | |
const | PAGE_READY_JS |
The JS code to check that the page is ready. | |
Protected Member Functions | |
find_header_administration_menu ($mustexist=false) | |
Locates the administration menu in the <header> element and returns its xpath. | |
find_node_in_navigation ($nodetext, $parentnodes, $nodetype='link') | |
Finds a node in the Navigation or Administration tree. | |
find_page_action_menu ($mustexist=false) | |
Locates the action menu on the page (but not in the header) and returns its xpath. | |
find_page_administration_menu ($mustexist=false) | |
Locates the administration menu on the page (but not in the header) and returns its xpath. | |
get_navigation_node ($nodetext, $parentnode=null) | |
Helper function to get sub-navigation node. | |
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. | |
get_top_navigation_node ($nodetext) | |
Helper function to get top navigation node in tree. | |
get_user_menu_xpath () | |
Return the xpath for the user menu element. | |
get_user_submenu_xpath ($submenuname) | |
Return the xpath for a given user submenu element. | |
go_to_main_course_page () | |
If we are not on the course main page, click on the course link in the navbar. | |
is_editing_on () | |
Returns whether the user can edit the current page. | |
open_tab (string $name, string $jstarget) | |
Opens a new tab at the given target URL. | |
parse_page_name (string $page) | |
Parse a full page name like 'Admin notifications' or 'core_user > Preferences'. | |
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'. | |
resolve_core_page_url (string $name) | |
Convert core page names to URLs for steps like 'When I am on the "[page name]" page'. | |
resolve_page_helper (string $page) | |
Helper used by i_am_on_page() and i_am_on_page_logged_in_as(). | |
resolve_page_instance_helper (string $identifier, string $pagetype) | |
Helper used by i_am_on_page() and i_am_on_page_logged_in_as(). | |
select_from_administration_menu ($nodelist) | |
Finds a page edit cog and select an item from it. | |
select_node_in_navigation ($nodetext, $parentnodes) | |
Finds a node in the Navigation or Administration tree and clicks on it. | |
select_on_administration_page ($nodelist) | |
Finds and clicks a link on the admin page (site administration or course administration) | |
toggle_page_administration_menu ($menuxpath=null) | |
Toggles administration menu. | |
Steps definitions to navigate through the navigation tree nodes.
|
protected |
Locates the administration menu in the <header> element and returns its xpath.
bool | $mustexist | if specified throws an exception if menu is not found |
null|string |
|
protected |
Finds a node in the Navigation or Administration tree.
string | $nodetext | |
array | $parentnodes | |
string | $nodetype | node type (link or text) |
NodeElement|null |
ExpectationException | when one of the parent nodes is not found |
|
protected |
Locates the action menu on the page (but not in the header) and returns its xpath.
null | bool | $mustexist | if specified throws an exception if menu is not found |
null|string |
|
protected |
Locates the administration menu on the page (but not in the header) and returns its xpath.
bool | $mustexist | if specified throws an exception if menu is not found |
null|string |
behat_navigation::get_expand_navbar_step | ( | ) |
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$/
|
protected |
Helper function to get sub-navigation node.
ExpectationException | if note not found. |
string | $nodetext | node to find. |
NodeElement | $parentnode | parent navigation node. |
NodeElement. |
|
protected |
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.
string | $text | |
bool | $branch | Set this true if you're only interested in the node if its a branch. |
null | bool | $collapsed | Set 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 | $exception | The exception to throw if the node is not found. |
Behat\Mink\Element\NodeElement |
|
protected |
Helper function to get top navigation node in tree.
ExpectationException | if note not found. |
string | $nodetext | name of top navigation node in tree. |
NodeElement |
Reimplemented in behat_theme_classic_behat_navigation.
|
protected |
Return the xpath for the user menu element.
string | The xpath |
|
protected |
Return the xpath for a given user submenu element.
string | $submenuname | The name of the submenu |
string | The xpath |
|
inherited |
Returns the Mink session.
string | null | $name | name of the session OR active session will be used |
Behat\Mink\Session |
Implemented in behat_form_field.
behat_navigation::go_to_breadcrumb_location | ( | string | $pagename | ) |
First checks to see if we are on this page via the breadcrumb.
If not we then attempt to follow the link name given.
string | $pagename | Name of the breadcrumb item to check and follow. @Given /^I follow the breadcrumb "(?P<url_string>(?:[^"]|::")*)"$/ |
behat_navigation::i_am_on_course_homepage | ( | $coursefullname | ) |
Opens the course homepage.
(Consider using 'I am on the "shortname" "Course" page' step instead.)
@Given /^I am on "(?P<coursefullname_string>(?:[^"]|::")*)" course homepage$/
coding_exception |
string | $coursefullname | The full name of the course. |
void |
behat_navigation::i_am_on_course_homepage_with_editing_mode_on | ( | $coursefullname | ) |
Open the course homepage with editing mode enabled.
string | $coursefullname | The course full name of the course. |
behat_navigation::i_am_on_course_homepage_with_editing_mode_set_to | ( | string | $coursefullname, |
string | $onoroff ) |
Open the course homepage with editing mode set to either on, or off.
@Given I am on :coursefullname course homepage with editing mode :onoroff
coding_exception |
string | $coursefullname | The course full name of the course. |
string | $onoroff | Whehter to switch editing on, or off. |
behat_navigation::i_am_on_fixture_page | ( | $url | ) |
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>(?:[^"]|::")*)"$/
string | $url | local path to fixture page |
behat_navigation::i_am_on_page | ( | string | $page | ) |
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$/
string | $page | the component and page name. E.g. 'Admin notifications' or 'core_user > Preferences'. |
Exception | if the specified page cannot be determined. |
behat_navigation::i_am_on_page_instance | ( | string | $identifier, |
string | $type ) |
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$/
string | $identifier | identifies the particular page. E.g. 'Test quiz'. |
string | $type | the component and page type. E.g. 'mod_quiz > View'. |
Exception | if the specified page cannot be determined. |
behat_navigation::i_am_on_page_instance_logged_in_as | ( | string | $identifier, |
string | $type, | ||
string | $username ) |
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>[^"]*)"$/
string | $identifier | identifies the particular page. E.g. 'Test quiz'. |
string | $type | the component and page type. E.g. 'mod_quiz > View'. |
string | $username | the name of the user to log in as. E.g. 'student'. |
Exception | if the specified page cannot be determined. |
behat_navigation::i_am_on_page_logged_in_as | ( | string | $page, |
string | $username ) |
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>[^ "]*)"$/
string | $page | the type of page. E.g. 'Admin notifications' or 'core_user > Preferences'. |
string | $username | the name of the user to log in as. E.g. 'admin'. |
Exception | if the specified page cannot be determined. |
behat_navigation::i_close_block_drawer_if_open | ( | ) |
Close the block drawer if it is open.
This is necessary as in Behat the block drawer is open at each page load (disregarding user's settings) As the block drawer is positioned at the front of some contextual dialogs on the grade report for example. @Given I close block drawer if open
void |
behat_navigation::i_close_flat_navigation_drawer | ( | ) |
Closes the flat navigation drawer if it is open (does nothing if JS disabled)
@When /^I close flat navigation drawer$/
ElementNotFoundException | Thrown by behat_base\find |
behat_navigation::i_collapse_node | ( | $nodetext | ) |
Collapses the selected node of the navigation tree that matches the text.
@Given /^I collapse "(?P<nodetext_string>(?:[^"]|::")*)" node$/
ExpectationException |
string | $nodetext |
bool|void |
behat_navigation::i_expand_node | ( | $nodetext | ) |
Expands the selected node of the navigation tree that matches the text.
@Given /^I expand "(?P<nodetext_string>(?:[^"]|::")*)" node$/
ExpectationException |
string | $nodetext |
bool|void |
behat_navigation::i_follow_in_the_user_menu | ( | $nodetext | ) |
Click on an entry in the user menu.
@Given /^I follow "(?P<nodetext_string>(?:[^"]|::")*)" in the user menu$/
string | $nodetext |
behat_navigation::i_keep_block_drawer_closed | ( | ) |
I close the block drawer and keep it closed.
@Given I keep block drawer closed
void |
behat_navigation::i_navigate_to_in_current_page_administration | ( | $nodetext | ) |
Go to current page setting item.
This can be used on front page, course, category or modules pages.
@Given /^I navigate to "(?P<nodetext_string>(?:[^"]|::")*)" in current page administration$/
ExpectationException |
string | $nodetext | navigation node to click, may contain path, for example "Reports > Overview" |
void |
Reimplemented in behat_theme_classic_behat_navigation.
behat_navigation::i_navigate_to_in_site_administration | ( | $nodetext | ) |
Go to site administration item.
@Given /^I navigate to "(?P<nodetext_string>(?:[^"]|::")*)" in site administration$/
ExpectationException |
string | $nodetext | navigation node to click, may contain path, for example "Reports > Overview" |
void |
Reimplemented in behat_theme_classic_behat_navigation.
behat_navigation::i_open_a_tab_on_the_current_page | ( | string | $name | ) |
Opens a new tab with given name on the same URL as current page and switches to it.
string | $name | Tab name that can be used for switching later (no whitespace) @When /^I open a tab named "(?<name>[^"]*)" on the current page$/ |
behat_navigation::i_open_a_tab_on_the_page | ( | string | $name, |
string | $page ) |
Opens a new tab with given name on specified page, and switches to it.
string | $name | Tab name that can be used for switching later (no whitespace) |
string | $page | Page name @When /^I open a tab named "(?<name>[^"]*)" on the "(?<page>[^"]*)" page$/ |
behat_navigation::i_open_a_tab_on_the_page_instance | ( | string | $name, |
string | $identifier, | ||
string | $page ) |
Opens a new tab with given name (on specified page), and switches to it.
behat_navigation::i_open_flat_navigation_drawer | ( | ) |
Opens the flat navigation drawer if it is not already open.
@When /^I open flat navigation drawer$/
ElementNotFoundException | Thrown by behat_base\find |
behat_navigation::i_open_my_profile_in_edit_mode | ( | ) |
Opens the current users profile page in edit mode.
@Given /^I open my profile in edit mode$/
coding_exception |
void |
behat_navigation::i_select_from_primary_navigation | ( | string | $link | ) |
Clicks link with specified id|title|alt|text in the primary navigation.
@When /^I select "(?P<link_string>(?:[^"]|::")*)" from primary navigation$/
ElementNotFoundException | Thrown by behat_base\find |
string | $link |
behat_navigation::i_select_from_secondary_navigation | ( | string | $link | ) |
Clicks link with specified id|title|alt|text in the secondary navigation.
@When I select :link from secondary navigation
ElementNotFoundException | Thrown by behat_base\find |
string | $link |
behat_navigation::i_should_see_is_active_in_navigation | ( | $element | ) |
Checks whether a navigation node is active within the block navigation.
@Given i should see :name is active in navigation
ElementNotFoundException |
string | $element | The name of the nav elemnent to look for. |
void |
Reimplemented in behat_theme_boost_behat_navigation.
behat_navigation::i_should_see_user_submenu | ( | $submenuname | ) |
Checks whether a given user submenu is visible.
@Then /^I should see "(?P<submenu_string>[^"]*)" user submenu$/
ElementNotFoundException | |
ExpectationException |
string | $submenuname | The name of the submenu |
void |
behat_navigation::i_turn_editing_mode_off | ( | ) |
Turns editing mode off.
@Given I switch editing mode off @Given I turn editing mode off
behat_navigation::i_turn_editing_mode_on | ( | ) |
Turns editing mode on.
@Given I switch editing mode on @Given I turn editing mode on
|
protected |
Returns whether the user can edit the current page.
bool |
behat_navigation::navigation_node_should_be_expandable | ( | $nodetext | ) |
Returns true if the navigation node with the given text is expandable.
@Given /^navigation node "([^"]*)" should be expandable$/
ExpectationException |
string | $nodetext |
bool |
behat_navigation::navigation_node_should_not_be_expandable | ( | $nodetext | ) |
Returns true if the navigation node with the given text is not expandable.
@Given /^navigation node "([^"]*)" should not be expandable$/
ExpectationException |
string | $nodetext |
bool |
|
protected |
Opens a new tab at the given target URL.
string | $name | Name for tab |
string | $jstarget | Target in JavaScript syntax, i.e. if a string, must be quoted |
|
protected |
|
protected |
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 | | 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
string | $type | identifies which type of page this is, e.g. 'Category page'. |
string | $identifier | identifies the particular page, e.g. 'test-cat'. |
moodle_url | the corresponding URL. |
Exception | with a meaningful error message if the specified page cannot be found. |
|
protected |
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. |
string | $name | identifies which identifies this page, e.g. 'Homepage', 'Admin notifications'. |
moodle_url | the corresponding URL. |
Exception | with a meaningful error message if the specified page cannot be found. |
|
protected |
Helper used by i_am_on_page() and i_am_on_page_logged_in_as().
string | $page | the type of page. E.g. 'Admin notifications' or 'core_user > Preferences'. |
moodle_url | the corresponding URL. |
|
protected |
Helper used by i_am_on_page() and i_am_on_page_logged_in_as().
string | $identifier | identifies the particular page. E.g. 'Test quiz'. |
string | $pagetype | the component and page type. E.g. 'mod_quiz > View'. |
moodle_url | the corresponding URL. |
|
protected |
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
array | $nodelist |
ElementNotFoundException |
|
protected |
Finds a node in the Navigation or Administration tree and clicks on it.
string | $nodetext | |
array | $parentnodes |
ExpectationException |
|
protected |
Finds and clicks a link on the admin page (site administration or course administration)
array | $nodelist |
behat_navigation::should_exist_in_current_page_administration | ( | $element, | |
$selectortype ) |
Checks that current page administration contains text.
@Given /^"(?P<element_string>(?:[^"]|::")*)" "(?P<selector_string>[^"]*)" should exist in current page administration$/ @throws ExpectationException @param string $element The locator of the specified selector. This may be a path, for example "Subscription mode > Forced subscription"
string | $selectortype | The selector type (link or text) |
void |
Reimplemented in behat_theme_classic_behat_navigation.
behat_navigation::should_exist_in_user_menu | ( | $itemtext, | |
$selectortype, | |||
$not = null ) |
Checks whether an item exists in the user menu.
@Given :itemtext :selectortype should exist in the user menu @Given :itemtext :selectortype should :not exist in the user menu
ElementNotFoundException |
string | $itemtext | The menu item to find |
string | $selectortype | The selector type |
string | null | $not | Instructs to checks whether the element does not exist in the user menu, if defined |
void |
behat_navigation::should_exist_in_user_submenu | ( | $itemtext, | |
$selectortype, | |||
$submenuname, | |||
$not = null ) |
Checks whether an item exists in a given user submenu.
@Given :itemtext :selectortype should exist in the :submenuname user submenu @Given :itemtext :selectortype should :not exist in the :submenuname user submenu
ElementNotFoundException |
string | $itemtext | The submenu item to find |
string | $selectortype | The selector type |
string | $submenuname | The name of the submenu |
string | null | $not | Instructs to checks whether the element does not exist in the user menu, if defined |
void |
behat_navigation::should_not_exist_in_current_page_administration | ( | $element, | |
$selectortype ) |
Checks that current page administration contains text.
@Given /^"(?P<element_string>(?:[^"]|::")*)" "(?P<selector_string>[^"]*)" should not exist in current page administration$/ @throws ExpectationException @param string $element The locator of the specified selector. This may be a path, for example "Subscription mode > Forced subscription"
string | $selectortype | The selector type (link or text) |
void |
|
protected |
Toggles administration menu.
string | $menuxpath | (optional) xpath to the page administration menu if already known |
|
inherited |
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.