-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from StudiUM/fix-unit-tests
Fix unit tests in auth_plugin_test.php
- Loading branch information
Showing
1 changed file
with
18 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
*/ | ||
|
@@ -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); | ||
|
@@ -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); | ||
|
@@ -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(); | ||
} | ||
|
@@ -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 { | ||
|
@@ -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() | ||
); | ||
} | ||
} | ||
|
||
} |