-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test to check permission search with asterisk (#137)
- Loading branch information
1 parent
4061df4
commit 394798d
Showing
2 changed files
with
86 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
namespace Artesaos\Defender\Testing; | ||
|
||
use Artesaos\Defender\Permission; | ||
|
||
/** | ||
* Class HasDefenderTest. | ||
*/ | ||
class HasDefenderTest extends AbstractTestCase | ||
{ | ||
/** | ||
* Array of service providers. | ||
* @var array | ||
*/ | ||
protected $providers = [ | ||
'Artesaos\Defender\Providers\DefenderServiceProvider', | ||
]; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->migrate([ | ||
$this->stubsPath('database/migrations'), | ||
$this->resourcePath('migrations'), | ||
]); | ||
|
||
$this->seed([ | ||
'UserTableSeeder', | ||
'PermissionTableSeeder', | ||
]); | ||
} | ||
|
||
public function testUserCanFindPermissionWithAsterisk() | ||
{ | ||
$user = User::find(1)->first(); | ||
|
||
$permission_create = Permission::find(1); | ||
$permission_delete = Permission::find(2); | ||
|
||
$user->attachPermission($permission_create); | ||
$user->attachPermission($permission_delete); | ||
|
||
$this->assertTrue($user->hasPermission('user.*')); | ||
} | ||
|
||
public function testUserCanNotFindPermissionWithAsterisk() | ||
{ | ||
$user = User::find(1)->first(); | ||
|
||
$permission_create = Permission::find(1); | ||
$permission_delete = Permission::find(2); | ||
|
||
$user->attachPermission($permission_create); | ||
$user->attachPermission($permission_delete); | ||
|
||
$this->assertFalse($user->hasPermission('admin.*')); | ||
} | ||
} |
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,23 @@ | ||
<?php | ||
|
||
namespace Artesaos\Defender\Testing; | ||
|
||
use Illuminate\Database\Seeder; | ||
use Artesaos\Defender\Permission; | ||
|
||
/** | ||
* Class PermissionTableSeeder. | ||
*/ | ||
class PermissionTableSeeder extends Seeder | ||
{ | ||
/** | ||
* Run the seeder. | ||
*/ | ||
public function run() | ||
{ | ||
Permission::unguard(); | ||
|
||
Permission::create(['name' => 'user.create', 'readable_name' => '']); | ||
Permission::create(['name' => 'user.delete', 'readable_name' => '']); | ||
} | ||
} |