From 6af21ea87bec151026132a752e71deaa4430587f Mon Sep 17 00:00:00 2001 From: REJack Date: Mon, 10 Dec 2018 12:57:11 +0100 Subject: [PATCH] updated GroupToGroupModelTest --- .../Aauth/Database/GroupToGroupModelTest.php | 70 +++++++++++++------ 1 file changed, 50 insertions(+), 20 deletions(-) diff --git a/tests/Aauth/Database/GroupToGroupModelTest.php b/tests/Aauth/Database/GroupToGroupModelTest.php index 4fdada3..8ad6a16 100644 --- a/tests/Aauth/Database/GroupToGroupModelTest.php +++ b/tests/Aauth/Database/GroupToGroupModelTest.php @@ -1,5 +1,6 @@ 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); }