Browse Source

updated Database Tests

v3-dev
REJack 6 years ago
parent
commit
483c1a95c6
No known key found for this signature in database
GPG Key ID: 4A44B48700429F46
  1. 10
      tests/Aauth/Database/GroupToGroupModelTest.php
  2. 80
      tests/Aauth/Database/GroupToUserModelTest.php
  3. 83
      tests/Aauth/Database/PermToGroupModelTest.php
  4. 95
      tests/Aauth/Database/PermToUserModelTest.php
  5. 78
      tests/Aauth/Database/UserVariableModelTest.php

10
tests/Aauth/Database/GroupToGroupModelTest.php

@ -22,6 +22,16 @@ class GroupToGroupModelTest extends CIDatabaseTestCase
//-------------------------------------------------------------------- //--------------------------------------------------------------------
public function testInsert()
{
$groupToGroup = $this->model->insert(99, 99);
$this->assertTrue($groupToGroup);
$this->seeInDatabase($this->config->dbTableGroupToGroup, [
'group_id' => 99,
'subgroup_id' => 99,
]);
}
public function testExistsFalse() public function testExistsFalse()
{ {
$groupToGroup = $this->model->exists(99, 99); $groupToGroup = $this->model->exists(99, 99);

80
tests/Aauth/Database/GroupToUserModelTest.php

@ -1,5 +1,6 @@
<?php namespace Tests\Aauth\Database; <?php namespace Tests\Aauth\Database;
use Config\Aauth as AauthConfig;
use CodeIgniter\Test\CIDatabaseTestCase; use CodeIgniter\Test\CIDatabaseTestCase;
use App\Models\Aauth\GroupToUserModel; use App\Models\Aauth\GroupToUserModel;
@ -16,10 +17,21 @@ class GroupToUserModelTest extends CIDatabaseTestCase
parent::setUp(); parent::setUp();
$this->model = new GroupToUserModel($this->db); $this->model = new GroupToUserModel($this->db);
$this->config = new AauthConfig();
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
public function testInsert()
{
$groupToGroup = $this->model->insert(99, 99);
$this->assertTrue($groupToGroup);
$this->seeInDatabase($this->config->dbTableGroupToUser, [
'group_id' => 99,
'user_id' => 99,
]);
}
public function testExistsFalse() public function testExistsFalse()
{ {
$groupToUser = $this->model->exists(99, 99); $groupToUser = $this->model->exists(99, 99);
@ -28,7 +40,10 @@ class GroupToUserModelTest extends CIDatabaseTestCase
public function testExistsTrue() public function testExistsTrue()
{ {
$this->model->insert(99, 99); $this->hasInDatabase($this->config->dbTableGroupToUser, [
'group_id' => 99,
'user_id' => 99,
]);
$groupToUser = $this->model->exists(99, 99); $groupToUser = $this->model->exists(99, 99);
$this->assertTrue($groupToUser); $this->assertTrue($groupToUser);
} }
@ -37,7 +52,10 @@ class GroupToUserModelTest extends CIDatabaseTestCase
{ {
$groupToUsers = $this->model->findAllByUserId(99); $groupToUsers = $this->model->findAllByUserId(99);
$this->assertCount(0, $groupToUsers); $this->assertCount(0, $groupToUsers);
$this->model->insert(99, 99); $this->hasInDatabase($this->config->dbTableGroupToUser, [
'group_id' => 99,
'user_id' => 99,
]);
$groupToUsers = $this->model->findAllByUserId(99); $groupToUsers = $this->model->findAllByUserId(99);
$this->assertCount(1, $groupToUsers); $this->assertCount(1, $groupToUsers);
} }
@ -46,46 +64,68 @@ class GroupToUserModelTest extends CIDatabaseTestCase
{ {
$groupToUsers = $this->model->findAllByGroupId(99); $groupToUsers = $this->model->findAllByGroupId(99);
$this->assertCount(0, $groupToUsers); $this->assertCount(0, $groupToUsers);
$this->model->insert(99, 99); $this->hasInDatabase($this->config->dbTableGroupToUser, [
'group_id' => 99,
'user_id' => 99,
]);
$groupToUsers = $this->model->findAllByGroupId(99); $groupToUsers = $this->model->findAllByGroupId(99);
$this->assertCount(1, $groupToUsers); $this->assertCount(1, $groupToUsers);
} }
public function testDelete() public function testDelete()
{ {
$this->model->insert(99, 99); $this->hasInDatabase($this->config->dbTableGroupToUser, [
$groupToUser = $this->model->exists(99, 99); 'group_id' => 99,
$this->assertTrue($groupToUser); 'user_id' => 99,
]);
$criteria = [
'group_id' => 99,
'user_id' => 99,
];
$this->seeNumRecords(1, $this->config->dbTableGroupToUser, $criteria);
$this->model->delete(99, 99); $this->model->delete(99, 99);
$groupToUser = $this->model->exists(99, 99); $this->seeNumRecords(0, $this->config->dbTableGroupToUser, $criteria);
$this->assertFalse($groupToUser);
} }
public function testDeleteAllByGroupId() public function testDeleteAllByGroupId()
{ {
$this->model->insert(99, 99); $this->hasInDatabase($this->config->dbTableGroupToUser, [
$groupToUsers = $this->model->findAllByGroupId(99); 'group_id' => 99,
$this->assertCount(1, $groupToUsers); 'user_id' => 99,
]);
$criteria = [
'group_id' => 99
];
$this->seeNumRecords(1, $this->config->dbTableGroupToUser, $criteria);
$this->model->deleteAllByGroupId(99); $this->model->deleteAllByGroupId(99);
$groupToUsers = $this->model->findAllByGroupId(99); $this->seeNumRecords(0, $this->config->dbTableGroupToUser, $criteria);
$this->assertCount(0, $groupToUsers);
} }
public function testDeleteAllByUserId() public function testDeleteAllByUserId()
{ {
$this->model->insert(99, 99); $this->hasInDatabase($this->config->dbTableGroupToUser, [
$groupToUsers = $this->model->findAllByUserId(99); 'group_id' => 99,
$this->assertCount(1, $groupToUsers); 'user_id' => 99,
]);
$criteria = [
'user_id' => 99
];
$this->seeNumRecords(1, $this->config->dbTableGroupToUser, $criteria);
$this->model->deleteAllByUserId(99); $this->model->deleteAllByUserId(99);
$groupToUsers = $this->model->findAllByUserId(99); $this->seeNumRecords(0, $this->config->dbTableGroupToUser, $criteria);
$this->assertCount(0, $groupToUsers);
} }
public function testConfigDBGroup() public function testConfigDBGroup()
{ {
$this->model = new GroupToUserModel(); $this->model = new GroupToUserModel();
$this->model->insert(99, 99); $this->hasInDatabase($this->config->dbTableGroupToUser, [
$this->model->insert(98, 99); 'group_id' => 99,
'user_id' => 99,
]);
$this->hasInDatabase($this->config->dbTableGroupToUser, [
'group_id' => 98,
'user_id' => 99,
]);
$groupToUsers = $this->model->findAllByUserId(99); $groupToUsers = $this->model->findAllByUserId(99);
$this->assertCount(2, $groupToUsers); $this->assertCount(2, $groupToUsers);
} }

83
tests/Aauth/Database/PermToGroupModelTest.php

@ -1,5 +1,6 @@
<?php namespace Tests\Aauth\Database; <?php namespace Tests\Aauth\Database;
use Config\Aauth as AauthConfig;
use CodeIgniter\Test\CIDatabaseTestCase; use CodeIgniter\Test\CIDatabaseTestCase;
use App\Models\Aauth\PermToGroupModel; use App\Models\Aauth\PermToGroupModel;
@ -16,19 +17,36 @@ class PermToGroupModelTest extends CIDatabaseTestCase
parent::setUp(); parent::setUp();
$this->model = new PermToGroupModel($this->db); $this->model = new PermToGroupModel($this->db);
$this->config = new AauthConfig();
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
public function testInsert()
{
$permToGroup = $this->model->insert(99, 99);
$this->assertTrue($permToGroup);
$this->seeInDatabase($this->config->dbTablePermToGroup, [
'perm_id' => 99,
'group_id' => 99,
]);
}
public function testExistsFalse() public function testExistsFalse()
{ {
$this->hasInDatabase($this->config->dbTablePermToGroup, [
'perm_id' => 99,
'group_id' => 99,
]);
$permToGroup = $this->model->exists(99, 99); $permToGroup = $this->model->exists(99, 99);
$this->assertFalse($permToGroup); $this->assertFalse($permToGroup);
} }
public function testExistsTrue() public function testExistsTrue()
{ {
$this->model->insert(99, 99); $this->hasInDatabase($this->config->dbTablePermToGroup, [
'perm_id' => 99,
'group_id' => 99,
]);
$permToGroup = $this->model->exists(99, 99); $permToGroup = $this->model->exists(99, 99);
$this->assertTrue($permToGroup); $this->assertTrue($permToGroup);
} }
@ -37,7 +55,10 @@ class PermToGroupModelTest extends CIDatabaseTestCase
{ {
$permsToGroup = $this->model->findAllByGroupId(99); $permsToGroup = $this->model->findAllByGroupId(99);
$this->assertCount(0, $permsToGroup); $this->assertCount(0, $permsToGroup);
$this->model->insert(99, 99); $this->hasInDatabase($this->config->dbTablePermToGroup, [
'perm_id' => 99,
'group_id' => 99,
]);
$permsToGroup = $this->model->findAllByGroupId(99); $permsToGroup = $this->model->findAllByGroupId(99);
$this->assertCount(1, $permsToGroup); $this->assertCount(1, $permsToGroup);
} }
@ -46,46 +67,68 @@ class PermToGroupModelTest extends CIDatabaseTestCase
{ {
$permToGroups = $this->model->findAllByPermId(99); $permToGroups = $this->model->findAllByPermId(99);
$this->assertCount(0, $permToGroups); $this->assertCount(0, $permToGroups);
$this->model->insert(99, 99); $this->hasInDatabase($this->config->dbTablePermToGroup, [
'perm_id' => 99,
'group_id' => 99,
]);
$permToGroups = $this->model->findAllByPermId(99); $permToGroups = $this->model->findAllByPermId(99);
$this->assertCount(1, $permToGroups); $this->assertCount(1, $permToGroups);
} }
public function testDelete() public function testDelete()
{ {
$this->model->insert(99, 99); $this->hasInDatabase($this->config->dbTablePermToGroup, [
$permToGroup = $this->model->exists(99, 99); 'perm_id' => 99,
$this->assertTrue($permToGroup); 'group_id' => 99,
]);
$criteria = [
'perm_id' => 99,
'group_id' => 99,
];
$this->seeNumRecords(1, $this->config->dbTablePermToGroup, $criteria);
$this->model->delete(99, 99); $this->model->delete(99, 99);
$permToGroup = $this->model->exists(99, 99); $this->seeNumRecords(0, $this->config->dbTablePermToGroup, $criteria);
$this->assertFalse($permToGroup);
} }
public function testDeleteAllByPermId() public function testDeleteAllByPermId()
{ {
$this->model->insert(99, 99); $this->hasInDatabase($this->config->dbTablePermToGroup, [
$permToGroups = $this->model->findAllByPermId(99); 'perm_id' => 99,
$this->assertCount(1, $permToGroups); 'group_id' => 99,
]);
$criteria = [
'perm_id' => 99,
];
$this->seeNumRecords(1, $this->config->dbTablePermToGroup, $criteria);
$this->model->deleteAllByPermId(99); $this->model->deleteAllByPermId(99);
$permToGroups = $this->model->findAllByPermId(99); $this->seeNumRecords(0, $this->config->dbTablePermToGroup, $criteria);
$this->assertCount(0, $permToGroups);
} }
public function testDeleteAllByGroupId() public function testDeleteAllByGroupId()
{ {
$this->model->insert(99, 99); $this->hasInDatabase($this->config->dbTablePermToGroup, [
$permsToGroup = $this->model->findAllByGroupId(99); 'perm_id' => 99,
$this->assertCount(1, $permsToGroup); 'group_id' => 99,
]);
$criteria = [
'group_id' => 99,
];
$this->seeNumRecords(1, $this->config->dbTablePermToGroup, $criteria);
$this->model->deleteAllByGroupId(99); $this->model->deleteAllByGroupId(99);
$permsToGroup = $this->model->findAllByGroupId(99); $this->seeNumRecords(0, $this->config->dbTablePermToGroup, $criteria);
$this->assertCount(0, $permsToGroup);
} }
public function testConfigDBPerm() public function testConfigDBPerm()
{ {
$this->model = new PermToGroupModel(); $this->model = new PermToGroupModel();
$this->model->insert(99, 99); $this->hasInDatabase($this->config->dbTablePermToGroup, [
$this->model->insert(98, 99); 'perm_id' => 99,
'group_id' => 99,
]);
$this->hasInDatabase($this->config->dbTablePermToGroup, [
'perm_id' => 98,
'group_id' => 99,
]);
$permsToGroup = $this->model->findAllByGroupId(99); $permsToGroup = $this->model->findAllByGroupId(99);
$this->assertCount(2, $permsToGroup); $this->assertCount(2, $permsToGroup);
} }

95
tests/Aauth/Database/PermToUserModelTest.php

@ -1,5 +1,6 @@
<?php namespace Tests\Aauth\Database; <?php namespace Tests\Aauth\Database;
use Config\Aauth as AauthConfig;
use CodeIgniter\Test\CIDatabaseTestCase; use CodeIgniter\Test\CIDatabaseTestCase;
use App\Models\Aauth\PermToUserModel; use App\Models\Aauth\PermToUserModel;
@ -16,29 +17,49 @@ class PermToUserModelTest extends CIDatabaseTestCase
parent::setUp(); parent::setUp();
$this->model = new PermToUserModel($this->db); $this->model = new PermToUserModel($this->db);
$this->config = new AauthConfig();
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
public function testInsert()
{
$permToUser = $this->model->insert(99, 99);
$this->assertTrue($permToUser);
$this->seeInDatabase($this->config->dbTablePermToUser, [
'perm_id' => 99,
'user_id' => 99,
]);
}
public function testExistsFalse() public function testExistsFalse()
{ {
$this->hasInDatabase($this->config->dbTablePermToUser, [
'perm_id' => 99,
'user_id' => 99,
]);
$permToUser = $this->model->exists(99, 99); $permToUser = $this->model->exists(99, 99);
$this->assertFalse($permToUser); $this->assertFalse($permToUser);
} }
public function testExistsTrue() public function testExistsTrue()
{ {
$this->model->insert(99, 99); $this->hasInDatabase($this->config->dbTablePermToUser, [
'perm_id' => 99,
'user_id' => 99,
]);
$permToUser = $this->model->exists(99, 99); $permToUser = $this->model->exists(99, 99);
$this->assertTrue($permToUser); $this->assertTrue($permToUser);
} }
public function testFindAllByUserId() public function testFindAllByGroupId()
{ {
$permsToUser = $this->model->findAllByUserId(99); $permsToUser = $this->model->findAllByGroupId(99);
$this->assertCount(0, $permsToUser); $this->assertCount(0, $permsToUser);
$this->model->insert(99, 99); $this->hasInDatabase($this->config->dbTablePermToUser, [
$permsToUser = $this->model->findAllByUserId(99); 'perm_id' => 99,
'user_id' => 99,
]);
$permsToUser = $this->model->findAllByGroupId(99);
$this->assertCount(1, $permsToUser); $this->assertCount(1, $permsToUser);
} }
@ -46,47 +67,69 @@ class PermToUserModelTest extends CIDatabaseTestCase
{ {
$permToUsers = $this->model->findAllByPermId(99); $permToUsers = $this->model->findAllByPermId(99);
$this->assertCount(0, $permToUsers); $this->assertCount(0, $permToUsers);
$this->model->insert(99, 99); $this->hasInDatabase($this->config->dbTablePermToUser, [
'perm_id' => 99,
'user_id' => 99,
]);
$permToUsers = $this->model->findAllByPermId(99); $permToUsers = $this->model->findAllByPermId(99);
$this->assertCount(1, $permToUsers); $this->assertCount(1, $permToUsers);
} }
public function testDelete() public function testDelete()
{ {
$this->model->insert(99, 99); $this->hasInDatabase($this->config->dbTablePermToUser, [
$permToUser = $this->model->exists(99, 99); 'perm_id' => 99,
$this->assertTrue($permToUser); 'user_id' => 99,
]);
$criteria = [
'perm_id' => 99,
'user_id' => 99,
];
$this->seeNumRecords(1, $this->config->dbTablePermToUser, $criteria);
$this->model->delete(99, 99); $this->model->delete(99, 99);
$permToUser = $this->model->exists(99, 99); $this->seeNumRecords(0, $this->config->dbTablePermToUser, $criteria);
$this->assertFalse($permToUser);
} }
public function testDeleteAllByPermId() public function testDeleteAllByPermId()
{ {
$this->model->insert(99, 99); $this->hasInDatabase($this->config->dbTablePermToUser, [
$permToUsers = $this->model->findAllByPermId(99); 'perm_id' => 99,
$this->assertCount(1, $permToUsers); 'user_id' => 99,
]);
$criteria = [
'perm_id' => 99,
];
$this->seeNumRecords(1, $this->config->dbTablePermToUser, $criteria);
$this->model->deleteAllByPermId(99); $this->model->deleteAllByPermId(99);
$permToUsers = $this->model->findAllByPermId(99); $this->seeNumRecords(0, $this->config->dbTablePermToUser, $criteria);
$this->assertCount(0, $permToUsers);
} }
public function testDeleteAllByUserId() public function testDeleteAllByGroupId()
{ {
$this->model->insert(99, 99); $this->hasInDatabase($this->config->dbTablePermToUser, [
$permsToUser = $this->model->findAllByUserId(99); 'perm_id' => 99,
$this->assertCount(1, $permsToUser); 'user_id' => 99,
$this->model->deleteAllByUserId(99); ]);
$permsToUser = $this->model->findAllByUserId(99); $criteria = [
$this->assertCount(0, $permsToUser); 'user_id' => 99,
];
$this->seeNumRecords(1, $this->config->dbTablePermToUser, $criteria);
$this->model->deleteAllByGroupId(99);
$this->seeNumRecords(0, $this->config->dbTablePermToUser, $criteria);
} }
public function testConfigDBPerm() public function testConfigDBPerm()
{ {
$this->model = new PermToUserModel(); $this->model = new PermToUserModel();
$this->model->insert(99, 99); $this->hasInDatabase($this->config->dbTablePermToUser, [
$this->model->insert(98, 99); 'perm_id' => 99,
$permsToUser = $this->model->findAllByUserId(99); 'user_id' => 99,
]);
$this->hasInDatabase($this->config->dbTablePermToUser, [
'perm_id' => 98,
'user_id' => 99,
]);
$permsToUser = $this->model->findAllByGroupId(99);
$this->assertCount(2, $permsToUser); $this->assertCount(2, $permsToUser);
} }
} }

78
tests/Aauth/Database/UserVariableModelTest.php

@ -1,5 +1,6 @@
<?php namespace Tests\Aauth\Database; <?php namespace Tests\Aauth\Database;
use Config\Aauth as AauthConfig;
use CodeIgniter\Test\CIDatabaseTestCase; use CodeIgniter\Test\CIDatabaseTestCase;
use App\Models\Aauth\UserVariableModel; use App\Models\Aauth\UserVariableModel;
@ -16,56 +17,93 @@ class UserVariableModelTest extends CIDatabaseTestCase
parent::setUp(); parent::setUp();
$this->model = new UserVariableModel($this->db); $this->model = new UserVariableModel($this->db);
$this->config = new AauthConfig();
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
public function testFindFalse() public function testFindFalse()
{ {
$userVariable = $this->model->find(1, 'test'); $userVariable = $this->model->find(99, 'test');
$this->assertFalse($userVariable); $this->assertFalse($userVariable);
} }
public function testFindReturn() public function testFindReturn()
{ {
$this->model->save(1, 'test', 'TRUE'); $this->hasInDatabase($this->config->dbTableUserVariables, [
$userVariable = $this->model->find(1, 'test'); 'user_id' => 99,
'data_key' => 'test',
'date_value' => 'TRUE',
]);
$userVariable = $this->model->find(99, 'test');
$this->assertEquals('TRUE', $userVariable); $this->assertEquals('TRUE', $userVariable);
} }
public function testFindAll() public function testFindAll()
{ {
$this->model->save(1, 'test', 'TRUE'); $this->hasInDatabase($this->config->dbTableUserVariables, [
$userVariables = $this->model->findAll(1); 'user_id' => 99,
'data_key' => 'test',
'date_value' => 'TRUE',
]);
$userVariables = $this->model->findAll(99);
$this->assertCount(1, $userVariables); $this->assertCount(1, $userVariables);
} }
public function testSaveInsert()
{
$this->model->save(99, 'test', 'TRUE');
$this->seeInDatabase($this->config->dbTableUserVariables, [
'user_id' => 99,
'data_key' => 'test',
'date_value' => 'TRUE',
]);
}
public function testSaveUpdate() public function testSaveUpdate()
{ {
$this->model->save(1, 'test', 'TRUE'); $this->model->save(99, 'test', 'TRUE');
$this->model->save(1, 'test', 'TRUE2'); $this->model->save(99, 'test', 'TRUE2');
$userVariable = $this->model->find(1, 'test'); $this->seeInDatabase($this->config->dbTableUserVariables, [
$this->assertEquals('TRUE2', $userVariable); 'user_id' => 99,
'data_key' => 'test',
'date_value' => 'TRUE2',
]);
} }
public function testDelete() public function testDelete()
{ {
$this->model->save(1, 'test', 'TRUE'); $this->hasInDatabase($this->config->dbTableUserVariables, [
$this->model->delete(1, 'test'); 'user_id' => 99,
$userVariables = $this->model->findAll(1); 'data_key' => 'test',
$this->assertCount(0, $userVariables); 'date_value' => 'TRUE',
]);
$criteria = [
'user_id' => 99,
];
$this->seeNumRecords(1, $this->config->dbTableUserVariables, $criteria);
$this->model->delete(99, 'test');
$this->seeNumRecords(0, $this->config->dbTableUserVariables, $criteria);
} }
public function testAsArrayFirst() public function testAsArrayFirst()
{ {
$this->model->save(1, 'test', 'TRUE'); $this->hasInDatabase($this->config->dbTableUserVariables, [
'user_id' => 99,
'data_key' => 'test',
'date_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); $this->assertInternalType('array', $userVariable);
} }
public function testAsObjectFirst() public function testAsObjectFirst()
{ {
$this->model->save(1, 'test', 'TRUE'); $this->hasInDatabase($this->config->dbTableUserVariables, [
'user_id' => 99,
'data_key' => 'test',
'date_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); $this->assertInternalType('object', $userVariable);
} }
@ -73,7 +111,11 @@ class UserVariableModelTest extends CIDatabaseTestCase
public function testConfigDBGroup() public function testConfigDBGroup()
{ {
$this->model = new UserVariableModel(); $this->model = new UserVariableModel();
$this->model->save(1, 'test', 'TRUE'); $this->hasInDatabase($this->config->dbTableUserVariables, [
'user_id' => 99,
'data_key' => 'test',
'date_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); $this->assertInternalType('object', $userVariable);
} }
@ -85,8 +127,8 @@ class UserVariableModelTest extends CIDatabaseTestCase
public function testDBCall() public function testDBCall()
{ {
$this->model->save(1, 'test', 'TRUE'); $this->model->save(99, 'test', 'TRUE');
$this->assertEquals(1, $this->model->insertID()); $this->assertEquals(99, $this->model->insertID());
} }
} }

Loading…
Cancel
Save