13 changed files with 126 additions and 15 deletions
@ -1,5 +1,6 @@ |
|||||||
<?php namespace Tests\Aauth\Libraries\Aauth; |
<?php namespace Tests\Aauth\Libraries\Aauth; |
||||||
|
|
||||||
|
use Config\Aauth as AauthConfig; |
||||||
use Config\Logger; |
use Config\Logger; |
||||||
use Config\Services; |
use Config\Services; |
||||||
use Tests\Support\Log\TestLogger; |
use Tests\Support\Log\TestLogger; |
||||||
@ -7,6 +8,8 @@ use Tests\Support\Session\MockSession; |
|||||||
use CodeIgniter\Session\Handlers\FileHandler; |
use CodeIgniter\Session\Handlers\FileHandler; |
||||||
use CodeIgniter\Test\CIDatabaseTestCase; |
use CodeIgniter\Test\CIDatabaseTestCase; |
||||||
use App\Libraries\Aauth; |
use App\Libraries\Aauth; |
||||||
|
use App\Models\Aauth\UserVariableModel; |
||||||
|
use App\Models\Aauth\LoginTokenModel; |
||||||
|
|
||||||
/** |
/** |
||||||
* @runTestsInSeparateProcesses |
* @runTestsInSeparateProcesses |
||||||
@ -64,18 +67,126 @@ class LoginTest extends CIDatabaseTestCase |
|||||||
public function testLoginEmailTrue() |
public function testLoginEmailTrue() |
||||||
{ |
{ |
||||||
$session = $this->getInstance(); |
$session = $this->getInstance(); |
||||||
$this->library = new Aauth(NULL, $session); |
$this->library = new Aauth(null, $session); |
||||||
$this->assertTrue($this->library->login('[email protected]', 'password123456')); |
$this->assertTrue($this->library->login('[email protected]', 'password123456')); |
||||||
print_r($_SESSION); |
} |
||||||
|
|
||||||
|
public function testLoginFalseEmailFailedEmail() |
||||||
|
{ |
||||||
|
$session = $this->getInstance(); |
||||||
|
$this->library = new Aauth(null, $session); |
||||||
|
$this->assertFalse($this->library->login('adminaexample.com', 'password123456')); |
||||||
|
$this->assertEquals(lang('Aauth.loginFailedEmail'), $this->library->getErrorsArray()[0]); |
||||||
|
} |
||||||
|
|
||||||
|
public function testLoginFalseEmailFailedPassword() |
||||||
|
{ |
||||||
|
$session = $this->getInstance(); |
||||||
|
$this->library = new Aauth(null, $session); |
||||||
|
$this->assertFalse($this->library->login('[email protected]', 'password')); |
||||||
|
$this->assertEquals(lang('Aauth.loginFailedEmail'), $this->library->getErrorsArray()[0]); |
||||||
|
} |
||||||
|
|
||||||
|
public function testLoginFalseEmailNotFound() |
||||||
|
{ |
||||||
|
$session = $this->getInstance(); |
||||||
|
$this->library = new Aauth(null, $session); |
||||||
|
$this->assertFalse($this->library->login('[email protected]', 'password123456')); |
||||||
|
$this->assertEquals(lang('Aauth.notFoundUser'), $this->library->getErrorsArray()[0]); |
||||||
|
} |
||||||
|
|
||||||
|
public function testLoginUsernameTrue() |
||||||
|
{ |
||||||
|
$session = $this->getInstance(); |
||||||
|
$config = new AauthConfig(); |
||||||
|
$config->loginUseUsername = true; |
||||||
|
$this->library = new Aauth($config, $session); |
||||||
|
$this->assertTrue($this->library->login('admin', 'password123456')); |
||||||
|
} |
||||||
|
|
||||||
|
public function testLoginFalseUsernameFailedPassword() |
||||||
|
{ |
||||||
|
$session = $this->getInstance(); |
||||||
|
$config = new AauthConfig(); |
||||||
|
$config->loginUseUsername = true; |
||||||
|
$this->library = new Aauth($config, $session); |
||||||
|
$this->assertFalse($this->library->login('admin', 'password')); |
||||||
|
$this->assertEquals(lang('Aauth.loginFailedUsername'), $this->library->getErrorsArray()[0]); |
||||||
|
} |
||||||
|
|
||||||
|
public function testLoginFalseUsernameNotFound() |
||||||
|
{ |
||||||
|
$session = $this->getInstance(); |
||||||
|
$config = new AauthConfig(); |
||||||
|
$config->loginUseUsername = true; |
||||||
|
$this->library = new Aauth($config, $session); |
||||||
|
$this->assertFalse($this->library->login('admina', 'password')); |
||||||
|
$this->assertEquals(lang('Aauth.notFoundUser'), $this->library->getErrorsArray()[0]); |
||||||
|
} |
||||||
|
|
||||||
|
public function testLoginFalseNotVerified() |
||||||
|
{ |
||||||
|
$userVariableModel = new UserVariableModel(); |
||||||
|
$session = $this->getInstance(); |
||||||
|
$this->library = new Aauth(null, $session); |
||||||
|
$userVariableModel->save(1, 'verification_code', '12345678', true); |
||||||
|
$this->assertFalse($this->library->login('[email protected]', 'password123456')); |
||||||
|
$this->assertEquals(lang('Aauth.notVerified'), $this->library->getErrorsArray()[0]); |
||||||
|
} |
||||||
|
|
||||||
|
public function testLoginFalseBanned() |
||||||
|
{ |
||||||
|
$session = $this->getInstance(); |
||||||
|
$this->library = new Aauth(null, $session); |
||||||
|
$this->library->banUser(1); |
||||||
|
$this->assertFalse($this->library->login('[email protected]', 'password123456')); |
||||||
|
$this->assertEquals(lang('Aauth.invalidUserBanned'), $this->library->getErrorsArray()[0]); |
||||||
|
} |
||||||
|
|
||||||
|
public function testLoginFalse() |
||||||
|
{ |
||||||
|
$session = $this->getInstance(); |
||||||
|
$this->library = new Aauth(null, $session); |
||||||
|
$this->assertFalse($this->library->login('[email protected]', 'password1234567')); |
||||||
|
$this->assertEquals(lang('Aauth.loginFailedAll'), $this->library->getErrorsArray()[0]); |
||||||
|
} |
||||||
|
|
||||||
|
public function testLoginFalseLoginAttemptsExceeded() |
||||||
|
{ |
||||||
|
$session = $this->getInstance(); |
||||||
|
$this->library = new Aauth(null, $session); |
||||||
|
$this->library->login('[email protected]', 'password123456'); |
||||||
|
$this->library->login('[email protected]', 'password123456'); |
||||||
|
$this->library->login('[email protected]', 'password123456'); |
||||||
|
$this->library->login('[email protected]', 'password123456'); |
||||||
|
$this->library->login('[email protected]', 'password123456'); |
||||||
|
$this->library->login('[email protected]', 'password123456'); |
||||||
|
$this->library->login('[email protected]', 'password123456'); |
||||||
|
$this->library->login('[email protected]', 'password123456'); |
||||||
|
$this->library->login('[email protected]', 'password123456'); |
||||||
|
$this->assertFalse($this->library->login('[email protected]', 'password123456')); |
||||||
|
$this->assertEquals(lang('Aauth.loginAttemptsExceeded'), $this->library->getErrorsArray()[0]); |
||||||
} |
} |
||||||
|
|
||||||
public function testIsLoggedIn() |
public function testIsLoggedIn() |
||||||
{ |
{ |
||||||
$session = $this->getInstance(); |
$session = $this->getInstance(); |
||||||
$this->library = new Aauth(NULL, $session); |
$this->library = new Aauth(null, $session); |
||||||
|
$session->set('user', [ |
||||||
|
'loggedIn' => true, |
||||||
|
]); |
||||||
|
$this->assertTrue($this->library->isLoggedIn()); |
||||||
|
} |
||||||
|
|
||||||
|
public function testLogout() |
||||||
|
{ |
||||||
|
$session = $this->getInstance(); |
||||||
|
$this->library = new Aauth(null, $session); |
||||||
$session->set('user', [ |
$session->set('user', [ |
||||||
'loggedIn' => true, |
'loggedIn' => true, |
||||||
]); |
]); |
||||||
$this->assertTrue($this->library->isLoggedIn()); |
$this->assertTrue($this->library->isLoggedIn()); |
||||||
|
$this->library->logout(); |
||||||
|
$this->assertFalse($this->library->isLoggedIn()); |
||||||
} |
} |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue