permission factory
This commit is contained in:
parent
35795b4422
commit
489b459e13
16
database/factories/Permission.php
Normal file
16
database/factories/Permission.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Auth\Permission;
|
||||||
|
use Faker\Generator as Faker;
|
||||||
|
|
||||||
|
$factory->define(Permission::class, function (Faker $faker) {
|
||||||
|
$map = ['Create', 'Read', 'Update', 'Delete'];
|
||||||
|
|
||||||
|
$prefix = $faker->randomElement($map);
|
||||||
|
|
||||||
|
return [
|
||||||
|
'name' => strtolower($prefix) . '-' . strtolower($faker->word) . '-' . strtolower($faker->word),
|
||||||
|
'display_name' => $prefix . ' ' . $faker->text(5),
|
||||||
|
'description' => $prefix . ' ' . $faker->text(5),
|
||||||
|
];
|
||||||
|
});
|
@ -3,6 +3,7 @@
|
|||||||
namespace Tests\Feature\Auth;
|
namespace Tests\Feature\Auth;
|
||||||
|
|
||||||
use App\Jobs\Auth\CreatePermission;
|
use App\Jobs\Auth\CreatePermission;
|
||||||
|
use App\Models\Auth\Permission;
|
||||||
use Tests\Feature\FeatureTestCase;
|
use Tests\Feature\FeatureTestCase;
|
||||||
|
|
||||||
class PermissionsTest extends FeatureTestCase
|
class PermissionsTest extends FeatureTestCase
|
||||||
@ -27,7 +28,7 @@ class PermissionsTest extends FeatureTestCase
|
|||||||
public function testItShouldCreatePermission()
|
public function testItShouldCreatePermission()
|
||||||
{
|
{
|
||||||
$this->loginAs()
|
$this->loginAs()
|
||||||
->post(route('permissions.store'), $this->getPermissionRequest())
|
->post(route('permissions.store'), $this->getRequest())
|
||||||
->assertStatus(200);
|
->assertStatus(200);
|
||||||
|
|
||||||
$this->assertFlashLevel('success');
|
$this->assertFlashLevel('success');
|
||||||
@ -35,7 +36,7 @@ class PermissionsTest extends FeatureTestCase
|
|||||||
|
|
||||||
public function testItShouldSeePermissionUpdatePage()
|
public function testItShouldSeePermissionUpdatePage()
|
||||||
{
|
{
|
||||||
$permission = $this->dispatch(new CreatePermission($this->getPermissionRequest()));
|
$permission = $this->dispatch(new CreatePermission($this->getRequest()));
|
||||||
|
|
||||||
$this->loginAs()
|
$this->loginAs()
|
||||||
->get(route('permissions.edit', $permission->id))
|
->get(route('permissions.edit', $permission->id))
|
||||||
@ -45,7 +46,7 @@ class PermissionsTest extends FeatureTestCase
|
|||||||
|
|
||||||
public function testItShouldUpdatePermission()
|
public function testItShouldUpdatePermission()
|
||||||
{
|
{
|
||||||
$request = $this->getPermissionRequest();
|
$request = $this->getRequest();
|
||||||
|
|
||||||
$permission = $this->dispatch(new CreatePermission($request));
|
$permission = $this->dispatch(new CreatePermission($request));
|
||||||
|
|
||||||
@ -60,7 +61,7 @@ class PermissionsTest extends FeatureTestCase
|
|||||||
|
|
||||||
public function testItShouldDeletePermission()
|
public function testItShouldDeletePermission()
|
||||||
{
|
{
|
||||||
$permission = $this->dispatch(new CreatePermission($this->getPermissionRequest()));
|
$permission = $this->dispatch(new CreatePermission($this->getRequest()));
|
||||||
|
|
||||||
$this->loginAs()
|
$this->loginAs()
|
||||||
->delete(route('permissions.destroy', $permission->id))
|
->delete(route('permissions.destroy', $permission->id))
|
||||||
@ -70,12 +71,8 @@ class PermissionsTest extends FeatureTestCase
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getPermissionRequest()
|
public function getRequest()
|
||||||
{
|
{
|
||||||
return [
|
return factory(Permission::class)->raw();
|
||||||
'name' => $this->faker->text(5),
|
|
||||||
'display_name' => $this->faker->text(5),
|
|
||||||
'description' => $this->faker->text(5),
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user