Skip to content

Commit 9c9266a

Browse files
authored
Merge pull request #101 from StudiUM/fix-unit-tests
Fix unit tests in auth_plugin_test.php
2 parents cd71596 + 87a5ef0 commit 9c9266a

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

tests/auth_plugin_test.php

+18-8
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ class auth_plugin_test extends advanced_testcase {
4545
*/
4646
protected $user;
4747

48+
/**
49+
* Path used for the redirection.
50+
* @var string
51+
*/
52+
const REDIRECTION_PATH = "/redirection";
53+
4854
/**
4955
* Initial set up.
5056
*/
@@ -392,7 +398,7 @@ public function test_create_refuse_duplicate_username() {
392398

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

395-
$duplicateuser = clone($originaluser);
401+
$duplicateuser = clone ($originaluser);
396402
$duplicateuser->email = '[email protected]';
397403

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

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

425-
$duplicateuser = clone($originaluser);
431+
$duplicateuser = clone ($originaluser);
426432
$duplicateuser->username = 'duplicateuser';
427433

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

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

10471055
$this->auth->user_logout_userkey();
10481056
}
@@ -1053,7 +1061,7 @@ public function test_user_logout_userkey_when_user_is_not_logged_in() {
10531061
public function test_user_logout_userkey_when_user_logged_in_with_different_auth() {
10541062
global $USER;
10551063

1056-
$_POST['return'] = 'http://google.com';
1064+
$_POST['return'] = self::REDIRECTION_PATH;
10571065

10581066
$this->setUser($this->user);
10591067
try {
@@ -1088,14 +1096,16 @@ public function test_user_logout_userkey_logging_out() {
10881096

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

10931101
try {
10941102
$this->auth->user_logout_userkey();
10951103
} catch (moodle_exception $e) {
10961104
$this->assertFalse(isloggedin());
1097-
$this->assertEquals('Unsupported redirect to http://google.com detected, execution terminated.', $e->getMessage());
1105+
$this->assertEquals(
1106+
sprintf('Unsupported redirect to %s detected, execution terminated.', self::REDIRECTION_PATH),
1107+
$e->getMessage()
1108+
);
10981109
}
10991110
}
1100-
11011111
}

0 commit comments

Comments
 (0)