diff --git a/application/Libraries/Aauth.php b/application/Libraries/Aauth.php
index 1d7bca9..908a1a7 100644
--- a/application/Libraries/Aauth.php
+++ b/application/Libraries/Aauth.php
@@ -418,9 +418,7 @@ class Aauth
if (! $userModel->existsById($userId))
{
- $this->error(lang('Aauth.notFoundUser'));
-
- return false;
+ return true;
}
return $userModel->isBanned($userId);
diff --git a/tests/Aauth/Database/GroupToGroupModelTest.php b/tests/Aauth/Database/GroupToGroupModelTest.php
index 1b5c84b..c5f4194 100644
--- a/tests/Aauth/Database/GroupToGroupModelTest.php
+++ b/tests/Aauth/Database/GroupToGroupModelTest.php
@@ -31,14 +31,11 @@ class GroupToGroupModelTest extends CIDatabaseTestCase
]);
}
- public function testExistsFalse()
+ public function testExists()
{
$groupToGroup = $this->model->exists(99, 99);
$this->assertFalse($groupToGroup);
- }
- public function testExistsTrue()
- {
$this->hasInDatabase($this->config->dbTableGroupToGroup, [
'group_id' => 99,
'subgroup_id' => 99,
diff --git a/tests/Aauth/Database/GroupToUserModelTest.php b/tests/Aauth/Database/GroupToUserModelTest.php
index 6677fd2..959d2f9 100644
--- a/tests/Aauth/Database/GroupToUserModelTest.php
+++ b/tests/Aauth/Database/GroupToUserModelTest.php
@@ -31,14 +31,11 @@ class GroupToUserModelTest extends CIDatabaseTestCase
]);
}
- public function testExistsFalse()
+ public function testExists()
{
$groupToUser = $this->model->exists(99, 99);
$this->assertFalse($groupToUser);
- }
- public function testExistsTrue()
- {
$this->hasInDatabase($this->config->dbTableGroupToUser, [
'group_id' => 99,
'user_id' => 99,
diff --git a/tests/Aauth/Database/LoginAttemptModelTest.php b/tests/Aauth/Database/LoginAttemptModelTest.php
index f483287..e930e88 100644
--- a/tests/Aauth/Database/LoginAttemptModelTest.php
+++ b/tests/Aauth/Database/LoginAttemptModelTest.php
@@ -26,26 +26,16 @@ class LoginAttemptModelTest extends CIDatabaseTestCase
$this->assertEquals(0, $loginAttempt);
}
- public function testSaveInsert()
+ public function testSave()
{
- $this->model->save();
+ $this->assertTrue($this->model->save());
$loginAttempt = $this->model->find();
$this->assertEquals(1, $loginAttempt);
- }
- public function testSaveUpdate()
- {
- $this->model->save();
$this->assertTrue($this->model->save());
$loginAttempt = $this->model->find();
$this->assertEquals(2, $loginAttempt);
- }
- public function testSaveUpdateFalse()
- {
- $this->model->save();
- $this->model->save();
- $this->model->save();
$this->model->save();
$this->model->save();
$this->model->save();
diff --git a/tests/Aauth/Database/PermToGroupModelTest.php b/tests/Aauth/Database/PermToGroupModelTest.php
index a589e22..7626826 100644
--- a/tests/Aauth/Database/PermToGroupModelTest.php
+++ b/tests/Aauth/Database/PermToGroupModelTest.php
@@ -30,14 +30,11 @@ class PermToGroupModelTest extends CIDatabaseTestCase
]);
}
- public function testExistsFalse()
+ public function testExists()
{
$permToGroup = $this->model->exists(99, 99);
$this->assertFalse($permToGroup);
- }
- public function testExistsTrue()
- {
$this->hasInDatabase($this->config->dbTablePermToGroup, [
'perm_id' => 99,
'group_id' => 99,
diff --git a/tests/Aauth/Database/PermToUserModelTest.php b/tests/Aauth/Database/PermToUserModelTest.php
index a7faeac..46e8a70 100644
--- a/tests/Aauth/Database/PermToUserModelTest.php
+++ b/tests/Aauth/Database/PermToUserModelTest.php
@@ -30,14 +30,11 @@ class PermToUserModelTest extends CIDatabaseTestCase
]);
}
- public function testExistsFalse()
+ public function testExists()
{
$permToUser = $this->model->exists(99, 99);
$this->assertFalse($permToUser);
- }
- public function testExistsTrue()
- {
$this->hasInDatabase($this->config->dbTablePermToUser, [
'perm_id' => 99,
'user_id' => 99,
diff --git a/tests/Aauth/Database/UserModelTest.php b/tests/Aauth/Database/UserModelTest.php
index fb5388b..c61c16f 100644
--- a/tests/Aauth/Database/UserModelTest.php
+++ b/tests/Aauth/Database/UserModelTest.php
@@ -40,45 +40,32 @@ class UserModelTest extends CIDatabaseTestCase
$this->assertTrue(strtotime("-5 seconds") < strtotime($user['last_activity']) && strtotime("+5 seconds") > strtotime($user['last_activity']));
}
- public function testUpdateBannedTrue()
+ public function testUpdateBanned()
{
+ $this->assertFalse($this->model->isBanned(1));
+
$this->model->updateBanned(1, TRUE);
$this->assertTrue($this->model->isBanned(1));
}
- public function testUpdateBannedFalse()
- {
- $this->model->updateBanned(1, FALSE);
- $this->assertFalse($this->model->isBanned(1));
- }
-
- public function testExistsByIdTrue()
+ public function testExistsById()
{
$this->assertTrue($this->model->existsById(1));
- }
- public function testExistsByIdFalse()
- {
$this->assertFalse($this->model->existsById(0));
}
- public function testExistsByEmailTrue()
+ public function testExistsByEmail()
{
$this->assertTrue($this->model->existsByEmail("admin@example.com"));
- }
- public function testExistsByEmailFalse()
- {
$this->assertFalse($this->model->existsByEmail(""));
}
- public function testExistsByUsernameTrue()
+ public function testExistsByUsername()
{
$this->assertTrue($this->model->existsByUsername("admin"));
- }
- public function testExistsByUsernameFalse()
- {
$this->assertFalse($this->model->existsByUsername(""));
}
@@ -88,10 +75,7 @@ class UserModelTest extends CIDatabaseTestCase
$this->model->update(1, ['id' => 1, 'password' => 'password123456']);
$userNew = $this->model->asArray()->find(1);
$this->assertTrue($userOld['password'] != $userNew['password'] && $userNew['password'] != 'password123456');
- }
- public function testHashPasswordNotSet()
- {
$userOld = $this->model->asArray()->find(1);
$this->model->update(1, ['id' => 1, 'username' => 'admin']);
$userNew = $this->model->asArray()->find(1);
diff --git a/tests/Aauth/Database/UserVariableModelTest.php b/tests/Aauth/Database/UserVariableModelTest.php
index a5d56dd..aa7b639 100644
--- a/tests/Aauth/Database/UserVariableModelTest.php
+++ b/tests/Aauth/Database/UserVariableModelTest.php
@@ -22,14 +22,11 @@ class UserVariableModelTest extends CIDatabaseTestCase
//--------------------------------------------------------------------
- public function testFindFalse()
+ public function testFind()
{
$userVariable = $this->model->find(99, 'test');
$this->assertFalse($userVariable);
- }
- public function testFindReturn()
- {
$this->hasInDatabase($this->config->dbTableUserVariables, [
'user_id' => 99,
'data_key' => 'test',
@@ -50,7 +47,7 @@ class UserVariableModelTest extends CIDatabaseTestCase
$this->assertCount(1, $userVariables);
}
- public function testSaveInsert()
+ public function testSave()
{
$this->model->save(99, 'test', 'TRUE');
$this->seeInDatabase($this->config->dbTableUserVariables, [
@@ -58,11 +55,7 @@ class UserVariableModelTest extends CIDatabaseTestCase
'data_key' => 'test',
'data_value' => 'TRUE',
]);
- }
- public function testSaveUpdate()
- {
- $this->model->save(99, 'test', 'TRUE');
$this->model->save(99, 'test', 'TRUE2');
$this->seeInDatabase($this->config->dbTableUserVariables, [
'user_id' => 99,
diff --git a/tests/Aauth/Libraries/Aauth/ErrorsTest.php b/tests/Aauth/Libraries/Aauth/ErrorsTest.php
index 1f93bcb..51b634f 100644
--- a/tests/Aauth/Libraries/Aauth/ErrorsTest.php
+++ b/tests/Aauth/Libraries/Aauth/ErrorsTest.php
@@ -68,19 +68,16 @@ class ErrorsTest extends \CIUnitTestCase
$this->assertEquals(['test message 1','test message 2'], $this->library->getErrorsArray());
}
- public function testPrintErrorsReturn()
+ public function testPrintErrors()
{
+
$this->library->error('test message 1');
$this->assertEquals('test message 1', $this->library->printErrors('
', true));
$this->library->error('test message 2');
$this->assertEquals('test message 1
test message 2', $this->library->printErrors('
', true));
- }
- public function testPrintErrorsEcho()
- {
- $this->library->error('test message 1');
$this->library->printErrors('
');
- $this->expectOutputString('test message 1');
+ $this->expectOutputString('test message 1
test message 2');
}
public function testClearErrors()
@@ -102,21 +99,14 @@ class ErrorsTest extends \CIUnitTestCase
$this->library->error('test message 1', true);
$session->start();
$this->assertEquals(['test message 1'], $session->getFlashdata('errors'));
- }
- public function testErrorsFlashKeep()
- {
- $session = $this->getInstance();
$this->library = new Aauth(NULL, $session);
- $this->assertNull($session->getFlashdata('errors'));
- $this->library->error('test message 1', true);
- $session->start();
- $this->library->keepErrors();
+ $this->library->error(['test message 1','test message 2'], true);
$session->start();
- $this->assertEquals(['test message 1'], $session->getFlashdata('errors'));
+ $this->assertEquals(['test message 1','test message 2'], $session->getFlashdata('errors'));
}
- public function testErrorsFlashKeepMerge()
+ public function testErrorsFlashKeep()
{
$session = $this->getInstance();
$this->library = new Aauth(NULL, $session);
@@ -129,14 +119,4 @@ class ErrorsTest extends \CIUnitTestCase
$session->start();
$this->assertEquals(['test message 1 Flash', 'test message 1 NonFlash'], $session->getFlashdata('errors'));
}
-
- public function testErrorsFlashArray()
- {
- $session = $this->getInstance();
- $this->library = new Aauth(NULL, $session);
- $this->assertNull($session->getFlashdata('errors'));
- $this->library->error(['test message 1','test message 2'], true);
- $session->start();
- $this->assertEquals(['test message 1','test message 2'], $session->getFlashdata('errors'));
- }
}
diff --git a/tests/Aauth/Libraries/Aauth/InfosTest.php b/tests/Aauth/Libraries/Aauth/InfosTest.php
index 434aa84..916eae0 100644
--- a/tests/Aauth/Libraries/Aauth/InfosTest.php
+++ b/tests/Aauth/Libraries/Aauth/InfosTest.php
@@ -68,19 +68,15 @@ class InfosTest extends \CIUnitTestCase
$this->assertEquals(['test message 1','test message 2'], $this->library->getInfosArray());
}
- public function testPrintInfosReturn()
+ public function testPrintInfos()
{
$this->library->info('test message 1');
$this->assertEquals('test message 1', $this->library->printInfos('
', true));
$this->library->info('test message 2');
$this->assertEquals('test message 1
test message 2', $this->library->printInfos('
', true));
- }
- public function testPrintInfosEcho()
- {
- $this->library->info('test message 1');
$this->library->printInfos('
');
- $this->expectOutputString('test message 1');
+ $this->expectOutputString('test message 1
test message 2');
}
public function testClearInfos()
@@ -102,21 +98,14 @@ class InfosTest extends \CIUnitTestCase
$this->library->info('test message 1', true);
$session->start();
$this->assertEquals(['test message 1'], $session->getFlashdata('infos'));
- }
- public function testInfosFlashKeep()
- {
- $session = $this->getInstance();
- $this->library = new Aauth(NULL, $session);
- $this->assertNull($session->getFlashdata('infos'));
- $this->library->info('test message 1', true);
- $session->start();
- $this->library->keepInfos();
+ $this->library->clearInfos();
+ $this->library->info(['test message 1','test message 2'], true);
$session->start();
- $this->assertEquals(['test message 1'], $session->getFlashdata('infos'));
+ $this->assertEquals(['test message 1','test message 2'], $session->getFlashdata('infos'));
}
- public function testInfosFlashKeepMerge()
+ public function testInfosFlashKeep()
{
$session = $this->getInstance();
$this->library = new Aauth(NULL, $session);
@@ -129,14 +118,4 @@ class InfosTest extends \CIUnitTestCase
$session->start();
$this->assertEquals(['test message 1 Flash', 'test message 1 NonFlash'], $session->getFlashdata('infos'));
}
-
- public function testInfosFlashArray()
- {
- $session = $this->getInstance();
- $this->library = new Aauth(NULL, $session);
- $this->assertNull($session->getFlashdata('infos'));
- $this->library->info(['test message 1','test message 2'], true);
- $session->start();
- $this->assertEquals(['test message 1','test message 2'], $session->getFlashdata('infos'));
- }
}
diff --git a/tests/Aauth/Libraries/Aauth/LoginTest.php b/tests/Aauth/Libraries/Aauth/LoginTest.php
index 4f5c788..6f41f3d 100644
--- a/tests/Aauth/Libraries/Aauth/LoginTest.php
+++ b/tests/Aauth/Libraries/Aauth/LoginTest.php
@@ -25,25 +25,25 @@ class LoginTest extends CIDatabaseTestCase
protected $namespace = 'App';
- public function setUp()
- {
- parent::setUp();
+ public function setUp()
+ {
+ parent::setUp();
- Services::injectMock('response', new MockResponse(new App()));
- $this->response = service('response');
- $this->library = new Aauth(null, true);
- $_COOKIE = [];
- $_SESSION = [];
- }
+ Services::injectMock('response', new MockResponse(new App()));
+ $this->response = service('response');
+ $this->library = new Aauth(null, true);
+ $_COOKIE = [];
+ $_SESSION = [];
+ }
- public function tearDown()
- {
+ public function tearDown()
+ {
- }
+ }
- protected function getInstance($options=[])
- {
- $defaults = [
+ protected function getInstance($options=[])
+ {
+ $defaults = [
'sessionDriver' => 'CodeIgniter\Session\Handlers\FileHandler',
'sessionCookieName' => 'ci_session',
'sessionExpiration' => 7200,
@@ -55,145 +55,93 @@ class LoginTest extends CIDatabaseTestCase
'cookiePrefix' => '',
'cookiePath' => '/',
'cookieSecure' => false,
- ];
+ ];
- $config = (object)$defaults;
+ $config = (object)$defaults;
- $session = new MockSession(new FileHandler($config, Services::request()->getIPAddress()), $config);
- $session->setLogger(new TestLogger(new Logger()));
- $session->start();
+ $session = new MockSession(new FileHandler($config, Services::request()->getIPAddress()), $config);
+ $session->setLogger(new TestLogger(new Logger()));
+ $session->start();
- return $session;
- }
+ return $session;
+ }
//--------------------------------------------------------------------
- public function testLoginEmailTrue()
- {
- $session = $this->getInstance();
- $this->library = new Aauth(null, $session);
- $this->assertTrue($this->library->login('admin@example.com', 'password123456'));
- }
-
- 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('admin@example.com', 'passwor'));
- $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('admina@example.com', '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', 'passwor'));
- $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('user99', 'password123456'));
- $this->assertEquals(lang('Aauth.notFoundUser'), $this->library->getErrorsArray()[0]);
- $config->loginUseUsername = false;
- }
-
- public function testLoginFalseNotVerified()
- {
- $session = $this->getInstance();
- $this->library = new Aauth(null, $session);
- $userVariableModel = new UserVariableModel();
- $userVariableModel->save(1, 'verification_code', '12345678', true);
- $this->assertFalse($this->library->login('admin@example.com', '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('admin@example.com', '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('admin@example.com', '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('admina@example.com', 'password123456');
- $this->library->login('admina@example.com', 'password123456');
- $this->library->login('admina@example.com', 'password123456');
- $this->library->login('admina@example.com', 'password123456');
- $this->library->login('admina@example.com', 'password123456');
- $this->library->login('admina@example.com', 'password123456');
- $this->library->login('admina@example.com', 'password123456');
- $this->library->login('admina@example.com', 'password123456');
- $this->library->login('admina@example.com', 'password123456');
- $this->library->clearErrors();
- $this->assertFalse($this->library->login('admina@example.com', 'password123456'));
- $this->assertEquals(lang('Aauth.loginAttemptsExceeded'), $this->library->getErrorsArray()[0]);
- }
+ public function testLogin()
+ {
+ $session = $this->getInstance();
+ $config = new AauthConfig();
+ $config->loginUseUsername = true;
+
+ $this->library = new Aauth($config, $session);
+ $this->assertTrue($this->library->login('admin', 'password123456'));
+
+ $this->assertFalse($this->library->login('admin', 'passwor'));
+ $this->assertEquals(lang('Aauth.loginFailedUsername'), $this->library->getErrorsArray()[0]);
+
+ $this->library->clearErrors();
+ $this->assertFalse($this->library->login('user99', 'password123456'));
+ $this->assertEquals(lang('Aauth.notFoundUser'), $this->library->getErrorsArray()[0]);
+ // $config->loginUseUsername = false;
+
+ $this->library = new Aauth(null, $session);
+ $this->assertTrue($this->library->login('admin@example.com', 'password123456'));
+
+ $this->assertFalse($this->library->login('adminaexample.com', 'password123456'));
+ $this->assertEquals(lang('Aauth.loginFailedEmail'), $this->library->getErrorsArray()[0]);
+
+ $this->library->clearErrors();
+ $this->assertFalse($this->library->login('admin@example.com', 'passwor'));
+ $this->assertEquals(lang('Aauth.loginFailedEmail'), $this->library->getErrorsArray()[0]);
+
+ $this->library->clearErrors();
+ $this->assertFalse($this->library->login('admina@example.com', 'password123456'));
+ $this->assertEquals(lang('Aauth.notFoundUser'), $this->library->getErrorsArray()[0]);
+
+ $userVariableModel = new UserVariableModel();
+ $userVariableModel->save(1, 'verification_code', '12345678', true);
+ $this->assertFalse($this->library->login('admin@example.com', 'password123456'));
+ $this->assertEquals(lang('Aauth.notVerified'), $this->library->getErrorsArray()[0]);
+
+ $this->library->banUser(1);
+ $this->library->clearErrors();
+ $this->assertFalse($this->library->login('admin@example.com', 'password123456'));
+ $this->assertEquals(lang('Aauth.invalidUserBanned'), $this->library->getErrorsArray()[0]);
+
+
+ $this->library->clearErrors();
+ $this->assertFalse($this->library->login('admin@example.com', 'password1234567'));
+ $this->assertEquals(lang('Aauth.loginFailedAll'), $this->library->getErrorsArray()[0]);
+
+ $this->library->login('admina@example.com', 'password123456');
+ $this->library->login('admina@example.com', 'password123456');
+ $this->library->login('admina@example.com', 'password123456');
+ $this->library->clearErrors();
+ $this->assertFalse($this->library->login('admina@example.com', 'password123456'));
+ $this->assertEquals(lang('Aauth.loginAttemptsExceeded'), $this->library->getErrorsArray()[0]);
+ }
public function testIsLoggedIn()
{
- $session = $this->getInstance();
- $this->library = new Aauth(null, $session);
+ $session = $this->getInstance();
+ $this->library = new Aauth(null, $session);
$session->set('user', [
- 'loggedIn' => true,
- ]);
- $this->assertTrue($this->library->isLoggedIn());
+ 'loggedIn' => true,
+ ]);
+ $this->assertTrue($this->library->isLoggedIn());
}
public function testLogout()
{
- $session = $this->getInstance();
- $this->library = new Aauth(null, $session);
+ $session = $this->getInstance();
+ $this->library = new Aauth(null, $session);
$session->set('user', [
- 'loggedIn' => true,
- ]);
- $this->assertTrue($this->library->isLoggedIn());
- $this->library->logout();
- $this->library = new Aauth(null, $session);
- $this->assertFalse($this->library->isLoggedIn());
+ 'loggedIn' => true,
+ ]);
+ $this->assertTrue($this->library->isLoggedIn());
+ $this->library->logout();
+ $this->library = new Aauth(null, $session);
+ $this->assertFalse($this->library->isLoggedIn());
}
}
diff --git a/tests/Aauth/Libraries/Aauth/UserTest.php b/tests/Aauth/Libraries/Aauth/UserTest.php
index 6eee3e4..58d5e12 100644
--- a/tests/Aauth/Libraries/Aauth/UserTest.php
+++ b/tests/Aauth/Libraries/Aauth/UserTest.php
@@ -63,66 +63,50 @@ class UserTest extends CIDatabaseTestCase
//--------------------------------------------------------------------
- public function testUpdateUserTrue()
+ public function testUpdateUser()
{
$this->seeInDatabase($this->config->dbTableUserVariables, [
- 'user_id' => 2,
+ 'id' => 2,
'email' => 'user@example.com',
'username' => 'user',
]);
$this->library->updateUser(2, 'user1@example.com', 'password987654', 'user1');
$this->seeInDatabase($this->config->dbTableUserVariables, [
- 'user_id' => 2,
+ 'id' => 2,
'email' => 'user1@example.com',
'username' => 'user1',
]);
$this->assertEquals(lang('Aauth.infoUpdateSuccess'), $this->library->getInfosArray()[0]);
- }
- public function testUpdateUserFalseEmailExists()
- {
+ $this->library->clearInfos();
$this->assertFalse($this->library->updateUser(2, 'admin@example.com', null, null));
$this->assertEquals(lang('Aauth.existsAlreadyEmail'), $this->library->getErrorsArray()[0]);
- }
- public function testUpdateUserFalseEmailInvalid()
- {
+ $this->library->clearErrors();
$this->assertFalse($this->library->updateUser(2, 'adminexample.com', null, null));
$this->assertEquals(lang('Aauth.invalidEmail'), $this->library->getErrorsArray()[0]);
- }
- public function testUpdateUserFalsePasswordMin()
- {
+ $this->library->clearErrors();
$this->assertFalse($this->library->updateUser(2, null, 'pass', null));
$this->assertEquals(lang('Aauth.invalidPassword'), $this->library->getErrorsArray()[0]);
- }
- public function testUpdateUserFalsePasswordMax()
- {
+ $this->library->clearErrors();
$this->assertFalse($this->library->updateUser(2, null, 'password12345678901011121314151617', null));
$this->assertEquals(lang('Aauth.invalidPassword'), $this->library->getErrorsArray()[0]);
- }
- public function testUpdateUserFalseUsernameExists()
- {
+ $this->library->clearErrors();
$this->assertFalse($this->library->updateUser(2, null, null, 'admin'));
$this->assertEquals(lang('Aauth.existsAlreadyUsername'), $this->library->getErrorsArray()[0]);
- }
- public function testUpdateUserFalseUsernameInvalid()
- {
+ $this->library->clearErrors();
$this->assertFalse($this->library->updateUser(2, null, null, 'user+'));
$this->assertEquals(lang('Aauth.invalidUsername'), $this->library->getErrorsArray()[0]);
- }
- public function testUpdateUserFalseEmpty()
- {
+ $this->library->clearErrors();
$this->assertFalse($this->library->updateUser(2));
$this->assertCount(0, $this->library->getErrorsArray());
- }
- public function testUpdateUserFalseUserNotFound()
- {
+ $this->library->clearErrors();
$this->assertFalse($this->library->updateUser(99));
$this->assertEquals(lang('Aauth.notFoundUser'), $this->library->getErrorsArray()[0]);
}
@@ -132,10 +116,7 @@ class UserTest extends CIDatabaseTestCase
$this->seeNumRecords(2, $this->config->dbTableUsers);
$this->library->deleteUser(2);
$this->seeNumRecords(1, $this->config->dbTableUsers);
- }
- public function testDeleteUserFalseUserNotFound()
- {
$this->assertFalse($this->library->deleteUser(99));
$this->assertEquals(lang('Aauth.notFoundUser'), $this->library->getErrorsArray()[0]);
}
@@ -146,25 +127,19 @@ class UserTest extends CIDatabaseTestCase
$this->assertCount(2, $users);
$this->assertEquals('admin', $users[0]['username']);
$this->assertEquals('user', $users[1]['username']);
- }
- public function testListUsersOrderBy()
- {
$usersOrderBy = $this->library->listUsers(0, 0, null, 'id DESC');
$this->assertEquals('user', $usersOrderBy[0]['username']);
$this->assertEquals('admin', $usersOrderBy[1]['username']);
}
- public function testGetUserByUserId()
+ public function testGetUser()
{
$user = $this->library->getUser(1);
$this->assertEquals('1', $user['id']);
$this->assertEquals('admin', $user['username']);
$this->assertEquals('admin@example.com', $user['email']);
- }
- public function testGetUserBySession()
- {
$session = $this->getInstance();
$this->library = new Aauth(NULL, $session);
$session->set('user', [
@@ -172,28 +147,19 @@ class UserTest extends CIDatabaseTestCase
]);
$userIdNone = $this->library->getUser();
$this->assertEquals('admin', $userIdNone['username']);
- }
- public function testGetUserWithVariables()
- {
$userVar = $this->library->getUser(1, true);
$this->assertInternalType('array', $userVar['variables']);
- }
- public function testGetUserFalseUserNotFound()
- {
$this->assertFalse($this->library->getUser(99));
$this->assertEquals(lang('Aauth.notFoundUser'), $this->library->getErrorsArray()[0]);
}
- public function testGetUserIdByEmail()
+ public function testGetUserId()
{
$userIdEmail = $this->library->getUserId('admin@example.com');
$this->assertEquals('1', $userIdEmail);
- }
- public function testGetUserIdBySession()
- {
$session = $this->getInstance();
$this->library = new Aauth(NULL, $session);
$session->set('user', [
@@ -201,10 +167,7 @@ class UserTest extends CIDatabaseTestCase
]);
$userIdNone = $this->library->getUserId();
$this->assertEquals('1', $userIdNone);
- }
- public function testGetUserIdFalseUserNotFound()
- {
$this->assertFalse($this->library->getUserId('none@example.com'));
$this->assertEquals(lang('Aauth.notFoundUser'), $this->library->getErrorsArray()[0]);
}
@@ -220,9 +183,7 @@ class UserTest extends CIDatabaseTestCase
'id' => 1,
'banned' => 1,
]);
- }
- public function testBanUserFalseUserNotFound()
- {
+
$this->assertFalse($this->library->banUser(99));
$this->assertEquals(lang('Aauth.notFoundUser'), $this->library->getErrorsArray()[0]);
}
@@ -239,9 +200,7 @@ class UserTest extends CIDatabaseTestCase
'id' => 1,
'banned' => 0,
]);
- }
- public function testUnbanUserFalseUserNotFound()
- {
+
$this->assertFalse($this->library->unbanUser(99));
$this->assertEquals(lang('Aauth.notFoundUser'), $this->library->getErrorsArray()[0]);
}
@@ -265,20 +224,13 @@ class UserTest extends CIDatabaseTestCase
]);
}
- public function testIsBannedTrue()
+ public function testIsBanned()
{
$this->library->banUser(1);
$this->assertTrue($this->library->isBanned(1));
- }
- public function testIsBannedFalse()
- {
$this->assertFalse($this->library->isBanned(1));
- }
- public function testIsBannedFalseUserNotFound()
- {
- $this->assertFalse($this->library->isBanned(99));
- $this->assertEquals(lang('Aauth.notFoundUser'), $this->library->getErrorsArray()[0]);
+ $this->assertTrue($this->library->isBanned(99));
}
}