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()
{
$groupToGroup = $this->model->exists(99, 99);

80
tests/Aauth/Database/GroupToUserModelTest.php

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

83
tests/Aauth/Database/PermToGroupModelTest.php

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

95
tests/Aauth/Database/PermToUserModelTest.php

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

78
tests/Aauth/Database/UserVariableModelTest.php

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

Loading…
Cancel
Save