-
-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New flat auth tests. Inclues refactoring how user entity gets permiss…
…ions. A couple of layers of caching on permissions. And a new ->can('fly') command on the entity.
- Loading branch information
1 parent
58c46e8
commit 136098f
Showing
8 changed files
with
558 additions
and
57 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
use Myth\Auth\Entities\User; | ||
use ModuleTests\Support\AuthTestCase; | ||
|
||
class UserTest extends AuthTestCase | ||
{ | ||
public function testGetPermissionsThroughUser() | ||
{ | ||
$user = $this->createUser(); | ||
$permission1 = $this->createPermission(['name' => 'first']); | ||
$permission2 = $this->createPermission(['name' => 'second']); | ||
|
||
$this->hasInDatabase('auth_users_permissions', [ | ||
'user_id' => $user->id, | ||
'permission_id' => $permission1->id | ||
]); | ||
$this->hasInDatabase('auth_users_permissions', [ | ||
'user_id' => $user->id, | ||
'permission_id' => $permission2->id | ||
]); | ||
|
||
$expected = [ | ||
$permission1->id => $permission1->name, | ||
$permission2->id => $permission2->name, | ||
]; | ||
|
||
$this->assertEquals($expected, $user->permissions); | ||
} | ||
|
||
public function testGetPermissionsThroughGroup() | ||
{ | ||
$user = $this->createUser(); | ||
$group = $this->createGroup(); | ||
$permission = $this->createPermission(['name' => 'first']); | ||
|
||
$this->hasInDatabase('auth_groups_permissions', [ | ||
'group_id' => $group->id, | ||
'permission_id' => $permission->id | ||
]); | ||
$this->hasInDatabase('auth_groups_users', [ | ||
'user_id' => $user->id, | ||
'group_id' => $group->id | ||
]); | ||
|
||
$expected = [ | ||
$permission->id => $permission->name, | ||
]; | ||
|
||
$this->assertEquals($expected, $user->permissions); | ||
} | ||
|
||
public function testCan() | ||
{ | ||
$user = $this->createUser(); | ||
$permission = $this->createPermission(); | ||
$this->hasInDatabase('auth_users_permissions', [ | ||
'user_id' => $user->id, | ||
'permission_id' => $permission->id | ||
]); | ||
|
||
$this->assertTrue($user->can($permission->name)); | ||
$this->assertFalse($user->can('jump for joy')); | ||
} | ||
} |
This file contains 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
Oops, something went wrong.