MDL-72173 behat: Automatically log user out on behat login

This commit is contained in:
Andrew Nicols 2021-07-19 09:43:16 +08:00
parent 93cb87cddb
commit 41ebf95bbe
2 changed files with 10 additions and 0 deletions

View File

@ -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')]);

View File

@ -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;