Skip to content

Commit

Permalink
Merge pull request #101 from StudiUM/fix-unit-tests
Browse files Browse the repository at this point in the history
Fix unit tests in auth_plugin_test.php
  • Loading branch information
dmitriim authored Dec 6, 2023
2 parents cd71596 + 87a5ef0 commit 9c9266a
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions tests/auth_plugin_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ class auth_plugin_test extends advanced_testcase {
*/
protected $user;

/**
* Path used for the redirection.
* @var string
*/
const REDIRECTION_PATH = "/redirection";

/**
* Initial set up.
*/
Expand Down Expand Up @@ -392,7 +398,7 @@ public function test_create_refuse_duplicate_username() {

self::getDataGenerator()->create_user($originaluser);

$duplicateuser = clone($originaluser);
$duplicateuser = clone ($originaluser);
$duplicateuser->email = '[email protected]';

$this->expectException(invalid_parameter_exception::class);
Expand Down Expand Up @@ -422,7 +428,7 @@ public function test_create_refuse_duplicate_email() {

self::getDataGenerator()->create_user($originaluser);

$duplicateuser = clone($originaluser);
$duplicateuser = clone ($originaluser);
$duplicateuser->username = 'duplicateuser';

$this->expectException(invalid_parameter_exception::class);
Expand Down Expand Up @@ -1039,10 +1045,12 @@ public function test_user_logout_userkey_when_required_return_not_set() {
* Test when try to logout, but user is not logged in.
*/
public function test_user_logout_userkey_when_user_is_not_logged_in() {
$_POST['return'] = 'http://google.com';
$_POST['return'] = self::REDIRECTION_PATH;

$this->expectException(moodle_exception::class);
$this->expectExceptionMessage('Unsupported redirect to http://google.com detected, execution terminated.');
$this->expectExceptionMessage(
sprintf("Unsupported redirect to %s detected, execution terminated.", self::REDIRECTION_PATH)
);

$this->auth->user_logout_userkey();
}
Expand All @@ -1053,7 +1061,7 @@ public function test_user_logout_userkey_when_user_is_not_logged_in() {
public function test_user_logout_userkey_when_user_logged_in_with_different_auth() {
global $USER;

$_POST['return'] = 'http://google.com';
$_POST['return'] = self::REDIRECTION_PATH;

$this->setUser($this->user);
try {
Expand Down Expand Up @@ -1088,14 +1096,16 @@ public function test_user_logout_userkey_logging_out() {

$this->setUser($this->user);
$USER->auth = 'userkey';
$_POST['return'] = 'http://google.com';
$_POST['return'] = self::REDIRECTION_PATH;

try {
$this->auth->user_logout_userkey();
} catch (moodle_exception $e) {
$this->assertFalse(isloggedin());
$this->assertEquals('Unsupported redirect to http://google.com detected, execution terminated.', $e->getMessage());
$this->assertEquals(
sprintf('Unsupported redirect to %s detected, execution terminated.', self::REDIRECTION_PATH),
$e->getMessage()
);
}
}

}

0 comments on commit 9c9266a

Please sign in to comment.