4 changed files with 151 additions and 42 deletions
@ -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' => '[email protected]', |
||||||
|
'username' => 'user', |
||||||
|
]); |
||||||
$this->library->updateUser(2, '[email protected]', 'password987654', 'user1'); |
$this->library->updateUser(2, '[email protected]', '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' => '[email protected]', |
||||||
$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, '[email protected]', 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('[email protected]', $user['email']); |
$this->assertEquals('[email protected]', $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('[email protected]'); |
$userIdEmail = $this->library->getUserId('[email protected]'); |
||||||
$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('[email protected]')); |
$this->assertFalse($this->library->getUserId('[email protected]')); |
||||||
|
$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]); |
||||||
} |
} |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue