-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1018 from spatie/1017-tests
Add tests for #1017
- Loading branch information
Showing
2 changed files
with
27 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -339,6 +339,32 @@ public function it_can_scope_users_using_an_object() | |
$this->assertEquals($scopedUsers3->count(), 1); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_scope_against_a_specific_guard() | ||
{ | ||
$user1 = User::create(['email' => '[email protected]']); | ||
$user2 = User::create(['email' => '[email protected]']); | ||
$user1->assignRole('testRole'); | ||
$user2->assignRole('testRole2'); | ||
|
||
$scopedUsers1 = User::role('testRole', 'web')->get(); | ||
|
||
$this->assertEquals($scopedUsers1->count(), 1); | ||
|
||
$user3 = Admin::create(['email' => '[email protected]']); | ||
$user4 = Admin::create(['email' => '[email protected]']); | ||
$user5 = Admin::create(['email' => '[email protected]']); | ||
$testAdminRole2 = app(Role::class)->create(['name' => 'testAdminRole2', 'guard_name' => 'admin']); | ||
$user3->assignRole($this->testAdminRole); | ||
$user4->assignRole($this->testAdminRole); | ||
$user5->assignRole($testAdminRole2); | ||
$scopedUsers2 = Admin::role('testAdminRole', 'admin')->get(); | ||
$scopedUsers3 = Admin::role('testAdminRole2', 'admin')->get(); | ||
|
||
$this->assertEquals($scopedUsers2->count(), 2); | ||
$this->assertEquals($scopedUsers3->count(), 1); | ||
} | ||
|
||
/** @test */ | ||
public function it_throws_an_exception_when_trying_to_scope_a_role_from_another_guard() | ||
{ | ||
|