-
-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
27 additions
and
76 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
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
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
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
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
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 |
---|---|---|
|
@@ -54,7 +54,10 @@ public function testAttemptLoginValidationErrors() | |
$this->asserttrue(isset($_SESSION['_ci_validation_errors'])); | ||
} | ||
|
||
public function testAttemptLoginSuccess() | ||
/** | ||
* @dataProvider rememberMeProvider | ||
*/ | ||
public function testAttemptLoginSuccess(bool $remembering) | ||
{ | ||
// Create user | ||
$user = [ | ||
|
@@ -81,7 +84,7 @@ public function testAttemptLoginSuccess() | |
|
||
// Just make sure since it's a default | ||
$config = config('Auth'); | ||
$config->allowRemembering = false; | ||
$config->allowRemembering = $remembering; | ||
\CodeIgniter\Config\Factories::injectMock('Config', 'Auth', $config); | ||
|
||
$result = $this->withUri(site_url('login')) | ||
|
@@ -91,46 +94,14 @@ public function testAttemptLoginSuccess() | |
|
||
$this->assertTrue($result->isRedirect()); | ||
$this->assertSame(lang('Auth.loginSuccess'), $_SESSION['message']); | ||
$this->assertFalse($result->response()->hasCookie('remember')); | ||
$this->assertSame($remembering, $result->response()->hasCookie('remember')); | ||
} | ||
|
||
public function testAttemptLoginSuccessWithRememberMe() | ||
public function rememberMeProvider() | ||
{ | ||
// Create user | ||
$user = [ | ||
'username' => 'Joe Cool', | ||
'email' => '[email protected]', | ||
'password' => 'xaH96AhjglK', | ||
'active' => 1, | ||
return [ | ||
[true], | ||
[false], | ||
]; | ||
$this->createUser($user); | ||
|
||
// Set form input | ||
$data = [ | ||
'login' => $user['username'], | ||
'password' => $user['password'], | ||
'remember' => 'on', | ||
]; | ||
$globals = [ | ||
'request' => $data, | ||
'post' => $data, | ||
]; | ||
|
||
$request = service('request', null, false); | ||
$this->setPrivateProperty($request, 'globals', $globals); | ||
|
||
// Just make sure since it's a default | ||
$config = config('Auth'); | ||
$config->allowRemembering = true; | ||
\CodeIgniter\Config\Factories::injectMock('Config', 'Auth', $config); | ||
|
||
$result = $this->withUri(site_url('login')) | ||
->withRequest($request) | ||
->controller(AuthController::class) | ||
->execute('attemptLogin'); | ||
|
||
$this->assertTrue($result->isRedirect()); | ||
$this->assertSame(lang('Auth.loginSuccess'), $_SESSION['message']); | ||
$this->assertTrue($result->response()->hasCookie('remember')); | ||
} | ||
} |