mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
MDL-67657 behat: Open course with editing using URL
This is a huge performance improvement for behat. The current set of steps loads the page It then looks for the Classic/Clean version of the settings menu If it fails to find it looks for the Boost Cog Then it clicks the "Turn editing on" button This can take a substantial period. We do not actually need to run these steps as we are able to jump straight to the URL. We already have access to the sesskey value required to do this. There is not loss in testing functionality because the actual testing of the Turn editing functionality is tested in other places sufficiently.
This commit is contained in:
parent
cd6eadd407
commit
083604ea09
@ -1291,4 +1291,22 @@ EOF;
|
||||
|
||||
$session->executeScript($script);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the session key for the current session via Javascript.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_sesskey(): string {
|
||||
$script = <<<EOF
|
||||
return (function() {
|
||||
if (M && M.cfg && M.cfg.sesskey) {
|
||||
return M.cfg.sesskey;
|
||||
}
|
||||
return '';
|
||||
})()
|
||||
EOF;
|
||||
|
||||
return $this->evaluate_script($script);
|
||||
}
|
||||
}
|
||||
|
@ -757,7 +757,7 @@ class behat_navigation extends behat_base {
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the course homepage with editing mode on.
|
||||
* Open the course homepage with editing mode enabled.
|
||||
*
|
||||
* @Given /^I am on "(?P<coursefullname_string>(?:[^"]|\\")*)" course homepage with editing mode on$/
|
||||
* @throws coding_exception
|
||||
@ -766,9 +766,22 @@ class behat_navigation extends behat_base {
|
||||
*/
|
||||
public function i_am_on_course_homepage_with_editing_mode_on($coursefullname) {
|
||||
global $DB;
|
||||
|
||||
$course = $DB->get_record("course", array("fullname" => $coursefullname), 'id', MUST_EXIST);
|
||||
$url = new moodle_url('/course/view.php', ['id' => $course->id]);
|
||||
|
||||
if ($this->running_javascript() && $sesskey = $this->get_sesskey()) {
|
||||
// Javascript is running so it is possible to grab the session ket and jump straight to editing mode.
|
||||
$url->param('edit', 1);
|
||||
$url->param('sesskey', $sesskey);
|
||||
$this->getSession()->visit($this->locate_path($url->out_as_local_url(false)));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Visit the course page.
|
||||
$this->getSession()->visit($this->locate_path($url->out_as_local_url(false)));
|
||||
|
||||
try {
|
||||
$this->execute("behat_forms::press_button", get_string('turneditingon'));
|
||||
} catch (Exception $e) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user