From 41ebf95bbe1381cfb83d723ccb3aa029da962d03 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Mon, 19 Jul 2021 09:43:16 +0800 Subject: [PATCH] MDL-72173 behat: Automatically log user out on behat login --- auth/tests/behat/behat_auth.php | 1 + auth/tests/behat/login.php | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/auth/tests/behat/behat_auth.php b/auth/tests/behat/behat_auth.php index e6fcadb71f4..08d75997f31 100644 --- a/auth/tests/behat/behat_auth.php +++ b/auth/tests/behat/behat_auth.php @@ -68,6 +68,7 @@ class behat_auth extends behat_base { * Logs out of the system. * * @Given /^I log out$/ + * @Given I am not logged in */ public function i_log_out() { $this->execute('behat_general::i_visit', [new moodle_url('/auth/tests/behat/logout.php')]); diff --git a/auth/tests/behat/login.php b/auth/tests/behat/login.php index d9d06b47d71..2f67eb1c98e 100644 --- a/auth/tests/behat/login.php +++ b/auth/tests/behat/login.php @@ -35,6 +35,15 @@ if (!$behatrunning) { $username = required_param('username', PARAM_ALPHANUMEXT); $wantsurl = new moodle_url(optional_param('wantsurl', '/', PARAM_URL)); +if (isloggedin()) { + // If the user is already logged in, log them out and redirect them back to login again. + require_logout(); + redirect(new moodle_url('/auth/tests/behat/login.php', [ + 'username' => $username, + 'wantsurl' => $wantsurl->out(false), + ])); +} + // Note - with behat, the password is always the same as the username. $password = $username;