Browse Source

fixed tests after added caching feature

v3-dev
REJack 6 years ago
parent
commit
8068cb78e0
No known key found for this signature in database
GPG Key ID: 4A44B48700429F46
  1. 14
      app/Models/Aauth/PermToGroupModel.php
  2. 13
      app/Models/Aauth/PermToUserModel.php
  3. 12
      tests/Aauth/Libraries/Aauth/AccessTest.php
  4. 2
      tests/Aauth/Libraries/Aauth/GroupTest.php
  5. 8
      tests/Aauth/Libraries/Aauth/PermTest.php

14
app/Models/Aauth/PermToGroupModel.php

@ -94,6 +94,7 @@ class PermToGroupModel
* Get all Perm Ids by 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);
}

13
app/Models/Aauth/PermToUserModel.php

@ -94,6 +94,7 @@ class PermToUserModel
* Get all Perm Ids by 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);
}

12
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));
}
}

2
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,

8
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,

Loading…
Cancel
Save