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

Loading…
Cancel
Save