Skip to content

Commit

Permalink
MDL-72090 navigation: Update to existing behat steps.
Browse files Browse the repository at this point in the history
This creates new general behat steps for navigating in theme
boost and classic.
  • Loading branch information
abgreeve committed Dec 9, 2021
1 parent 89d749f commit 8a5e36f
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 32 deletions.
32 changes: 6 additions & 26 deletions backup/util/ui/tests/behat/behat_backup.php
Expand Up @@ -55,15 +55,8 @@ public function i_backup_course_using_this_options($backupcourse, $options = fal
// We can not use other steps here as we don't know where the provided data
// table elements are used, and we need to catch exceptions contantly.

// Go to homepage.
$this->execute('behat_general::i_visit', ['/?redirect=0']);
$this->execute("behat_general::wait_until_the_page_is_ready");

// Click the course link.
$this->execute("behat_general::click_link", $backupcourse);

// Click the backup link.
$this->execute("behat_navigation::i_navigate_to_in_current_page_administration", get_string('backup'));
// Navigate to the course backup page.
$this->execute("behat_navigation::i_am_on_page_instance", [$backupcourse, 'backup']);

// Initial settings.
$this->fill_backup_restore_form($this->get_step_options($options, "Initial"));
Expand Down Expand Up @@ -97,14 +90,8 @@ public function i_perform_a_quick_backup_of_course($backupcourse) {
// We can not use other steps here as we don't know where the provided data
// table elements are used, and we need to catch exceptions contantly.

// Go to homepage.
$this->execute('behat_general::i_visit', ['/?redirect=0']);

// Click the course link.
$this->execute("behat_general::click_link", $backupcourse);

// Click the backup link.
$this->execute("behat_navigation::i_navigate_to_in_current_page_administration", get_string('backup'));
// Navigate to the course backup page.
$this->execute("behat_navigation::i_am_on_page_instance", [$backupcourse, 'backup']);

// Initial settings.
$this->execute("behat_forms::press_button", get_string('jumptofinalstep', 'backup'));
Expand Down Expand Up @@ -133,15 +120,8 @@ public function i_import_course_into_course($fromcourse, $tocourse, $options = f
// We can not use other steps here as we don't know where the provided data
// table elements are used, and we need to catch exceptions contantly.

// Go to homepage.
$this->execute('behat_general::i_visit', ['/?redirect=0']);
$this->execute("behat_general::wait_until_the_page_is_ready");

// Click the course link.
$this->execute("behat_general::click_link", $tocourse);

// Click the import link.
$this->execute("behat_navigation::i_navigate_to_in_current_page_administration", get_string('import'));
// Navigate to the course import page.
$this->execute("behat_navigation::i_am_on_page_instance", [$tocourse, 'import']);

// Select the course.
$fromcourse = behat_context_helper::escape($fromcourse);
Expand Down
43 changes: 39 additions & 4 deletions enrol/tests/behat/behat_enrol.php
Expand Up @@ -74,6 +74,37 @@ public function i_add_enrolment_method_with($enrolmethod, TableNode $table) {

}

/**
* Add the specified enrolment method to the specified course filling the form with the provided data.
*
* @Given /^I add "(?P<enrolment_method_name_string>(?:[^"]|\\")*)" enrolment method in "(?P<course_identifier_string>(?:[^"]|\\")*)" with:$/
* @param string $enrolmethod The enrolment method being used
* @param string $courseidentifier The courseidentifier such as short name
* @param TableNode $table Enrolment details
*/
public function i_add_enrolment_method_for_with(string $enrolmethod, string $courseidentifier, TableNode $table): void {
$this->execute("behat_navigation::i_am_on_page_instance", [$courseidentifier, 'enrolment methods']);

// Select enrolment method.
$this->execute('behat_forms::i_select_from_the_singleselect',
array($this->escape($enrolmethod), get_string('addinstance', 'enrol'))
);

// Wait again, for page to reloaded.
$this->execute('behat_general::i_wait_to_be_redirected');

// Set form fields.
$this->execute("behat_forms::i_set_the_following_fields_to_these_values", $table);

// Ensure we get button in focus, before pressing button.
if ($this->running_javascript()) {
$this->execute('behat_general::i_press_named_key', ['', 'tab']);
}

// Save changes.
$this->execute("behat_forms::press_button", get_string('addinstance', 'enrol'));
}

/**
* Enrols the specified user in the current course without options.
*
Expand All @@ -87,10 +118,14 @@ public function i_add_enrolment_method_with($enrolmethod, TableNode $table) {
public function i_enrol_user_as($userfullname, $rolename) {

// Navigate to enrolment page.
$parentnodes = get_string('users', 'admin');
$this->execute("behat_navigation::i_navigate_to_in_current_page_administration",
array($parentnodes . ' > '. get_string('enrolledusers', 'enrol'))
);
try {
$parentnodes = get_string('users', 'admin');
$this->execute("behat_navigation::i_navigate_to_in_current_page_administration",
array($parentnodes . ' > '. get_string('enrolledusers', 'enrol'))
);
} catch (Exception $e) {
$this->execute("behat_general::i_click_on", [get_string('participants'), 'link']);
}

$this->execute("behat_forms::press_button", get_string('enrolusers', 'enrol'));

Expand Down
76 changes: 75 additions & 1 deletion lib/tests/behat/behat_navigation.php
Expand Up @@ -736,11 +736,20 @@ protected function resolve_core_page_url(string $name): moodle_url {
* 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 | course shortname | Main course home page |
* | 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 |
*
* Examples:
*
Expand Down Expand Up @@ -787,6 +796,71 @@ protected function resolve_core_page_instance_url(string $type, string $identifi
return new moodle_url('/course/modedit.php', [
'update' => $cm->id,
]);
case 'backup':
$courseid = $this->get_course_id($identifier);
if (!$courseid) {
throw new Exception('The specified course with shortname, fullname, or idnumber "' .
$identifier . '" does not exist');
}
return new moodle_url('/backup/backup.php', ['id' => $courseid]);
case 'import':
$courseid = $this->get_course_id($identifier);
if (!$courseid) {
throw new Exception('The specified course with shortname, fullname, or idnumber "' .
$identifier . '" does not exist');
}
return new moodle_url('/backup/import.php', ['id' => $courseid]);
case 'restore':
$courseid = $this->get_course_id($identifier);
if (!$courseid) {
throw new Exception('The specified course with shortname, fullname, or idnumber "' .
$identifier . '" does not exist');
}
$context = context_course::instance($courseid);
return new moodle_url('/backup/restorefile.php', ['contextid' => $context->id]);
case 'reset':
$courseid = $this->get_course_id($identifier);
if (!$courseid) {
throw new Exception('The specified course with shortname, fullname, or idnumber "' .
$identifier . '" does not exist');
}
return new moodle_url('/course/reset.php', ['id' => $courseid]);
case 'course copy':
$courseid = $this->get_course_id($identifier);
if (!$courseid) {
throw new Exception('The specified course with shortname, fullname, or idnumber "' .
$identifier . '" does not exist');
}
return new moodle_url('/backup/copy.php', ['id' => $courseid]);
case 'groups':
$courseid = $this->get_course_id($identifier);
if (!$courseid) {
throw new Exception('The specified course with shortname, fullname, or idnumber "' .
$identifier . '" does not exist');
}
return new moodle_url('/group/index.php', ['id' => $courseid]);
case 'permissions':
$courseid = $this->get_course_id($identifier);
if (!$courseid) {
throw new Exception('The specified course with shortname, fullname, or idnumber "' .
$identifier . '" does not exist');
}
$context = context_course::instance($courseid);
return new moodle_url('/admin/roles/permissions.php', ['contextid' => $context->id]);
case 'enrolment methods':
$courseid = $this->get_course_id($identifier);
if (!$courseid) {
throw new Exception('The specified course with shortname, fullname, or idnumber "' .
$identifier . '" does not exist');
}
return new moodle_url('/enrol/instances.php', ['id' => $courseid]);
case 'enrolled users':
$courseid = $this->get_course_id($identifier);
if (!$courseid) {
throw new Exception('The specified course with shortname, fullname, or idnumber "' .
$identifier . '" does not exist');
}
return new moodle_url('/user/index.php', ['id' => $courseid]);
}

$parts = explode(' ', $type);
Expand Down
7 changes: 6 additions & 1 deletion lib/tests/behat/behat_permissions.php
Expand Up @@ -81,7 +81,12 @@ public function i_override_the_system_permissions_of_role_with($rolename, $table
);

if (!$this->running_javascript()) {
$this->execute("behat_general::i_click_on_in_the", [get_string('go'), 'button', "div.advancedoverride", 'css_element']);
$xpath = "//div[@class='advancedoverride']/div/form/noscript";
$this->execute("behat_general::i_click_on_in_the", [
get_string('go'), 'button',
$this->escape($xpath),
'xpath_element']
);
}

$this->execute("behat_permissions::i_fill_the_capabilities_form_with_the_following_permissions", $table);
Expand Down

0 comments on commit 8a5e36f

Please sign in to comment.