-
Notifications
You must be signed in to change notification settings - Fork 0
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
13 changed files
with
176 additions
and
33 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 was deleted.
Oops, something went wrong.
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,14 @@ | ||
<?php | ||
|
||
namespace Jampire\MoonshineImpersonate\Services\Contracts; | ||
|
||
/** | ||
* @author Dzianis Kotau <me@dzianiskotau.com> | ||
*/ | ||
interface BeImpersonable | ||
{ | ||
/** | ||
* True if user can be impersonated, false otherwise | ||
*/ | ||
public function canBeImpersonated(): bool; | ||
} |
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,14 @@ | ||
<?php | ||
|
||
namespace Jampire\MoonshineImpersonate\Services\Contracts; | ||
|
||
/** | ||
* @author Dzianis Kotau <me@dzianiskotau.com> | ||
*/ | ||
interface Impersonable | ||
{ | ||
/** | ||
* True if user can impersonate, false otherwise | ||
*/ | ||
public function canImpersonate(): bool; | ||
} |
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
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,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Jampire\MoonshineImpersonate\Services\ImpersonateManager; | ||
use Jampire\MoonshineImpersonate\Tests\Stubs\Models\MoonshineUser; | ||
use Jampire\MoonshineImpersonate\Tests\Stubs\Models\User; | ||
|
||
it('can impersonate', function (): void { | ||
$moonShineUser = MoonshineUser::factory()->create(); | ||
|
||
$manager = new ImpersonateManager($moonShineUser); | ||
|
||
expect($manager->canImpersonate()) | ||
->toBeTrue() | ||
; | ||
}); | ||
|
||
it('can be impersonated', function (): void { | ||
$user = User::factory()->create(); | ||
$moonShineUser = MoonshineUser::factory()->create(); | ||
|
||
$manager = new ImpersonateManager($moonShineUser); | ||
|
||
expect($manager->canBeImpersonated($user)) | ||
->toBeTrue() | ||
; | ||
}); | ||
|
||
it('cannot impersonate with no permissions', function (): void { | ||
$moonShineUser = MoonshineUser::factory()->cannotImpersonate()->create(); | ||
|
||
$manager = new ImpersonateManager($moonShineUser); | ||
|
||
expect($manager->canImpersonate()) | ||
->toBeFalse() | ||
; | ||
}); | ||
|
||
it('cannot be impersonated with no permissions', function (): void { | ||
$user = User::factory()->notImpersonated()->create(); | ||
$moonShineUser = MoonshineUser::factory()->create(); | ||
|
||
$manager = new ImpersonateManager($moonShineUser); | ||
|
||
expect($manager->canBeImpersonated($user)) | ||
->toBeFalse() | ||
; | ||
}); |