|
|
@ -21,7 +21,7 @@ class UserTest extends CIDatabaseTestCase |
|
|
|
protected $namespace = 'App'; |
|
|
|
protected $namespace = 'App'; |
|
|
|
|
|
|
|
|
|
|
|
public function setUp() |
|
|
|
public function setUp() |
|
|
|
{ |
|
|
|
{ |
|
|
|
parent::setUp(); |
|
|
|
parent::setUp(); |
|
|
|
|
|
|
|
|
|
|
|
$this->library = new Aauth(null, true); |
|
|
|
$this->library = new Aauth(null, true); |
|
|
@ -30,12 +30,12 @@ class UserTest extends CIDatabaseTestCase |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function tearDown() |
|
|
|
public function tearDown() |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected function getInstance($options=[]) |
|
|
|
protected function getInstance($options=[]) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$defaults = [ |
|
|
|
$defaults = [ |
|
|
|
'sessionDriver' => 'CodeIgniter\Session\Handlers\FileHandler', |
|
|
|
'sessionDriver' => 'CodeIgniter\Session\Handlers\FileHandler', |
|
|
|
'sessionCookieName' => 'ci_session', |
|
|
|
'sessionCookieName' => 'ci_session', |
|
|
@ -61,29 +61,81 @@ class UserTest extends CIDatabaseTestCase |
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------- |
|
|
|
//-------------------------------------------------------------------- |
|
|
|
|
|
|
|
|
|
|
|
public function testUpdateUser() |
|
|
|
public function testUpdateUserTrue() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$userPre = $this->library->getUser(2); |
|
|
|
$this->seeInDatabase($this->config->dbTableUserVariables, [ |
|
|
|
|
|
|
|
'user_id' => 2, |
|
|
|
|
|
|
|
'email' => 'user@example.com', |
|
|
|
|
|
|
|
'username' => 'user', |
|
|
|
|
|
|
|
]); |
|
|
|
$this->library->updateUser(2, 'user1@example.com', 'password987654', 'user1'); |
|
|
|
$this->library->updateUser(2, 'user1@example.com', 'password987654', 'user1'); |
|
|
|
$user = $this->library->getUser(2); |
|
|
|
$this->seeInDatabase($this->config->dbTableUserVariables, [ |
|
|
|
$this->assertNotEquals($userPre['email'], $user['email']); |
|
|
|
'user_id' => 2, |
|
|
|
$this->assertNotEquals($userPre['username'], $user['username']); |
|
|
|
'email' => 'user1@example.com', |
|
|
|
$this->library->updateUser(2, null, null, 'user1'); |
|
|
|
'username' => 'user1', |
|
|
|
$userAfter = $this->library->getUser(2); |
|
|
|
]); |
|
|
|
$this->assertEquals($user['username'], $userAfter['username']); |
|
|
|
$this->assertEquals(lang('Aauth.infoUpdateSuccess'), $this->library->getInfosArray()[0]); |
|
|
|
$this->assertFalse($this->library->updateUser(2, 'asasdfasd')); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function testUpdateUserFalseEmailExists() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$this->assertFalse($this->library->updateUser(2, 'admin@example.com', null, null)); |
|
|
|
|
|
|
|
$this->assertEquals(lang('Aauth.existsAlreadyEmail'), $this->library->getErrorsArray()[0]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function testUpdateUserFalseEmailInvalid() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$this->assertFalse($this->library->updateUser(2, 'adminexample.com', null, null)); |
|
|
|
|
|
|
|
$this->assertEquals(lang('Aauth.invalidEmail'), $this->library->getErrorsArray()[0]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function testUpdateUserFalsePasswordMin() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$this->assertFalse($this->library->updateUser(2, null, 'pass', null)); |
|
|
|
|
|
|
|
$this->assertEquals(lang('Aauth.invalidPassword'), $this->library->getErrorsArray()[0]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function testUpdateUserFalsePasswordMax() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$this->assertFalse($this->library->updateUser(2, null, 'password12345678901011121314151617', null)); |
|
|
|
|
|
|
|
$this->assertEquals(lang('Aauth.invalidPassword'), $this->library->getErrorsArray()[0]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function testUpdateUserFalseUsernameExists() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$this->assertFalse($this->library->updateUser(2, null, null, 'admin')); |
|
|
|
|
|
|
|
$this->assertEquals(lang('Aauth.existsAlreadyUsername'), $this->library->getErrorsArray()[0]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function testUpdateUserFalseUsernameInvalid() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$this->assertFalse($this->library->updateUser(2, null, null, 'user+')); |
|
|
|
|
|
|
|
$this->assertEquals(lang('Aauth.invalidUsername'), $this->library->getErrorsArray()[0]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function testUpdateUserFalseEmpty() |
|
|
|
|
|
|
|
{ |
|
|
|
$this->assertFalse($this->library->updateUser(2)); |
|
|
|
$this->assertFalse($this->library->updateUser(2)); |
|
|
|
|
|
|
|
$this->assertCount(0, $this->library->getErrorsArray()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function testUpdateUserFalseUserNotFound() |
|
|
|
|
|
|
|
{ |
|
|
|
$this->assertFalse($this->library->updateUser(99)); |
|
|
|
$this->assertFalse($this->library->updateUser(99)); |
|
|
|
|
|
|
|
$this->assertEquals(lang('Aauth.notFoundUser'), $this->library->getErrorsArray()[0]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function testDeleteUser() |
|
|
|
public function testDeleteUser() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$users = $this->library->listUsers(); |
|
|
|
$this->seeNumRecords(2, $this->config->dbTableUsers); |
|
|
|
$this->assertCount(2, $users); |
|
|
|
|
|
|
|
$this->library->deleteUser(2); |
|
|
|
$this->library->deleteUser(2); |
|
|
|
$users = $this->library->listUsers(); |
|
|
|
$this->seeNumRecords(1, $this->config->dbTableUsers); |
|
|
|
$this->assertCount(1, $users); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function testDeleteUserFalseUserNotFound() |
|
|
|
|
|
|
|
{ |
|
|
|
$this->assertFalse($this->library->deleteUser(99)); |
|
|
|
$this->assertFalse($this->library->deleteUser(99)); |
|
|
|
|
|
|
|
$this->assertEquals(lang('Aauth.notFoundUser'), $this->library->getErrorsArray()[0]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function testListUsers() |
|
|
|
public function testListUsers() |
|
|
@ -92,22 +144,25 @@ class UserTest extends CIDatabaseTestCase |
|
|
|
$this->assertCount(2, $users); |
|
|
|
$this->assertCount(2, $users); |
|
|
|
$this->assertEquals('admin', $users[0]['username']); |
|
|
|
$this->assertEquals('admin', $users[0]['username']); |
|
|
|
$this->assertEquals('user', $users[1]['username']); |
|
|
|
$this->assertEquals('user', $users[1]['username']); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function testListUsersOrderBy() |
|
|
|
|
|
|
|
{ |
|
|
|
$usersOrderBy = $this->library->listUsers(0, 0, null, 'id DESC'); |
|
|
|
$usersOrderBy = $this->library->listUsers(0, 0, null, 'id DESC'); |
|
|
|
$this->assertEquals('user', $usersOrderBy[0]['username']); |
|
|
|
$this->assertEquals('user', $usersOrderBy[0]['username']); |
|
|
|
$this->assertEquals('admin', $usersOrderBy[1]['username']); |
|
|
|
$this->assertEquals('admin', $usersOrderBy[1]['username']); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function testGetUser() |
|
|
|
public function testGetUserByUserId() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$user = $this->library->getUser(1); |
|
|
|
$user = $this->library->getUser(1); |
|
|
|
$this->assertEquals('1', $user['id']); |
|
|
|
$this->assertEquals('1', $user['id']); |
|
|
|
$this->assertEquals('admin', $user['username']); |
|
|
|
$this->assertEquals('admin', $user['username']); |
|
|
|
$this->assertEquals('admin@example.com', $user['email']); |
|
|
|
$this->assertEquals('admin@example.com', $user['email']); |
|
|
|
$this->assertFalse($this->library->getUser(99)); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$userVar = $this->library->getUser(1, true); |
|
|
|
|
|
|
|
$this->assertInternalType('array', $userVar['variables']); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function testGetUserBySession() |
|
|
|
|
|
|
|
{ |
|
|
|
$session = $this->getInstance(); |
|
|
|
$session = $this->getInstance(); |
|
|
|
$this->library = new Aauth(NULL, $session); |
|
|
|
$this->library = new Aauth(NULL, $session); |
|
|
|
$session->set('user', [ |
|
|
|
$session->set('user', [ |
|
|
@ -117,11 +172,26 @@ class UserTest extends CIDatabaseTestCase |
|
|
|
$this->assertEquals('admin', $userIdNone['username']); |
|
|
|
$this->assertEquals('admin', $userIdNone['username']); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function testGetUserId() |
|
|
|
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() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$userIdEmail = $this->library->getUserId('admin@example.com'); |
|
|
|
$userIdEmail = $this->library->getUserId('admin@example.com'); |
|
|
|
$this->assertEquals('1', $userIdEmail); |
|
|
|
$this->assertEquals('1', $userIdEmail); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function testGetUserIdBySession() |
|
|
|
|
|
|
|
{ |
|
|
|
$session = $this->getInstance(); |
|
|
|
$session = $this->getInstance(); |
|
|
|
$this->library = new Aauth(NULL, $session); |
|
|
|
$this->library = new Aauth(NULL, $session); |
|
|
|
$session->set('user', [ |
|
|
|
$session->set('user', [ |
|
|
@ -129,30 +199,52 @@ class UserTest extends CIDatabaseTestCase |
|
|
|
]); |
|
|
|
]); |
|
|
|
$userIdNone = $this->library->getUserId(); |
|
|
|
$userIdNone = $this->library->getUserId(); |
|
|
|
$this->assertEquals('1', $userIdNone); |
|
|
|
$this->assertEquals('1', $userIdNone); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function testGetUserIdFalseUserNotFound() |
|
|
|
|
|
|
|
{ |
|
|
|
$this->assertFalse($this->library->getUserId('none@example.com')); |
|
|
|
$this->assertFalse($this->library->getUserId('none@example.com')); |
|
|
|
|
|
|
|
$this->assertEquals(lang('Aauth.notFoundUser'), $this->library->getErrorsArray()[0]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function testBanUser() |
|
|
|
public function testBanUser() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$this->assertFalse($this->library->isBanned(1)); |
|
|
|
$this->seeInDatabase($this->config->dbTableUsers, [ |
|
|
|
|
|
|
|
'id' => 1, |
|
|
|
|
|
|
|
'banned' => 0, |
|
|
|
|
|
|
|
]); |
|
|
|
$this->library->banUser(1); |
|
|
|
$this->library->banUser(1); |
|
|
|
$this->assertTrue($this->library->isBanned(1)); |
|
|
|
$this->seeInDatabase($this->config->dbTableUsers, [ |
|
|
|
|
|
|
|
'id' => 1, |
|
|
|
|
|
|
|
'banned' => 1, |
|
|
|
|
|
|
|
]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public function testBanUserFalseUserNotFound() |
|
|
|
|
|
|
|
{ |
|
|
|
$this->assertFalse($this->library->banUser(99)); |
|
|
|
$this->assertFalse($this->library->banUser(99)); |
|
|
|
$this->assertCount(1, $this->library->getErrorsArray()); |
|
|
|
$this->assertEquals(lang('Aauth.notFoundUser'), $this->library->getErrorsArray()[0]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function testUnbanUser() |
|
|
|
public function testUnbanUser() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$this->library->banUser(1); |
|
|
|
$this->library->banUser(1); |
|
|
|
$this->assertTrue($this->library->isBanned(1)); |
|
|
|
$this->seeInDatabase($this->config->dbTableUsers, [ |
|
|
|
|
|
|
|
'id' => 1, |
|
|
|
|
|
|
|
'banned' => 1, |
|
|
|
|
|
|
|
]); |
|
|
|
$this->library->unbanUser(1); |
|
|
|
$this->library->unbanUser(1); |
|
|
|
$this->assertFalse($this->library->isBanned(1)); |
|
|
|
$this->seeInDatabase($this->config->dbTableUsers, [ |
|
|
|
|
|
|
|
'id' => 1, |
|
|
|
|
|
|
|
'banned' => 0, |
|
|
|
|
|
|
|
]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public function testUnbanUserFalseUserNotFound() |
|
|
|
|
|
|
|
{ |
|
|
|
$this->assertFalse($this->library->unbanUser(99)); |
|
|
|
$this->assertFalse($this->library->unbanUser(99)); |
|
|
|
$this->assertCount(1, $this->library->getErrorsArray()); |
|
|
|
$this->assertEquals(lang('Aauth.notFoundUser'), $this->library->getErrorsArray()[0]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function testBanUnbanUserSession() |
|
|
|
public function testUnbanUserSession() |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
$session = $this->getInstance(); |
|
|
|
$session = $this->getInstance(); |
|
|
|
$this->library = new Aauth(NULL, $session); |
|
|
|
$this->library = new Aauth(NULL, $session); |
|
|
@ -160,14 +252,31 @@ class UserTest extends CIDatabaseTestCase |
|
|
|
'id' => 1, |
|
|
|
'id' => 1, |
|
|
|
]); |
|
|
|
]); |
|
|
|
$this->library->banUser(); |
|
|
|
$this->library->banUser(); |
|
|
|
$this->assertTrue($this->library->isBanned()); |
|
|
|
$this->seeInDatabase($this->config->dbTableUsers, [ |
|
|
|
|
|
|
|
'id' => 1, |
|
|
|
|
|
|
|
'banned' => 1, |
|
|
|
|
|
|
|
]); |
|
|
|
$this->library->unbanUser(); |
|
|
|
$this->library->unbanUser(); |
|
|
|
$this->assertFalse($this->library->isBanned()); |
|
|
|
$this->seeInDatabase($this->config->dbTableUsers, [ |
|
|
|
|
|
|
|
'id' => 1, |
|
|
|
|
|
|
|
'banned' => 0, |
|
|
|
|
|
|
|
]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function testIsBannedTrue() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$this->library->banUser(1); |
|
|
|
|
|
|
|
$this->assertTrue($this->library->isBanned(1)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function testIsBannedFalse() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$this->assertFalse($this->library->isBanned(1)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function testIsBanned() |
|
|
|
public function testIsBannedFalseUserNotFound() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$this->assertFalse($this->library->isBanned(99)); |
|
|
|
$this->assertFalse($this->library->isBanned(99)); |
|
|
|
$this->assertCount(1, $this->library->getErrorsArray()); |
|
|
|
$this->assertEquals(lang('Aauth.notFoundUser'), $this->library->getErrorsArray()[0]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|