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. 6
      tests/Aauth/Database/UserVariableModelTest.php
  5. 22
      tests/Aauth/Libraries/Aauth/ErrorsTest.php
  6. 21
      tests/Aauth/Libraries/Aauth/InfosTest.php
  7. 3
      tests/Aauth/Libraries/Aauth/LoginTest.php
  8. 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']);

6
tests/Aauth/Database/UserVariableModelTest.php

@ -86,7 +86,7 @@ class UserVariableModelTest extends CIDatabaseTestCase
'data_key' => 'test',
'data_value' => 'TRUE',
]);
$userVariable = $this->model->asArray()->where(['data_key'=>'test', 'data_value'=>'TRUE'])->first();
$userVariable = $this->model->asArray()->where(['data_key' => 'test', 'data_value' => 'TRUE'])->first();
$this->assertInternalType('array', $userVariable);
}
@ -97,7 +97,7 @@ class UserVariableModelTest extends CIDatabaseTestCase
'data_key' => 'test',
'data_value' => 'TRUE',
]);
$userVariable = $this->model->asObject()->where(['data_key'=>'test', 'data_value'=>'TRUE'])->first();
$userVariable = $this->model->asObject()->where(['data_key' => 'test', 'data_value' => 'TRUE'])->first();
$this->assertInternalType('object', $userVariable);
}
@ -109,7 +109,7 @@ class UserVariableModelTest extends CIDatabaseTestCase
'data_key' => 'test',
'data_value' => 'TRUE',
]);
$userVariable = $this->model->asObject()->where(['data_key'=>'test', 'data_value'=>'TRUE'])->first();
$userVariable = $this->model->asObject()->where(['data_key' => 'test', 'data_value' => 'TRUE'])->first();
$this->assertInternalType('object', $userVariable);
}

22
tests/Aauth/Libraries/Aauth/ErrorsTest.php

@ -24,10 +24,9 @@ class ErrorsTest extends \CIUnitTestCase
public function tearDown()
{
}
protected function getInstance($options=[])
protected function getInstance($options = [])
{
$defaults = [
'sessionDriver' => 'CodeIgniter\Session\Handlers\FileHandler',
@ -64,13 +63,12 @@ class ErrorsTest extends \CIUnitTestCase
public function testErrorsArray()
{
$this->assertCount(0, $this->library->getErrorsArray());
$this->library->error(['test message 1','test message 2']);
$this->assertEquals(['test message 1','test message 2'], $this->library->getErrorsArray());
$this->library->error(['test message 1', 'test message 2']);
$this->assertEquals(['test message 1', 'test message 2'], $this->library->getErrorsArray());
}
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,26 +92,26 @@ 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->error(['test message 1','test message 2'], true);
$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'));
$this->assertEquals(['test message 1', 'test message 2'], $session->getFlashdata('errors'));
}
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();

21
tests/Aauth/Libraries/Aauth/InfosTest.php

@ -24,10 +24,9 @@ class InfosTest extends \CIUnitTestCase
public function tearDown()
{
}
protected function getInstance($options=[])
protected function getInstance($options = [])
{
$defaults = [
'sessionDriver' => 'CodeIgniter\Session\Handlers\FileHandler',
@ -64,8 +63,8 @@ class InfosTest extends \CIUnitTestCase
public function testInfosArray()
{
$this->assertCount(0, $this->library->getInfosArray());
$this->library->info(['test message 1','test message 2']);
$this->assertEquals(['test message 1','test message 2'], $this->library->getInfosArray());
$this->library->info(['test message 1', 'test message 2']);
$this->assertEquals(['test message 1', 'test message 2'], $this->library->getInfosArray());
}
public function testPrintInfos()
@ -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,26 +92,26 @@ 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->info(['test message 1','test message 2'], true);
$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'));
$this->assertEquals(['test message 1', 'test message 2'], $session->getFlashdata('infos'));
}
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();

3
tests/Aauth/Libraries/Aauth/LoginTest.php

@ -38,10 +38,9 @@ class LoginTest extends CIDatabaseTestCase
public function tearDown()
{
}
protected function getInstance($options=[])
protected function getInstance($options = [])
{
$defaults = [
'sessionDriver' => 'CodeIgniter\Session\Handlers\FileHandler',

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