Created
February 11, 2020 10:29
-
-
Save sasin91/6f3e51555e1b7c34d62cd2d9347dd826 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace Tests\Unit; | |
| use App\User; | |
| use App\Enums\RBAC; | |
| use Tests\TestCase; | |
| use Illuminate\Foundation\Testing\WithFaker; | |
| use Illuminate\Foundation\Testing\RefreshDatabase; | |
| class RBACTest extends TestCase | |
| { | |
| public function test_a_role_name_implicitly_grants_a_set_of_permissions() | |
| { | |
| $member = new User([ | |
| 'permissions' => 0, | |
| 'role' => 'member' | |
| ]); | |
| self::assertEquals(RBAC::Member, $member->permissions); | |
| } | |
| public function test_a_user_without_a_role_only_have_the_permissions_theyre_explicitly_granted() | |
| { | |
| $user = new User([ | |
| 'permissions' => $permission = RBAC::getRandomValue() | |
| ]); | |
| self::assertEquals($permission, $user->permissions); | |
| } | |
| public function test_a_user_with_a_role_plus_explicit_permissions() | |
| { | |
| $member = new User([ | |
| 'permissions' => $grants = RBAC::flags([RBAC::CreateForumCategories, RBAC::EditForumCategories])->value, | |
| 'role' => 'member' | |
| ]); | |
| self::assertEquals(RBAC::Member | $grants, $member->permissions); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment