Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

LuPermissionTest.php 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. use Luticate\Auth\DataAccess\LuPermissionsDataAccess;
  3. use Luticate\Utils\Dbo\LuDbo;
  4. /**
  5. * Created by PhpStorm.
  6. * User: robin
  7. * Date: 7/2/16
  8. * Time: 5:26 PM
  9. */
  10. class LuPermissionTest extends \PHPUnit_Framework_TestCase
  11. {
  12. protected function permissionTest($expectedValue, string $permissionName, int $permissionId, int $userId)
  13. {
  14. $this->assertSame($expectedValue, LuPermissionsDataAccess::getUserEffectivePermissionByName($userId, $permissionName));
  15. $this->assertSame($expectedValue, LuPermissionsDataAccess::getUserEffectivePermissionById($userId, $permissionId));
  16. }
  17. public function testPermission0True()
  18. {
  19. static::permissionTest(true, "LU_TEST_SIMPLE_TRUE", 3, 0);
  20. }
  21. public function testPermission0False()
  22. {
  23. static::permissionTest(false, "LU_TEST_SIMPLE_FALSE", 4, 0);
  24. }
  25. public function testPermission0DoesNotExist()
  26. {
  27. static::permissionTest(null, "LU_TEST_DOES_NOT_EXIST", 0, 0);
  28. }
  29. public function testPermissionGroup1True()
  30. {
  31. static::permissionTest(true, "LU_TEST_GROUP_1_TRUE", 5, 1);
  32. }
  33. public function testPermissionGroup1False()
  34. {
  35. static::permissionTest(false, "LU_TEST_GROUP_1_FALSE", 6, 1);
  36. }
  37. public function testPermissionGroup2MultipleGroupsTrue()
  38. {
  39. static::permissionTest(true, "LU_TEST_GROUP_2_TRUE", 7, 2);
  40. }
  41. public function testPermissionGroup3MultipleGroupsTrueFalse()
  42. {
  43. static::permissionTest(false, "LU_TEST_GROUP_3_FALSE", 8, 3);
  44. }
  45. public function testPermissionGroup4MultipleGroupsFalse()
  46. {
  47. static::permissionTest(false, "LU_TEST_GROUP_4_FALSE", 9, 4);
  48. }
  49. public function testPermissionUser5True()
  50. {
  51. static::permissionTest(true, "LU_TEST_USER_5_TRUE", 10, 5);
  52. }
  53. public function testPermissionUser6False()
  54. {
  55. static::permissionTest(false, "LU_TEST_USER_6_FALSE", 11, 6);
  56. }
  57. public function testPermissionGetAll0()
  58. {
  59. $permissions = [
  60. ["id" => 6, "name" =>"LU_TEST_GROUP_1_FALSE", "value" => true],
  61. ["id" => 5, "name" => "LU_TEST_GROUP_1_TRUE", "value" => true],
  62. ["id" => 7, "name" => "LU_TEST_GROUP_2_TRUE", "value" => false],
  63. ["id" => 8, "name" => "LU_TEST_GROUP_3_FALSE", "value" => true],
  64. ["id" => 9, "name" => "LU_TEST_GROUP_4_FALSE", "value" => true],
  65. ["id" => 4, "name" => "LU_TEST_SIMPLE_FALSE", "value" => false],
  66. ["id" => 3, "name" => "LU_TEST_SIMPLE_TRUE", "value" => true],
  67. ["id" => 10, "name" => "LU_TEST_USER_5_TRUE", "value" => false],
  68. ["id" => 11, "name" => "LU_TEST_USER_6_FALSE", "value" => true]];
  69. $this->assertSame($permissions, LuDbo::serializeValue(LuPermissionsDataAccess::getUserEffectivePermissions(0)));
  70. }
  71. public function testPermissionGetAll4()
  72. {
  73. $permissions = [
  74. ["id" => 6, "name" =>"LU_TEST_GROUP_1_FALSE", "value" => true],
  75. ["id" => 5, "name" => "LU_TEST_GROUP_1_TRUE", "value" => true],
  76. ["id" => 7, "name" => "LU_TEST_GROUP_2_TRUE", "value" => false],
  77. ["id" => 8, "name" => "LU_TEST_GROUP_3_FALSE", "value" => true],
  78. ["id" => 9, "name" => "LU_TEST_GROUP_4_FALSE", "value" => false],
  79. ["id" => 4, "name" => "LU_TEST_SIMPLE_FALSE", "value" => false],
  80. ["id" => 3, "name" => "LU_TEST_SIMPLE_TRUE", "value" => true],
  81. ["id" => 10, "name" => "LU_TEST_USER_5_TRUE", "value" => false],
  82. ["id" => 11, "name" => "LU_TEST_USER_6_FALSE", "value" => true]];
  83. $this->assertSame($permissions, LuDbo::serializeValue(LuPermissionsDataAccess::getUserEffectivePermissions(4)));
  84. }
  85. public function testPermissionGetAll6()
  86. {
  87. $permissions = [
  88. ["id" => 6, "name" =>"LU_TEST_GROUP_1_FALSE", "value" => true],
  89. ["id" => 5, "name" => "LU_TEST_GROUP_1_TRUE", "value" => true],
  90. ["id" => 7, "name" => "LU_TEST_GROUP_2_TRUE", "value" => false],
  91. ["id" => 8, "name" => "LU_TEST_GROUP_3_FALSE", "value" => true],
  92. ["id" => 9, "name" => "LU_TEST_GROUP_4_FALSE", "value" => true],
  93. ["id" => 4, "name" => "LU_TEST_SIMPLE_FALSE", "value" => false],
  94. ["id" => 3, "name" => "LU_TEST_SIMPLE_TRUE", "value" => true],
  95. ["id" => 10, "name" => "LU_TEST_USER_5_TRUE", "value" => false],
  96. ["id" => 11, "name" => "LU_TEST_USER_6_FALSE", "value" => false]];
  97. $this->assertSame($permissions, LuDbo::serializeValue(LuPermissionsDataAccess::getUserEffectivePermissions(6)));
  98. }
  99. }