Browse Source

updated GroupToGroupModelTest

v3-dev
REJack 6 years ago
parent
commit
6af21ea87b
No known key found for this signature in database
GPG Key ID: 4A44B48700429F46
  1. 70
      tests/Aauth/Database/GroupToGroupModelTest.php

70
tests/Aauth/Database/GroupToGroupModelTest.php

@ -1,5 +1,6 @@
<?php namespace Tests\Aauth\Database;
use Config\Aauth as AauthConfig;
use CodeIgniter\Test\CIDatabaseTestCase;
use App\Models\Aauth\GroupToGroupModel;
@ -16,6 +17,7 @@ class GroupToGroupModelTest extends CIDatabaseTestCase
parent::setUp();
$this->model = new GroupToGroupModel($this->db);
$this->config = new AauthConfig();
}
//--------------------------------------------------------------------
@ -28,7 +30,10 @@ class GroupToGroupModelTest extends CIDatabaseTestCase
public function testExistsTrue()
{
$this->model->insert(99, 99);
$this->hasInDatabase($this->config->dbTableGroupToGroup, [
'group_id' => 99,
'subgroup_id' => 99,
]);
$groupToGroup = $this->model->exists(99, 99);
$this->assertTrue($groupToGroup);
}
@ -37,7 +42,10 @@ class GroupToGroupModelTest extends CIDatabaseTestCase
{
$groupsToGroup = $this->model->findAllBySubgroupId(99);
$this->assertCount(0, $groupsToGroup);
$this->model->insert(99, 99);
$this->hasInDatabase($this->config->dbTableGroupToGroup, [
'group_id' => 99,
'subgroup_id' => 99,
]);
$groupsToGroup = $this->model->findAllBySubgroupId(99);
$this->assertCount(1, $groupsToGroup);
}
@ -46,46 +54,68 @@ class GroupToGroupModelTest extends CIDatabaseTestCase
{
$groupToGroups = $this->model->findAllByGroupId(99);
$this->assertCount(0, $groupToGroups);
$this->model->insert(99, 99);
$this->hasInDatabase($this->config->dbTableGroupToGroup, [
'group_id' => 99,
'subgroup_id' => 99,
]);
$groupToGroups = $this->model->findAllByGroupId(99);
$this->assertCount(1, $groupToGroups);
}
public function testDelete()
{
$this->model->insert(99, 99);
$groupToGroup = $this->model->exists(99, 99);
$this->assertTrue($groupToGroup);
$this->hasInDatabase($this->config->dbTableGroupToGroup, [
'group_id' => 99,
'subgroup_id' => 99,
]);
$criteria = [
'group_id' => 99,
'subgroup_id' => 99,
];
$this->seeNumRecords(1, $this->config->dbTableGroupToGroup, $criteria);
$this->model->delete(99, 99);
$groupToGroup = $this->model->exists(99, 99);
$this->assertFalse($groupToGroup);
$this->seeNumRecords(0, $this->config->dbTableGroupToGroup, $criteria);
}
public function testDeleteAllByGroupId()
{
$this->model->insert(99, 99);
$groupToGroups = $this->model->findAllByGroupId(99);
$this->assertCount(1, $groupToGroups);
$this->hasInDatabase($this->config->dbTableGroupToGroup, [
'group_id' => 99,
'subgroup_id' => 99,
]);
$criteria = [
'group_id' => 99
];
$this->seeNumRecords(1, $this->config->dbTableGroupToGroup, $criteria);
$this->model->deleteAllByGroupId(99);
$groupToGroups = $this->model->findAllByGroupId(99);
$this->assertCount(0, $groupToGroups);
$this->seeNumRecords(0, $this->config->dbTableGroupToGroup, $criteria);
}
public function testDeleteAllBySubgroupId()
{
$this->model->insert(99, 99);
$groupsToGroup = $this->model->findAllBySubgroupId(99);
$this->assertCount(1, $groupsToGroup);
$this->hasInDatabase($this->config->dbTableGroupToGroup, [
'group_id' => 99,
'subgroup_id' => 99,
]);
$criteria = [
'subgroup_id' => 99
];
$this->seeNumRecords(1, $this->config->dbTableGroupToGroup, $criteria);
$this->model->deleteAllBySubgroupId(99);
$groupsToGroup = $this->model->findAllBySubgroupId(99);
$this->assertCount(0, $groupsToGroup);
$this->seeNumRecords(0, $this->config->dbTableGroupToGroup, $criteria);
}
public function testConfigDBGroup()
{
$this->model = new GroupToGroupModel();
$this->model->insert(99, 99);
$this->model->insert(98, 99);
$this->hasInDatabase($this->config->dbTableGroupToGroup, [
'group_id' => 99,
'subgroup_id' => 99,
]);
$this->hasInDatabase($this->config->dbTableGroupToGroup, [
'group_id' => 98,
'subgroup_id' => 99,
]);
$groupsToGroup = $this->model->findAllBySubgroupId(99);
$this->assertCount(2, $groupsToGroup);
}

Loading…
Cancel
Save