From 9ab20032175bedcdc95c8ed2e22ea6138ddc2f69 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Mon, 16 Dec 2019 16:40:52 +0800 Subject: [PATCH] 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. --- lib/behat/behat_base.php | 18 ++++++++++++++++++ lib/tests/behat/behat_navigation.php | 15 ++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) 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) {