Browse Source

updated tests

v3-dev
REJack 6 years ago
parent
commit
06f2d67633
No known key found for this signature in database
GPG Key ID: 4A44B48700429F46
  1. 4
      tests/Aauth/Database/GroupToGroupModelTest.php
  2. 4
      tests/Aauth/Database/GroupToUserModelTest.php
  3. 16
      tests/Aauth/Database/UserModelTest.php
  4. 12
      tests/Aauth/Libraries/Aauth/ErrorsTest.php
  5. 11
      tests/Aauth/Libraries/Aauth/InfosTest.php
  6. 1
      tests/Aauth/Libraries/Aauth/LoginTest.php
  7. 20
      tests/Aauth/Libraries/Aauth/UserTest.php

4
tests/Aauth/Database/GroupToGroupModelTest.php

@ -90,7 +90,7 @@ class GroupToGroupModelTest extends CIDatabaseTestCase
'subgroup_id' => 99,
]);
$criteria = [
'group_id' => 99
'group_id' => 99,
];
$this->seeNumRecords(1, $this->config->dbTableGroupToGroup, $criteria);
$this->model->deleteAllByGroupId(99);
@ -104,7 +104,7 @@ class GroupToGroupModelTest extends CIDatabaseTestCase
'subgroup_id' => 99,
]);
$criteria = [
'subgroup_id' => 99
'subgroup_id' => 99,
];
$this->seeNumRecords(1, $this->config->dbTableGroupToGroup, $criteria);
$this->model->deleteAllBySubgroupId(99);

4
tests/Aauth/Database/GroupToUserModelTest.php

@ -90,7 +90,7 @@ class GroupToUserModelTest extends CIDatabaseTestCase
'user_id' => 99,
]);
$criteria = [
'group_id' => 99
'group_id' => 99,
];
$this->seeNumRecords(1, $this->config->dbTableGroupToUser, $criteria);
$this->model->deleteAllByGroupId(99);
@ -104,7 +104,7 @@ class GroupToUserModelTest extends CIDatabaseTestCase
'user_id' => 99,
]);
$criteria = [
'user_id' => 99
'user_id' => 99,
];
$this->seeNumRecords(1, $this->config->dbTableGroupToUser, $criteria);
$this->model->deleteAllByUserId(99);

16
tests/Aauth/Database/UserModelTest.php

@ -31,21 +31,21 @@ class UserModelTest extends CIDatabaseTestCase
{
$this->model->updateLastLogin(1);
$user = $this->model->asArray()->find(1);
$this->assertTrue((strtotime("-5 seconds") < strtotime($user['last_login']) && strtotime("+5 seconds") > strtotime($user['last_login'])) && strtotime("-5 seconds") < strtotime($user['last_activity']) && strtotime("+5 seconds") > strtotime($user['last_activity']));
$this->assertTrue((strtotime('-5 seconds') < strtotime($user['last_login']) && strtotime('+5 seconds') > strtotime($user['last_login'])) && strtotime('-5 seconds') < strtotime($user['last_activity']) && strtotime('+5 seconds') > strtotime($user['last_activity']));
}
public function testUpdateLastActivity()
{
$this->model->updateLastActivity(1);
$user = $this->model->asArray()->find(1);
$this->assertTrue(strtotime("-5 seconds") < strtotime($user['last_activity']) && strtotime("+5 seconds") > strtotime($user['last_activity']));
$this->assertTrue(strtotime('-5 seconds') < strtotime($user['last_activity']) && strtotime('+5 seconds') > strtotime($user['last_activity']));
}
public function testUpdateBanned()
{
$this->assertFalse($this->model->isBanned(1));
$this->model->updateBanned(1, TRUE);
$this->model->updateBanned(1, true);
$this->assertTrue($this->model->isBanned(1));
}
@ -58,16 +58,16 @@ class UserModelTest extends CIDatabaseTestCase
public function testExistsByEmail()
{
$this->assertTrue($this->model->existsByEmail("[email protected]"));
$this->assertTrue($this->model->existsByEmail('[email protected]'));
$this->assertFalse($this->model->existsByEmail(""));
$this->assertFalse($this->model->existsByEmail(''));
}
public function testExistsByUsername()
{
$this->assertTrue($this->model->existsByUsername("admin"));
$this->assertTrue($this->model->existsByUsername('admin'));
$this->assertFalse($this->model->existsByUsername(""));
$this->assertFalse($this->model->existsByUsername(''));
}
public function testHashPasswordFilled()
@ -75,7 +75,7 @@ class UserModelTest extends CIDatabaseTestCase
$userOld = $this->model->asArray()->find(1);
$this->model->update(1, ['id' => 1, 'password' => 'password123456']);
$userNew = $this->model->asArray()->find(1);
$this->assertTrue($userOld['password'] != $userNew['password'] && $userNew['password'] != 'password123456');
$this->assertTrue($userOld['password'] !== $userNew['password'] && $userNew['password'] !== 'password123456');
$userOld = $this->model->asArray()->find(1);
$this->model->update(1, ['id' => 1, 'username' => 'admin']);

12
tests/Aauth/Libraries/Aauth/ErrorsTest.php

@ -24,7 +24,6 @@ class ErrorsTest extends \CIUnitTestCase
public function tearDown()
{
}
protected function getInstance($options = [])
@ -70,7 +69,6 @@ class ErrorsTest extends \CIUnitTestCase
public function testPrintErrors()
{
$this->library->error('test message 1');
$this->assertEquals('test message 1', $this->library->printErrors('<br />', true));
$this->library->error('test message 2');
@ -83,7 +81,7 @@ class ErrorsTest extends \CIUnitTestCase
public function testClearErrors()
{
$session = $this->getInstance();
$this->library = new Aauth(NULL, $session);
$this->library = new Aauth(null, $session);
$this->library->error('test message 1', true);
$this->assertEquals(['test message 1'], $session->getFlashdata('errors'));
$this->library->clearErrors();
@ -94,13 +92,13 @@ class ErrorsTest extends \CIUnitTestCase
public function testErrorsFlash()
{
$session = $this->getInstance();
$this->library = new Aauth(NULL, $session);
$this->library = new Aauth(null, $session);
$this->assertNull($session->getFlashdata('errors'));
$this->library->error('test message 1', true);
$session->start();
$this->assertEquals(['test message 1'], $session->getFlashdata('errors'));
$this->library = new Aauth(NULL, $session);
$this->library = new Aauth(null, $session);
$this->library->error(['test message 1', 'test message 2'], true);
$session->start();
$this->assertEquals(['test message 1', 'test message 2'], $session->getFlashdata('errors'));
@ -109,11 +107,11 @@ class ErrorsTest extends \CIUnitTestCase
public function testErrorsFlashKeep()
{
$session = $this->getInstance();
$this->library = new Aauth(NULL, $session);
$this->library = new Aauth(null, $session);
$this->assertNull($session->getFlashdata('errors'));
$this->library->error('test message 1 Flash', true);
$session->start();
$this->library = new Aauth(NULL, $session);
$this->library = new Aauth(null, $session);
$this->library->error('test message 1 NonFlash');
$this->library->keepErrors(true);
$session->start();

11
tests/Aauth/Libraries/Aauth/InfosTest.php

@ -24,7 +24,6 @@ class InfosTest extends \CIUnitTestCase
public function tearDown()
{
}
protected function getInstance($options = [])
@ -82,7 +81,7 @@ class InfosTest extends \CIUnitTestCase
public function testClearInfos()
{
$session = $this->getInstance();
$this->library = new Aauth(NULL, $session);
$this->library = new Aauth(null, $session);
$this->library->info('test message 1', true);
$this->assertEquals(['test message 1'], $session->getFlashdata('infos'));
$this->library->clearInfos();
@ -93,13 +92,13 @@ class InfosTest extends \CIUnitTestCase
public function testInfosFlash()
{
$session = $this->getInstance();
$this->library = new Aauth(NULL, $session);
$this->library = new Aauth(null, $session);
$this->assertNull($session->getFlashdata('infos'));
$this->library->info('test message 1', true);
$session->start();
$this->assertEquals(['test message 1'], $session->getFlashdata('infos'));
$this->library = new Aauth(NULL, $session);
$this->library = new Aauth(null, $session);
$this->library->info(['test message 1', 'test message 2'], true);
$session->start();
$this->assertEquals(['test message 1', 'test message 2'], $session->getFlashdata('infos'));
@ -108,11 +107,11 @@ class InfosTest extends \CIUnitTestCase
public function testInfosFlashKeep()
{
$session = $this->getInstance();
$this->library = new Aauth(NULL, $session);
$this->library = new Aauth(null, $session);
$this->assertNull($session->getFlashdata('infos'));
$this->library->info('test message 1 Flash', true);
$session->start();
$this->library = new Aauth(NULL, $session);
$this->library = new Aauth(null, $session);
$this->library->info('test message 1 NonFlash');
$this->library->keepInfos(true);
$session->start();

1
tests/Aauth/Libraries/Aauth/LoginTest.php

@ -38,7 +38,6 @@ class LoginTest extends CIDatabaseTestCase
public function tearDown()
{
}
protected function getInstance($options = [])

20
tests/Aauth/Libraries/Aauth/UserTest.php

@ -81,35 +81,35 @@ class UserTest extends CIDatabaseTestCase
]);
$this->assertEquals(lang('Aauth.infoUpdateSuccess'), $this->library->getInfosArray()[0]);
// $this->library->clearInfos();
// $this->assertFalse($this->library->updateUser(2, '[email protected]', null, null));
// $this->assertEquals(lang('Aauth.existsAlreadyEmail'), $this->library->getErrorsArray()[0]);
$this->library = new Aauth(NULL, $session);
$this->assertFalse($this->library->updateUser(2, '[email protected]', null, null));
$this->assertEquals(lang('Aauth.existsAlreadyEmail'), $this->library->getErrorsArray()[0]);
$this->library->clearErrors();
$this->library = new Aauth(NULL, $session);
$this->assertFalse($this->library->updateUser(2, 'adminexample.com', null, null));
$this->assertEquals(lang('Aauth.invalidEmail'), $this->library->getErrorsArray()[0]);
$this->library->clearErrors();
$this->library = new Aauth(NULL, $session);
$this->assertFalse($this->library->updateUser(2, null, 'pass', null));
$this->assertEquals(lang('Aauth.invalidPassword'), $this->library->getErrorsArray()[0]);
$this->library->clearErrors();
$this->library = new Aauth(NULL, $session);
$this->assertFalse($this->library->updateUser(2, null, 'password12345678901011121314151617', null));
$this->assertEquals(lang('Aauth.invalidPassword'), $this->library->getErrorsArray()[0]);
$this->library->clearErrors();
$this->library = new Aauth(NULL, $session);
$this->assertFalse($this->library->updateUser(2, null, null, 'admin'));
$this->assertEquals(lang('Aauth.existsAlreadyUsername'), $this->library->getErrorsArray()[0]);
$this->library->clearErrors();
$this->library = new Aauth(NULL, $session);
$this->assertFalse($this->library->updateUser(2, null, null, 'user+'));
$this->assertEquals(lang('Aauth.invalidUsername'), $this->library->getErrorsArray()[0]);
$this->library->clearErrors();
$this->library = new Aauth(NULL, $session);
$this->assertFalse($this->library->updateUser(2));
$this->assertCount(0, $this->library->getErrorsArray());
$this->library->clearErrors();
$this->library = new Aauth(NULL, $session);
$this->assertFalse($this->library->updateUser(99));
$this->assertEquals(lang('Aauth.notFoundUser'), $this->library->getErrorsArray()[0]);
}

Loading…
Cancel
Save