Skip to content

Commit

Permalink
MDL-72173 behat: Respect login page preference
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Sep 16, 2021
1 parent 6b7f929 commit 89fe559
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions auth/tests/behat/login.php
Expand Up @@ -26,21 +26,22 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require(__DIR__.'/../../../config.php');
require_once("{$CFG->dirroot}/login/lib.php");

$behatrunning = defined('BEHAT_SITE_RUNNING') && BEHAT_SITE_RUNNING;
if (!$behatrunning) {
redirect(new moodle_url('/'));
}

$username = required_param('username', PARAM_ALPHANUMEXT);
$wantsurl = new moodle_url(optional_param('wantsurl', '/', PARAM_URL));
$wantsurl = optional_param('wantsurl', null, 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),
'wantsurl' => (new moodle_url($wantsurl))->out(false),
]));
}

Expand Down Expand Up @@ -82,4 +83,7 @@
throw new Exception("Failed to login as behat step for $username");
}

redirect($wantsurl);
if (empty($wantsurl)) {
$wantsurl = core_login_get_return_url();
}
redirect(new moodle_url($wantsurl));

0 comments on commit 89fe559

Please sign in to comment.