Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

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

Behat course-related steps definitions.

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

Defines 1 class

behat_course:: (93 methods):
  get_partial_named_selectors()
  get_named_replacements()
  i_create_a_course_with()
  i_go_to_the_courses_management_page()
  i_add_to_section_and_i_fill_the_form_with()
  i_add_to_section()
  i_open_section_edit_menu()
  i_delete_section()
  i_turn_section_highlighting_on()
  i_turn_section_highlighting_off()
  i_show_section()
  i_hide_section()
  i_edit_the_section()
  i_edit_the_section_and_i_fill_the_form_with()
  section_should_be_highlighted()
  section_should_not_be_highlighted()
  section_should_be_hidden()
  section_activities_should_be_hidden()
  section_should_be_visible()
  i_move_up_section()
  i_move_down_section()
  activity_should_be_visible()
  activity_should_be_available_but_hidden_from_course_page()
  activity_should_be_hidden()
  label_should_be_hidden()
  i_move_activity_to_section()
  i_move_activity_to_section_yui()
  i_change_activity_name_to()
  i_open_actions_menu()
  i_close_actions_menu()
  actions_menu_should_be_open()
  actions_menu_should_have_item()
  actions_menu_should_not_have_item()
  i_indent_right_activity()
  i_indent_left_activity()
  i_delete_activity()
  i_duplicate_activity()
  i_duplicate_activity_editing_the_new_copy_with()
  i_wait_until_section_is_available()
  i_click_on_in_the_activity()
  get_activity_element()
  section_exists()
  show_section_link_exists()
  hide_section_link_exists()
  get_course_format()
  get_section_activities()
  get_activity_node()
  get_activity_name()
  is_course_editor()
  is_editing_on()
  get_management_category_listing_node_by_idnumber()
  get_management_category_listing_node_by_name()
  get_management_course_listing_node_by_name()
  get_management_course_listing_node_by_idnumber()
  i_click_on_category_in_the_management_interface()
  i_click_on_course_in_the_management_interface()
  i_select_category_in_the_management_interface()
  i_unselect_category_in_the_management_interface()
  i_select_course_in_the_management_interface()
  i_unselect_course_in_the_management_interface()
  i_move_category_to_top_level_in_the_management_interface()
  i_should_see_category_as_subcategory_of_in_the_management_interface()
  i_should_not_see_category_as_subcategory_of_in_the_management_interface()
  i_click_to_expand_category_in_the_management_interface()
  category_in_management_listing_should_be_visible()
  category_in_management_listing_should_be_dimmed()
  course_in_management_listing_should_be_visible()
  course_in_management_listing_should_be_dimmed()
  i_toggle_visibility_of_course_in_management_listing()
  i_toggle_visibility_of_category_in_management_listing()
  i_click_to_move_category_by_one()
  i_click_to_move_course_by_one()
  user_moves_listing_by_one()
  listing_is_highlighted()
  i_should_see_course_listing_before()
  i_should_see_category_listing_before()
  i_should_see_the_courses_management_page()
  i_should_see_the_courses_management_page_with_a_course_selected()
  i_click_on_action_for_item_in_management_course_listing()
  i_click_on_action_for_item_in_management_category_listing()
  i_toggle_category_children_visibility_in_frontpage()
  user_clicks_on_management_listing_action()
  i_click_on_category_in_the_management_category_listing()
  i_open_the_action_menu_for_item_in_management_category_listing()
  category_actions_menu_should_have_item()
  category_actions_menu_should_not_have_item()
  i_navigate_to_course_participants()
  i_should_see_teacher_before()
  i_should_not_see_teacher_after()
  i_open_the_activity_chooser()
  activity_date_in_activity_should_contain_text()
  activity_dates_information_in_activity_should_exist()
  activity_dates_information_in_activity_should_not_exist()


Class: behat_course  - X-Ref

Course-related steps definitions.

get_partial_named_selectors()   X-Ref
Return the list of partial named selectors.

return: array

get_named_replacements()   X-Ref
Return a list of the Mink named replacements for the component.

Named replacements allow you to define parts of an xpath that can be reused multiple times, or in multiple
xpaths.

This method should return a list of {@link behat_component_named_replacement} and the docs on that class explain
how it works.

return: behat_component_named_replacement[]

i_create_a_course_with(TableNode $table)   X-Ref
Creates a new course with the provided table data matching course settings names with the desired values.

param: TableNode $table The course data

i_go_to_the_courses_management_page()   X-Ref
Goes to the system courses/categories management page.


i_add_to_section_and_i_fill_the_form_with($activity, $section, TableNode $data)   X-Ref
Adds the selected activity/resource filling the form data with the specified field/value pairs. Sections 0 and 1 are also allowed on frontpage.

param: string $activity The activity name
param: int $section The section number
param: TableNode $data The activity field/value data

i_add_to_section($activity, $section)   X-Ref
Opens the activity chooser and opens the activity/resource form page. Sections 0 and 1 are also allowed on frontpage.

param: string $activity
param: int $section

i_open_section_edit_menu($sectionnumber)   X-Ref
Opens a section edit menu if it is not already opened.

param: string $sectionnumber

i_delete_section($sectionnumber)   X-Ref
Deletes course section.

param: int $sectionnumber The section number

i_turn_section_highlighting_on($sectionnumber)   X-Ref
Turns course section highlighting on.

param: int $sectionnumber The section number

i_turn_section_highlighting_off($sectionnumber)   X-Ref
Turns course section highlighting off.

param: int $sectionnumber The section number

i_show_section($sectionnumber)   X-Ref
Shows the specified hidden section. You need to be in the course page and on editing mode.

param: int $sectionnumber

i_hide_section($sectionnumber)   X-Ref
Hides the specified visible section. You need to be in the course page and on editing mode.

param: int $sectionnumber

i_edit_the_section($sectionnumber)   X-Ref
Go to editing section page for specified section number. You need to be in the course page and on editing mode.

param: int $sectionnumber

i_edit_the_section_and_i_fill_the_form_with($sectionnumber, TableNode $data)   X-Ref
Edit specified section and fill the form data with the specified field/value pairs.

param: int $sectionnumber The section number
param: TableNode $data The activity field/value data

section_should_be_highlighted($sectionnumber)   X-Ref
Checks if the specified course section hightlighting is turned on. You need to be in the course page on editing mode.

param: int $sectionnumber The section number

section_should_not_be_highlighted($sectionnumber)   X-Ref
Checks if the specified course section highlighting is turned off. You need to be in the course page on editing mode.

param: int $sectionnumber The section number

section_should_be_hidden($sectionnumber)   X-Ref
Checks that the specified section is visible. You need to be in the course page. It can be used being logged as a student and as a teacher on editing mode.

param: int $sectionnumber

section_activities_should_be_hidden($sectionnumber)   X-Ref
Checks that all actiities in the specified section are hidden. You need to be in the course page. It can be used being logged as a student and as a teacher on editing mode.

param: int $sectionnumber

section_should_be_visible($sectionnumber)   X-Ref
Checks that the specified section is visible. You need to be in the course page. It can be used being logged as a student and as a teacher on editing mode.

param: int $sectionnumber

i_move_up_section($sectionnumber)   X-Ref
Moves up the specified section, this step only works with Javascript disabled. Editing mode should be on.

param: int $sectionnumber

i_move_down_section($sectionnumber)   X-Ref
Moves down the specified section, this step only works with Javascript disabled. Editing mode should be on.

param: int $sectionnumber

activity_should_be_visible($activityname)   X-Ref
Checks that the specified activity is visible. You need to be in the course page. It can be used being logged as a student and as a teacher on editing mode.

param: string $activityname

activity_should_be_available_but_hidden_from_course_page($activityname)   X-Ref
Checks that the specified activity is visible. You need to be in the course page.
It can be used being logged as a student and as a teacher on editing mode.

param: string $activityname

activity_should_be_hidden($activityname)   X-Ref
Checks that the specified activity is hidden. You need to be in the course page. It can be used being logged as a student and as a teacher on editing mode.

param: string $activityname

label_should_be_hidden($activityname)   X-Ref
Checks that the specified label is hidden from students. You need to be in the course page.

param: string $activityname

i_move_activity_to_section($activityname, $sectionnumber)   X-Ref
Moves the specified activity to the first slot of a section.

Editing mode should be on.

param: string $activityname The activity name
param: int $sectionnumber The number of section

i_move_activity_to_section_yui($activityname, $sectionnumber)   X-Ref
Moves the specified activity to the first slot of a section using the YUI course format.

This step is experimental when using it in Javascript tests. Editing mode should be on.

param: string $activityname The activity name
param: int $sectionnumber The number of section

i_change_activity_name_to($activityname, $newactivityname)   X-Ref
Edits the activity name through the edit activity; this step only works with Javascript enabled. Editing mode should be on.

param: string $activityname
param: string $newactivityname

i_open_actions_menu($activityname)   X-Ref
Opens an activity actions menu if it is not already opened.

param: string $activityname

i_close_actions_menu($activityname)   X-Ref
Closes an activity actions menu if it is not already closed.

param: string $activityname

actions_menu_should_be_open($activityname)   X-Ref
Checks that the specified activity's action menu is open.

param: string $activityname

actions_menu_should_have_item($activityname, $menuitem)   X-Ref
Checks that the specified activity's action menu contains an item.

param: string $activityname
param: string $menuitem

actions_menu_should_not_have_item($activityname, $menuitem)   X-Ref
Checks that the specified activity's action menu does not contains an item.

param: string $activityname
param: string $menuitem

i_indent_right_activity($activityname)   X-Ref
Indents to the right the activity or resource specified by it's name. Editing mode should be on.

param: string $activityname

i_indent_left_activity($activityname)   X-Ref
Indents to the left the activity or resource specified by it's name. Editing mode should be on.

param: string $activityname

i_delete_activity($activityname)   X-Ref
Deletes the activity or resource specified by it's name. This step is experimental when using it in Javascript tests. You should be in the course page with editing mode on.

param: string $activityname

i_duplicate_activity($activityname)   X-Ref
Duplicates the activity or resource specified by it's name. You should be in the course page with editing mode on.

param: string $activityname

i_duplicate_activity_editing_the_new_copy_with($activityname, TableNode $data)   X-Ref
Duplicates the activity or resource and modifies the new activity with the provided data. You should be in the course page with editing mode on.

param: string $activityname
param: TableNode $data

i_wait_until_section_is_available($sectionnumber)   X-Ref
Waits until the section is available to interact with it. Useful when the section is performing an action and the section is overlayed with a loading layout.

Using the protected method as this method will be usually
called by other methods which are not returning a set of
steps and performs the actions directly, so it would not
be executed if it returns another step.

Hopefully we would not require test writers to use this step
and we will manage it from other step definitions.

param: int $sectionnumber
return: void

i_click_on_in_the_activity($element, $selectortype, $activityname)   X-Ref
Clicks on the specified element of the activity. You should be in the course page with editing mode turned on.

param: string $element
param: string $selectortype
param: string $activityname

get_activity_element($element, $selectortype, $activityname)   X-Ref
Clicks on the specified element inside the activity container.

param: string $element
param: string $selectortype
param: string $activityname
return: NodeElement

section_exists($sectionnumber)   X-Ref
Checks if the course section exists.

param: int $sectionnumber
return: string The xpath of the section.

show_section_link_exists($sectionnumber)   X-Ref
Returns the show section icon or throws an exception.

param: int $sectionnumber
return: NodeElement

hide_section_link_exists($sectionnumber)   X-Ref
Returns the hide section icon link if it exists or throws exception.

param: int $sectionnumber
return: NodeElement

get_course_format()   X-Ref
Gets the current course format.

return: string The course format in a frankenstyled name.

get_section_activities($sectionxpath)   X-Ref
Gets the section's activites DOM nodes.

param: string $sectionxpath
return: array NodeElement instances

get_activity_node($activityname)   X-Ref
Returns the DOM node of the activity from <li>.

param: string $activityname The activity name
return: NodeElement

get_activity_name($activitynode)   X-Ref
Gets the activity instance name from the activity node.

param: NodeElement $activitynode
return: string

is_course_editor()   X-Ref
Returns whether the user can edit the course contents or not.

return: bool

is_editing_on()   X-Ref
Returns whether the user can edit the course contents and the editing mode is on.

return: bool

get_management_category_listing_node_by_idnumber($idnumber)   X-Ref
Returns the category node from within the listing on the management page.

param: string $idnumber
return: \Behat\Mink\Element\NodeElement

get_management_category_listing_node_by_name($name, $link = false)   X-Ref
Returns a category node from within the management interface.

param: string $name The name of the category.
param: bool $link If set to true we'll resolve to the link rather than just the node.
return: \Behat\Mink\Element\NodeElement

get_management_course_listing_node_by_name($name, $link = false)   X-Ref
Returns a course node from within the management interface.

param: string $name The name of the course.
param: bool $link If set to true we'll resolve to the link rather than just the node.
return: \Behat\Mink\Element\NodeElement

get_management_course_listing_node_by_idnumber($idnumber)   X-Ref
Returns the course node from within the listing on the management page.

param: string $idnumber
return: \Behat\Mink\Element\NodeElement

i_click_on_category_in_the_management_interface($name)   X-Ref
Clicks on a category in the management interface.

param: string $name

i_click_on_course_in_the_management_interface($name)   X-Ref
Clicks on a course in the management interface.

param: string $name

i_select_category_in_the_management_interface($name)   X-Ref
Clicks on a category checkbox in the management interface, if not checked.

param: string $name

i_unselect_category_in_the_management_interface($name)   X-Ref
Clicks on a category checkbox in the management interface, if checked.

param: string $name

i_select_course_in_the_management_interface($name)   X-Ref
Clicks course checkbox in the management interface, if not checked.

param: string $name

i_unselect_course_in_the_management_interface($name)   X-Ref
Clicks course checkbox in the management interface, if checked.

param: string $name

i_move_category_to_top_level_in_the_management_interface($name)   X-Ref
Move selected categories to top level in the management interface.

param: string $name

i_should_see_category_as_subcategory_of_in_the_management_interface($subcatidnumber, $catidnumber)   X-Ref
Checks that a category is a subcategory of specific category.

param: string $subcatidnumber
param: string $catidnumber

i_should_not_see_category_as_subcategory_of_in_the_management_interface($subcatidnumber, $catidnumber)   X-Ref
Checks that a category is not a subcategory of specific category.

param: string $subcatidnumber
param: string $catidnumber

i_click_to_expand_category_in_the_management_interface($idnumber)   X-Ref
Click to expand a category revealing its sub categories within the management UI.

param: string $idnumber

category_in_management_listing_should_be_visible($idnumber)   X-Ref
Checks that a category within the management interface is visible.

param: string $idnumber

category_in_management_listing_should_be_dimmed($idnumber)   X-Ref
Checks that a category within the management interface is dimmed.

param: string $idnumber

course_in_management_listing_should_be_visible($idnumber)   X-Ref
Checks that a course within the management interface is visible.

param: string $idnumber

course_in_management_listing_should_be_dimmed($idnumber)   X-Ref
Checks that a course within the management interface is dimmed.

param: string $idnumber

i_toggle_visibility_of_course_in_management_listing($idnumber)   X-Ref
Toggles the visibility of a course in the management UI.

If it was visible it will be hidden. If it is hidden it will be made visible.

param: string $idnumber

i_toggle_visibility_of_category_in_management_listing($idnumber)   X-Ref
Toggles the visibility of a category in the management UI.

If it was visible it will be hidden. If it is hidden it will be made visible.


i_click_to_move_category_by_one($idnumber, $direction)   X-Ref
Moves a category displayed in the management interface up or down one place.

param: string $idnumber The category idnumber
param: string $direction The direction to move in, either up or down

i_click_to_move_course_by_one($idnumber, $direction)   X-Ref
Moves a course displayed in the management interface up or down one place.

param: string $idnumber The course idnumber
param: string $direction The direction to move in, either up or down

user_moves_listing_by_one($listingtype, $listingnode, $direction, $highlight = true)   X-Ref
Moves a course or category listing within the management interface up or down by one.

param: string $listingtype One of course or category
param: \Behat\Mink\Element\NodeElement $listingnode
param: string $direction One of up or down.
param: bool $highlight If set to false we don't check the node has been highlighted.

listing_is_highlighted($self, $selector)   X-Ref
Used by spin to determine the callback has been highlighted.

param: behat_course $self A self reference (default first arg from a spin callback)
param: \Behat\Mink\Element\NodeElement $selector
return: bool

i_should_see_course_listing_before($preceedingcourse, $followingcourse)   X-Ref
Check that one course appears before another in the course category management listings.

param: string $preceedingcourse The first course to find
param: string $followingcourse The second course to find (should be AFTER the first course)

i_should_see_category_listing_before($preceedingcategory, $followingcategory)   X-Ref
Check that one category appears before another in the course category management listings.

param: string $preceedingcategory The first category to find
param: string $followingcategory The second category to find (should be after the first category)

i_should_see_the_courses_management_page($mode)   X-Ref
Checks that we are on the course management page that we expect to be on and that no course has been selected.

param: string $mode The mode to expected. One of 'Courses', 'Course categories' or 'Course categories and courses'

i_should_see_the_courses_management_page_with_a_course_selected($mode)   X-Ref
Checks that we are on the course management page that we expect to be on and that a course has been selected.

param: string $mode The mode to expected. One of 'Courses', 'Course categories' or 'Course categories and courses'

i_click_on_action_for_item_in_management_course_listing($action, $name)   X-Ref
Locates a course in the course category management interface and then triggers an action for it.

param: string $action The action to take. One of
param: string $name The name of the course as it is displayed in the management interface.

i_click_on_action_for_item_in_management_category_listing($action, $name)   X-Ref
Locates a category in the course category management interface and then triggers an action for it.

param: string $action The action to take. One of
param: string $name The name of the category as it is displayed in the management interface.

i_toggle_category_children_visibility_in_frontpage($categoryname)   X-Ref
Clicks to expand or collapse a category displayed on the frontpage

param: string $categoryname

user_clicks_on_management_listing_action($listingtype, $listingnode, $action)   X-Ref
Finds the node to use for a management listitem action and clicks it.

param: string $listingtype Either course or category.
param: \Behat\Mink\Element\NodeElement $listingnode
param: string $action The action being taken

i_click_on_category_in_the_management_category_listing($name)   X-Ref
Clicks on a category in the management interface.

param: string $name The name of the category to click.

i_open_the_action_menu_for_item_in_management_category_listing($name)   X-Ref
Locates a category in the course category management interface and then opens action menu for it.

param: string $name The name of the category as it is displayed in the management interface.

category_actions_menu_should_have_item($name, $menuitem)   X-Ref
Checks that the specified category actions menu contains an item.

param: string $name
param: string $menuitem

category_actions_menu_should_not_have_item($name, $menuitem)   X-Ref
Checks that the specified category actions menu does not contain an item.

param: string $name
param: string $menuitem

i_navigate_to_course_participants()   X-Ref
Go to the course participants


i_should_see_teacher_before($pteacher, $fteacher)   X-Ref
Check that one teacher appears before another in the course contacts.

param: string $pteacher The first teacher to find
param: string $fteacher The second teacher to find (should be after the first teacher)

i_should_not_see_teacher_after($fteacher, $pteacher)   X-Ref
Check that one teacher oes not appears after another in the course contacts.

param: string $fteacher The teacher that should not be found (after the other teacher)
param: string $pteacher The teacher after who the other should not be found (this teacher must be found!)

i_open_the_activity_chooser()   X-Ref
Open the activity chooser in a course.


activity_date_in_activity_should_contain_text(string $activityname, string $text)   X-Ref
Checks the presence of the given text in the activity's displayed dates.

param: string $activityname The activity name.
param: string $text The text to be searched in the activity date.

activity_dates_information_in_activity_should_exist(string $activityname)   X-Ref
Checks the presence of activity dates information in the activity information output component.

param: string $activityname The activity name.

activity_dates_information_in_activity_should_not_exist(string $activityname)   X-Ref
Checks the absence of activity dates information in the activity information output component.

param: string $activityname The activity name.