From 8068cb78e0149b05c1b5fc49d8ed6f412911281b Mon Sep 17 00:00:00 2001 From: REJack Date: Sat, 26 Jan 2019 14:23:16 +0100 Subject: [PATCH] fixed tests after added caching feature --- app/Models/Aauth/PermToGroupModel.php | 16 ++++++++++------ app/Models/Aauth/PermToUserModel.php | 15 +++++++++------ tests/Aauth/Libraries/Aauth/AccessTest.php | 12 +++++++++--- tests/Aauth/Libraries/Aauth/GroupTest.php | 2 ++ tests/Aauth/Libraries/Aauth/PermTest.php | 8 ++++++++ 5 files changed, 38 insertions(+), 15 deletions(-) diff --git a/app/Models/Aauth/PermToGroupModel.php b/app/Models/Aauth/PermToGroupModel.php index 348f2ec..25d2b22 100644 --- a/app/Models/Aauth/PermToGroupModel.php +++ b/app/Models/Aauth/PermToGroupModel.php @@ -93,7 +93,8 @@ class PermToGroupModel /** * Get all Perm Ids by Group Id * - * @param integer $groupId Group Id + * @param integer $groupId Group Id + * @param integer|null $state State (0 = denied, 1 = allowed) * * @return array|null */ @@ -102,15 +103,16 @@ class PermToGroupModel $builder = $this->builder(); $builder->where('group_id', $groupId); - if (! $state) - { - $builder->select('perm_id, state'); - } - else if ($state) + if (is_int($state)) { $builder->select('perm_id'); $builder->where('state', $state); } + else + { + $builder->select('perm_id, state'); + } + return $builder->get()->getResult('array'); } @@ -145,6 +147,7 @@ class PermToGroupModel $builder->where('perm_id', $permId); $builder->where('group_id', $groupId); $builder->where('state', 1); + return ($builder->countAllResults() ? true : false); } @@ -163,6 +166,7 @@ class PermToGroupModel $builder->where('perm_id', $permId); $builder->where('group_id', $groupId); $builder->where('state', 0); + return ($builder->countAllResults() ? true : false); } diff --git a/app/Models/Aauth/PermToUserModel.php b/app/Models/Aauth/PermToUserModel.php index 9a88c16..dd8c082 100644 --- a/app/Models/Aauth/PermToUserModel.php +++ b/app/Models/Aauth/PermToUserModel.php @@ -93,7 +93,8 @@ class PermToUserModel /** * Get all Perm Ids by User Id * - * @param integer $userId User Id + * @param integer $userId User Id + * @param integer|null $state State (0 = denied, 1 = allowed) * * @return array|null */ @@ -102,15 +103,15 @@ class PermToUserModel $builder = $this->builder(); $builder->where('user_id', $userId); - if (! $state) - { - $builder->select('perm_id, state'); - } - else if ($state) + if (is_int($state)) { $builder->select('perm_id'); $builder->where('state', $state); } + else + { + $builder->select('perm_id, state'); + } return $builder->get()->getResult('array'); } @@ -146,6 +147,7 @@ class PermToUserModel $builder->where('perm_id', $permId); $builder->where('user_id', $userId); $builder->where('state', 1); + return ($builder->countAllResults() ? true : false); } @@ -164,6 +166,7 @@ class PermToUserModel $builder->where('perm_id', $permId); $builder->where('user_id', $userId); $builder->where('state', 0); + return ($builder->countAllResults() ? true : false); } diff --git a/tests/Aauth/Libraries/Aauth/AccessTest.php b/tests/Aauth/Libraries/Aauth/AccessTest.php index fb45a83..53efad0 100644 --- a/tests/Aauth/Libraries/Aauth/AccessTest.php +++ b/tests/Aauth/Libraries/Aauth/AccessTest.php @@ -138,12 +138,15 @@ class AccessTest extends CIDatabaseTestCase $this->hasInDatabase($config->dbTablePermToGroup, [ 'perm_id' => 1, 'group_id' => 2, + 'state' => 1, ]); + $this->library = new Aauth(null, true); $this->assertTrue($this->library->isAllowed('testPerm1', 2)); $this->hasInDatabase($config->dbTablePermToUser, [ 'perm_id' => 1, 'user_id' => 2, + 'state' => 1, ]); $this->assertTrue($this->library->isAllowed('testPerm1', 2)); @@ -173,11 +176,11 @@ class AccessTest extends CIDatabaseTestCase 'definition' => 'Test Perm 1', ]); - $this->assertTrue($this->library->isGroupAllowed('testPerm1', $config->groupAdmin)); - $session = $this->getInstance(); $this->library = new Aauth(null, $session); + $this->assertTrue($this->library->isGroupAllowed('testPerm1', $config->groupAdmin)); + $session->set('user', [ 'id' => 2, 'loggedIn' => true, @@ -188,6 +191,7 @@ class AccessTest extends CIDatabaseTestCase $this->hasInDatabase($config->dbTablePermToGroup, [ 'perm_id' => 1, 'group_id' => 2, + 'state' => 1, ]); $this->assertTrue($this->library->isGroupAllowed('testPerm1', 2)); @@ -228,7 +232,6 @@ class AccessTest extends CIDatabaseTestCase 'name' => 'testGroups1', 'definition' => 'Test Group 1', ]); - $this->hasInDatabase($config->dbTableGroupToGroup, [ 'group_id' => 2, 'subgroup_id' => 4, @@ -236,7 +239,10 @@ class AccessTest extends CIDatabaseTestCase $this->hasInDatabase($config->dbTablePermToGroup, [ 'perm_id' => 1, 'group_id' => 4, + 'state' => 1, ]); + + $this->library = new Aauth(null, true); $this->assertTrue($this->library->isGroupAllowed('testPerm1', 2)); } } diff --git a/tests/Aauth/Libraries/Aauth/GroupTest.php b/tests/Aauth/Libraries/Aauth/GroupTest.php index acdf10b..ae1bf27 100644 --- a/tests/Aauth/Libraries/Aauth/GroupTest.php +++ b/tests/Aauth/Libraries/Aauth/GroupTest.php @@ -91,6 +91,7 @@ class GroupTest extends CIDatabaseTestCase 'name' => 'testGroup1', 'definition' => 'Test Group 1', ]); + $this->library = new Aauth(null, true); $this->library->updateGroup('testGroup1', 'testGroup1N', 'Test Group 1 New'); $this->seeInDatabase($this->config->dbTableGroups, [ 'id' => 4, @@ -121,6 +122,7 @@ class GroupTest extends CIDatabaseTestCase 'name' => 'testGroup1', 'definition' => 'Test Group 1', ]); + $this->library = new Aauth(null, true); $this->assertTrue($this->library->deleteGroup('testGroup1')); $this->dontSeeInDatabase($this->config->dbTableGroups, [ 'id' => 4, diff --git a/tests/Aauth/Libraries/Aauth/PermTest.php b/tests/Aauth/Libraries/Aauth/PermTest.php index 3887ca0..bdbf595 100644 --- a/tests/Aauth/Libraries/Aauth/PermTest.php +++ b/tests/Aauth/Libraries/Aauth/PermTest.php @@ -87,6 +87,7 @@ class PermTest extends CIDatabaseTestCase 'name' => 'testPerm2', 'definition' => 'Test Perm 2', ]); + $this->library = new Aauth(null, true); $this->library->updatePerm('testPerm1', 'testPerm1N', 'Test Perm 1 New'); $this->seeInDatabase($this->config->dbTablePerms, [ 'id' => 1, @@ -116,6 +117,7 @@ class PermTest extends CIDatabaseTestCase 'name' => 'testPerm1', 'definition' => 'Test Perm 1', ]); + $this->library = new Aauth(null, true); $this->assertTrue($this->library->deletePerm('testPerm1')); $this->dontSeeInDatabase($this->config->dbTablePerms, [ 'name' => 'testPerm1', @@ -270,6 +272,7 @@ class PermTest extends CIDatabaseTestCase 'name' => 'testPerm1', 'definition' => 'Test Perm 1', ]); + $this->library = new Aauth(null, true); $this->assertEquals(1, $this->library->getPermId('testPerm1')); $this->assertEquals(1, $this->library->getPermId(1)); @@ -282,6 +285,7 @@ class PermTest extends CIDatabaseTestCase 'name' => 'testPerm1', 'definition' => 'Test Perm 1', ]); + $this->library = new Aauth(null, true); $perm = $this->library->getPerm('testPerm1'); $this->assertEquals(1, $perm['id']); @@ -298,6 +302,7 @@ class PermTest extends CIDatabaseTestCase 'name' => 'testPerm1', 'definition' => 'Test Perm 1', ]); + $this->library = new Aauth(null, true); $this->assertTrue($this->library->allowUser(1, 1)); $this->seeInDatabase($this->config->dbTablePermToUser, [ 'perm_id' => 1, @@ -320,6 +325,7 @@ class PermTest extends CIDatabaseTestCase 'name' => 'testPerm1', 'definition' => 'Test Perm 1', ]); + $this->library = new Aauth(null, true); $this->assertTrue($this->library->denyUser(1, 1)); $this->seeInDatabase($this->config->dbTablePermToUser, [ 'perm_id' => 1, @@ -342,6 +348,7 @@ class PermTest extends CIDatabaseTestCase 'name' => 'testPerm1', 'definition' => 'Test Perm 1', ]); + $this->library = new Aauth(null, true); $this->assertTrue($this->library->allowGroup(1, 1)); $this->seeInDatabase($this->config->dbTablePermToGroup, [ 'perm_id' => 1, @@ -364,6 +371,7 @@ class PermTest extends CIDatabaseTestCase 'name' => 'testPerm1', 'definition' => 'Test Perm 1', ]); + $this->library = new Aauth(null, true); $this->assertTrue($this->library->denyGroup(1, 1)); $this->seeInDatabase($this->config->dbTablePermToGroup, [ 'perm_id' => 1,