123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
-
- use Luticate\Auth\DataAccess\LuPermissionsDataAccess;
- use Luticate\Utils\Dbo\LuDbo;
-
- /**
- * Created by PhpStorm.
- * User: robin
- * Date: 7/2/16
- * Time: 5:26 PM
- */
- class LuPermissionTest extends \PHPUnit_Framework_TestCase
- {
- protected function permissionTest($expectedValue, string $permissionName, int $permissionId, int $userId)
- {
- $this->assertSame($expectedValue, LuPermissionsDataAccess::getUserEffectivePermissionByName($userId, $permissionName));
- $this->assertSame($expectedValue, LuPermissionsDataAccess::getUserEffectivePermissionById($userId, $permissionId));
- }
-
- public function testPermission0True()
- {
- static::permissionTest(true, "LU_TEST_SIMPLE_TRUE", 3, 0);
- }
-
- public function testPermission0False()
- {
- static::permissionTest(false, "LU_TEST_SIMPLE_FALSE", 4, 0);
- }
-
- public function testPermission0DoesNotExist()
- {
- static::permissionTest(null, "LU_TEST_DOES_NOT_EXIST", 0, 0);
- }
-
- public function testPermissionGroup1True()
- {
- static::permissionTest(true, "LU_TEST_GROUP_1_TRUE", 5, 1);
- }
-
- public function testPermissionGroup1False()
- {
- static::permissionTest(false, "LU_TEST_GROUP_1_FALSE", 6, 1);
- }
-
- public function testPermissionGroup2MultipleGroupsTrue()
- {
- static::permissionTest(true, "LU_TEST_GROUP_2_TRUE", 7, 2);
- }
-
- public function testPermissionGroup3MultipleGroupsTrueFalse()
- {
- static::permissionTest(false, "LU_TEST_GROUP_3_FALSE", 8, 3);
- }
-
- public function testPermissionGroup4MultipleGroupsFalse()
- {
- static::permissionTest(false, "LU_TEST_GROUP_4_FALSE", 9, 4);
- }
-
- public function testPermissionUser5True()
- {
- static::permissionTest(true, "LU_TEST_USER_5_TRUE", 10, 5);
- }
-
- public function testPermissionUser6False()
- {
- static::permissionTest(false, "LU_TEST_USER_6_FALSE", 11, 6);
- }
-
- public function testPermissionGetAll0()
- {
- $permissions = [
- ["id" => 6, "name" =>"LU_TEST_GROUP_1_FALSE", "value" => true],
- ["id" => 5, "name" => "LU_TEST_GROUP_1_TRUE", "value" => true],
- ["id" => 7, "name" => "LU_TEST_GROUP_2_TRUE", "value" => false],
- ["id" => 8, "name" => "LU_TEST_GROUP_3_FALSE", "value" => true],
- ["id" => 9, "name" => "LU_TEST_GROUP_4_FALSE", "value" => true],
- ["id" => 4, "name" => "LU_TEST_SIMPLE_FALSE", "value" => false],
- ["id" => 3, "name" => "LU_TEST_SIMPLE_TRUE", "value" => true],
- ["id" => 10, "name" => "LU_TEST_USER_5_TRUE", "value" => false],
- ["id" => 11, "name" => "LU_TEST_USER_6_FALSE", "value" => true]];
-
- $this->assertSame($permissions, LuDbo::serializeValue(LuPermissionsDataAccess::getUserEffectivePermissions(0)));
- }
-
- public function testPermissionGetAll4()
- {
- $permissions = [
- ["id" => 6, "name" =>"LU_TEST_GROUP_1_FALSE", "value" => true],
- ["id" => 5, "name" => "LU_TEST_GROUP_1_TRUE", "value" => true],
- ["id" => 7, "name" => "LU_TEST_GROUP_2_TRUE", "value" => false],
- ["id" => 8, "name" => "LU_TEST_GROUP_3_FALSE", "value" => true],
- ["id" => 9, "name" => "LU_TEST_GROUP_4_FALSE", "value" => false],
- ["id" => 4, "name" => "LU_TEST_SIMPLE_FALSE", "value" => false],
- ["id" => 3, "name" => "LU_TEST_SIMPLE_TRUE", "value" => true],
- ["id" => 10, "name" => "LU_TEST_USER_5_TRUE", "value" => false],
- ["id" => 11, "name" => "LU_TEST_USER_6_FALSE", "value" => true]];
-
- $this->assertSame($permissions, LuDbo::serializeValue(LuPermissionsDataAccess::getUserEffectivePermissions(4)));
- }
-
- public function testPermissionGetAll6()
- {
- $permissions = [
- ["id" => 6, "name" =>"LU_TEST_GROUP_1_FALSE", "value" => true],
- ["id" => 5, "name" => "LU_TEST_GROUP_1_TRUE", "value" => true],
- ["id" => 7, "name" => "LU_TEST_GROUP_2_TRUE", "value" => false],
- ["id" => 8, "name" => "LU_TEST_GROUP_3_FALSE", "value" => true],
- ["id" => 9, "name" => "LU_TEST_GROUP_4_FALSE", "value" => true],
- ["id" => 4, "name" => "LU_TEST_SIMPLE_FALSE", "value" => false],
- ["id" => 3, "name" => "LU_TEST_SIMPLE_TRUE", "value" => true],
- ["id" => 10, "name" => "LU_TEST_USER_5_TRUE", "value" => false],
- ["id" => 11, "name" => "LU_TEST_USER_6_FALSE", "value" => false]];
-
- $this->assertSame($permissions, LuDbo::serializeValue(LuPermissionsDataAccess::getUserEffectivePermissions(6)));
- }
- }
|