Skip to content

Commit

Permalink
Add test to check permission search with asterisk (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniloBenevides authored and vinicius73 committed Aug 31, 2018
1 parent 4061df4 commit 394798d
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
63 changes: 63 additions & 0 deletions tests/Defender/HasDefenderTest.php
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.*'));
}
}
23 changes: 23 additions & 0 deletions tests/stubs/database/seeds/PermissionTableSeeder.php
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' => '']);
}
}

0 comments on commit 394798d

Please sign in to comment.