forked from spatie/laravel-permission
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
63 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -765,4 +765,33 @@ public function it_can_reject_permission_based_on_logged_in_user_guard() | |
'status' => false, | ||
]); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_be_given_a_permission_on_role_when_lazy_loading_is_restricted() | ||
{ | ||
try { | ||
$testRole = app(Role::class)->with('permissions')->get()->first(); | ||
|
||
$testRole->givePermissionTo('edit-articles'); | ||
|
||
$this->assertTrue($testRole->hasPermissionTo('edit-articles')); | ||
} catch (Exception $e) { | ||
$this->fail('Lazy loading detected in the givePermissionTo method: ' . $e->getMessage()); | ||
} | ||
} | ||
|
||
/** @test */ | ||
public function it_can_be_given_a_permission_on_user_when_lazy_loading_is_restricted() | ||
{ | ||
try { | ||
User::create(['email' => '[email protected]']); | ||
$testUser = User::with('permissions')->get()->first(); | ||
|
||
$testUser->givePermissionTo('edit-articles'); | ||
|
||
$this->assertTrue($testUser->hasPermissionTo('edit-articles')); | ||
} catch (Exception $e) { | ||
$this->fail('Lazy loading detected in the givePermissionTo method: ' . $e->getMessage()); | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
namespace Spatie\Permission\Tests; | ||
|
||
use Illuminate\Support\Facades\DB; | ||
use Spatie\Permission\Contracts\Permission; | ||
use Spatie\Permission\Contracts\Role; | ||
use Spatie\Permission\Exceptions\GuardDoesNotMatch; | ||
use Spatie\Permission\Exceptions\RoleDoesNotExist; | ||
|
@@ -856,4 +857,33 @@ public function it_does_not_detach_roles_when_user_soft_deleting() | |
|
||
$this->assertTrue($user->hasRole('testRole')); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_be_given_a_role_on_permission_when_lazy_loading_is_restricted() | ||
{ | ||
try { | ||
$testPermission = app(Permission::class)->with('roles')->get()->first(); | ||
|
||
$testPermission->assignRole('testRole'); | ||
|
||
$this->assertTrue($testPermission->hasRole('testRole')); | ||
} catch (Exception $e) { | ||
$this->fail('Lazy loading detected in the givePermissionTo method: ' . $e->getMessage()); | ||
} | ||
} | ||
|
||
/** @test */ | ||
public function it_can_be_given_a_role_on_user_when_lazy_loading_is_restricted() | ||
{ | ||
try { | ||
User::create(['email' => '[email protected]']); | ||
$user = User::with('roles')->get()->first(); | ||
$user->assignRole('testRole'); | ||
|
||
$this->assertTrue($user->hasRole('testRole')); | ||
} catch (Exception $e) { | ||
$this->fail('Lazy loading detected in the givePermissionTo method: ' . $e->getMessage()); | ||
} | ||
} | ||
|
||
} |