From b2842934029433ddebb679032080c7c90560bbaa Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Thu, 25 Jun 2020 14:39:38 +0800 Subject: [PATCH] MDL-69138 behat: Update session->visit() to use visit step --- auth/email/tests/behat/behat_auth_email.php | 2 +- auth/tests/behat/behat_auth.php | 2 +- backup/util/ui/tests/behat/behat_backup.php | 6 +++--- calendar/tests/behat/behat_calendar.php | 4 ++-- lib/tests/behat/behat_app.php | 2 +- lib/tests/behat/behat_general.php | 8 ++++---- lib/tests/behat/behat_hooks.php | 2 +- lib/tests/behat/behat_navigation.php | 16 +++++++--------- mod/forum/tests/behat/behat_mod_forum.php | 2 +- 9 files changed, 21 insertions(+), 23 deletions(-) diff --git a/auth/email/tests/behat/behat_auth_email.php b/auth/email/tests/behat/behat_auth_email.php index b3fe2fbbca1..83924f7029b 100644 --- a/auth/email/tests/behat/behat_auth_email.php +++ b/auth/email/tests/behat/behat_auth_email.php @@ -49,6 +49,6 @@ class behat_auth_email extends behat_base { $confirmationpath = $confirmationurl->out_as_local_url(false); $url = $confirmationpath . '?' . 'data='. $secret .'/'. $username; - $this->getSession()->visit($this->locate_path($url)); + $this->execute('behat_general::i_visit', [$url]); } } diff --git a/auth/tests/behat/behat_auth.php b/auth/tests/behat/behat_auth.php index e7b65e581ff..6233454f99f 100644 --- a/auth/tests/behat/behat_auth.php +++ b/auth/tests/behat/behat_auth.php @@ -58,7 +58,7 @@ class behat_auth extends behat_base { } // Visit login page. - $this->getSession()->visit($this->locate_path($loginurl->out_as_local_url())); + $this->execute('behat_general::i_visit', [$loginurl]); // Enter username and password. $this->execute('behat_forms::i_set_the_field_to', array('Username', $this->escape($username))); diff --git a/backup/util/ui/tests/behat/behat_backup.php b/backup/util/ui/tests/behat/behat_backup.php index a5ead378370..fe5f57544be 100644 --- a/backup/util/ui/tests/behat/behat_backup.php +++ b/backup/util/ui/tests/behat/behat_backup.php @@ -56,7 +56,7 @@ class behat_backup extends behat_base { // table elements are used, and we need to catch exceptions contantly. // Go to homepage. - $this->getSession()->visit($this->locate_path('/?redirect=0')); + $this->execute('behat_general::i_visit', ['/?redirect=0']); $this->execute("behat_general::wait_until_the_page_is_ready"); // Click the course link. @@ -98,7 +98,7 @@ class behat_backup extends behat_base { // table elements are used, and we need to catch exceptions contantly. // Go to homepage. - $this->getSession()->visit($this->locate_path('/?redirect=0')); + $this->execute('behat_general::i_visit', ['/?redirect=0']); // Click the course link. $this->execute("behat_general::click_link", $backupcourse); @@ -134,7 +134,7 @@ class behat_backup extends behat_base { // table elements are used, and we need to catch exceptions contantly. // Go to homepage. - $this->getSession()->visit($this->locate_path('/?redirect=0')); + $this->execute('behat_general::i_visit', ['/?redirect=0']); $this->execute("behat_general::wait_until_the_page_is_ready"); // Click the course link. diff --git a/calendar/tests/behat/behat_calendar.php b/calendar/tests/behat/behat_calendar.php index 1c6cb4ccb30..e089afc01a3 100644 --- a/calendar/tests/behat/behat_calendar.php +++ b/calendar/tests/behat/behat_calendar.php @@ -121,7 +121,7 @@ class behat_calendar extends behat_base { */ public function i_view_the_calendar_for($month, $year) { $time = make_timestamp($year, $month, 1); - $this->getSession()->visit($this->locate_path('/calendar/view.php?view=month&course=1&time='.$time)); + $this->execute('behat_general::i_visit', ['/calendar/view.php?view=month&course=1&time='.$time]); } @@ -134,6 +134,6 @@ class behat_calendar extends behat_base { */ public function i_am_viewing_site_calendar() { $url = new moodle_url('/calendar/view.php', ['view' => 'month']); - $this->getSession()->visit($this->locate_path($url->out_as_local_url(false))); + $this->execute('behat_general::i_visit', [$url]); } } diff --git a/lib/tests/behat/behat_app.php b/lib/tests/behat/behat_app.php index e474ffc6737..ce9f392c01d 100644 --- a/lib/tests/behat/behat_app.php +++ b/lib/tests/behat/behat_app.php @@ -283,7 +283,7 @@ class behat_app extends behat_base { global $CFG; // Visit the Ionic URL and wait for it to load. - $this->getSession()->visit($url); + $this->execute('behat_general::i_visit', [$url]); $this->spin( function($context, $args) { $title = $context->getSession()->getPage()->find('xpath', '//title'); diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php index e8976d756a2..49b2fdd63c0 100644 --- a/lib/tests/behat/behat_general.php +++ b/lib/tests/behat/behat_general.php @@ -74,7 +74,7 @@ class behat_general extends behat_base { * @Given /^I am on homepage$/ */ public function i_am_on_homepage() { - $this->getSession()->visit($this->locate_path('/')); + $this->execute('behat_general::i_visit', ['/']); } /** @@ -83,7 +83,7 @@ class behat_general extends behat_base { * @Given /^I am on site homepage$/ */ public function i_am_on_site_homepage() { - $this->getSession()->visit($this->locate_path('/?redirect=0')); + $this->execute('behat_general::i_visit', ['/?redirect=0']); } /** @@ -92,7 +92,7 @@ class behat_general extends behat_base { * @Given /^I am on course index$/ */ public function i_am_on_course_index() { - $this->getSession()->visit($this->locate_path('/course/index.php')); + $this->execute('behat_general::i_visit', ['/course/index.php']); } /** @@ -1057,7 +1057,7 @@ EOF; * @Given /^I trigger cron$/ */ public function i_trigger_cron() { - $this->getSession()->visit($this->locate_path('/admin/cron.php')); + $this->execute('behat_general::i_visit', ['/admin/cron.php']); } /** diff --git a/lib/tests/behat/behat_hooks.php b/lib/tests/behat/behat_hooks.php index ec007f1c3c2..1e8e1e88ab5 100644 --- a/lib/tests/behat/behat_hooks.php +++ b/lib/tests/behat/behat_hooks.php @@ -496,7 +496,7 @@ EOF; // Again, this would be better in the BeforeSuite hook, but that does not have access to the selectors in // order to perform the necessary searches. $session = $this->getSession(); - $session->visit($this->locate_path('/')); + $this->execute('behat_general::i_visit', ['/']); // Checking that the root path is a Moodle test site. if (self::is_first_scenario()) { diff --git a/lib/tests/behat/behat_navigation.php b/lib/tests/behat/behat_navigation.php index a2309e4edca..7acc898f3dc 100644 --- a/lib/tests/behat/behat_navigation.php +++ b/lib/tests/behat/behat_navigation.php @@ -526,7 +526,7 @@ class behat_navigation extends behat_base { } } - $this->getSession()->visit($this->locate_path($url->out_as_local_url())); + $this->execute('behat_general::i_visit', [$url]); } // Restore global user variable. @@ -549,8 +549,7 @@ class behat_navigation extends behat_base { * @throws Exception if the specified page cannot be determined. */ public function i_am_on_page(string $page) { - $this->getSession()->visit($this->locate_path( - $this->resolve_page_helper($page)->out_as_local_url())); + $this->execute('behat_general::i_visit', [$this->resolve_page_helper($page)]); } /** @@ -629,8 +628,7 @@ class behat_navigation extends behat_base { * @throws Exception if the specified page cannot be determined. */ public function i_am_on_page_instance(string $identifier, string $type) { - $this->getSession()->visit($this->locate_path( - $this->resolve_page_instance_helper($identifier, $type)->out_as_local_url())); + $this->execute('behat_general::i_visit', [$this->resolve_page_instance_helper($identifier, $type)]); } /** @@ -753,7 +751,7 @@ class behat_navigation extends behat_base { global $DB; $course = $DB->get_record("course", array("fullname" => $coursefullname), 'id', MUST_EXIST); $url = new moodle_url('/course/view.php', ['id' => $course->id]); - $this->getSession()->visit($this->locate_path($url->out_as_local_url(false))); + $this->execute('behat_general::i_visit', [$url]); } /** @@ -774,13 +772,13 @@ class behat_navigation extends behat_base { // 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))); + $this->execute('behat_general::i_visit', [$url]); return; } // Visit the course page. - $this->getSession()->visit($this->locate_path($url->out_as_local_url(false))); + $this->execute('behat_general::i_visit', [$url]); try { $this->execute("behat_forms::press_button", get_string('turneditingon')); @@ -1003,6 +1001,6 @@ class behat_navigation extends behat_base { if (!preg_match($fixtureregex, $url)) { throw new coding_exception("URL {$url} is not a fixture URL"); } - $this->getSession()->visit($this->locate_path($url)); + $this->execute('behat_general::i_visit', [$url]); } } diff --git a/mod/forum/tests/behat/behat_mod_forum.php b/mod/forum/tests/behat/behat_mod_forum.php index 58937ced844..454743e9751 100644 --- a/mod/forum/tests/behat/behat_mod_forum.php +++ b/mod/forum/tests/behat/behat_mod_forum.php @@ -529,6 +529,6 @@ class behat_mod_forum extends behat_base { global $DB; $post = $DB->get_record("forum_posts", array("subject" => $postsubject), 'id', MUST_EXIST); $url = new moodle_url('/mod/forum/post.php', ['reply' => $post->id]); - $this->getSession()->visit($this->locate_path($url->out_as_local_url(false))); + $this->execute('behat_general::i_visit', [$url]); } }