diff --git a/lib/behat/behat_base.php b/lib/behat/behat_base.php index c0d84412de8..490bf5401a1 100644 --- a/lib/behat/behat_base.php +++ b/lib/behat/behat_base.php @@ -1222,4 +1222,22 @@ EOF; $session->executeScript($script); } + + /** + * Get the session key for the current session via Javascript. + * + * @return string + */ + public function get_sesskey(): string { + $script = <<evaluate_script($script); + } } diff --git a/lib/tests/behat/behat_navigation.php b/lib/tests/behat/behat_navigation.php index 86b17ac4862..0ec0d98294f 100644 --- a/lib/tests/behat/behat_navigation.php +++ b/lib/tests/behat/behat_navigation.php @@ -780,7 +780,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(?:[^"]|\\")*)" course homepage with editing mode on$/ * @throws coding_exception @@ -789,9 +789,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) {