Skip to content

Commit

Permalink
feat(Roles): Support for casting role names to enums
Browse files Browse the repository at this point in the history
  • Loading branch information
gajosadrian committed Feb 19, 2024
1 parent 3036777 commit 8aac412
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/HasRolesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ public function it_can_assign_and_remove_a_role_using_enums()
$this->assertFalse($this->testUser->hasRole($enum2));
$this->assertFalse($this->testUser->hasRole($enum3));
$this->assertFalse($this->testUser->hasRole($enum4));
$this->assertFalse($this->testUser->hasRole('user-manager'));
$this->assertFalse($this->testUser->hasRole('writer'));
$this->assertFalse($this->testUser->hasRole('casted_enum-1'));
$this->assertFalse($this->testUser->hasRole('casted_enum-2'));

$this->testUser->assignRole($enum1);
$this->testUser->assignRole($enum2);
Expand All @@ -70,10 +74,16 @@ public function it_can_assign_and_remove_a_role_using_enums()
$this->assertTrue($this->testUser->hasRole($enum3));
$this->assertTrue($this->testUser->hasRole($enum4));

$this->assertTrue($this->testUser->hasRole([$enum1, 'writer']));
$this->assertTrue($this->testUser->hasRole([$enum3, 'casted_enum-2']));

$this->assertTrue($this->testUser->hasAllRoles([$enum1, $enum2, $enum3, $enum4]));
$this->assertTrue($this->testUser->hasAllRoles(['user-manager', 'writer', 'casted_enum-1', 'casted_enum-2']));
$this->assertFalse($this->testUser->hasAllRoles([$enum1, $enum2, $enum3, $enum4, 'not exist']));
$this->assertFalse($this->testUser->hasAllRoles(['user-manager', 'writer', 'casted_enum-1', 'casted_enum-2', 'not exist']));

$this->assertTrue($this->testUser->hasExactRoles([$enum4, $enum3, $enum2, $enum1]));
$this->assertTrue($this->testUser->hasExactRoles(['user-manager', 'writer', 'casted_enum-1', 'casted_enum-2']));

$this->testUser->removeRole($enum1);

Expand Down

0 comments on commit 8aac412

Please sign in to comment.