2018-10-19 12:34:14 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Auth;
|
|
|
|
|
2019-11-17 15:06:00 +03:00
|
|
|
use App\Jobs\Auth\CreatePermission;
|
2020-01-13 11:18:40 +03:00
|
|
|
use App\Models\Auth\Permission;
|
2018-10-19 12:34:14 +03:00
|
|
|
use Tests\Feature\FeatureTestCase;
|
|
|
|
|
|
|
|
class PermissionsTest extends FeatureTestCase
|
|
|
|
{
|
|
|
|
public function testItShouldSeePermissionListPage()
|
|
|
|
{
|
|
|
|
$this->loginAs()
|
|
|
|
->get(route('permissions.index'))
|
|
|
|
->assertStatus(200)
|
|
|
|
->assertSeeText(trans_choice('general.permissions', 2));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItShouldSeePermissionCreatePage()
|
|
|
|
{
|
|
|
|
$this->loginAs()
|
|
|
|
->get(route('permissions.create'))
|
|
|
|
->assertStatus(200)
|
|
|
|
->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.permissions', 1)]));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItShouldCreatePermission()
|
|
|
|
{
|
2020-06-21 01:34:44 +03:00
|
|
|
$request = $this->getRequest();
|
2020-06-21 01:27:20 +03:00
|
|
|
|
2018-10-19 12:34:14 +03:00
|
|
|
$this->loginAs()
|
2020-06-21 01:27:20 +03:00
|
|
|
->post(route('permissions.store'), $request)
|
2019-11-16 10:21:14 +03:00
|
|
|
->assertStatus(200);
|
2018-10-19 12:34:14 +03:00
|
|
|
|
|
|
|
$this->assertFlashLevel('success');
|
2020-06-21 01:27:20 +03:00
|
|
|
|
2020-06-21 01:34:44 +03:00
|
|
|
$this->assertDatabaseHas('permissions', $request);
|
2018-10-19 12:34:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testItShouldSeePermissionUpdatePage()
|
|
|
|
{
|
2020-06-21 01:34:44 +03:00
|
|
|
$request = $this->getRequest();
|
2020-06-21 01:27:20 +03:00
|
|
|
|
|
|
|
$permission = $this->dispatch(new CreatePermission($request));
|
2018-10-19 12:34:14 +03:00
|
|
|
|
|
|
|
$this->loginAs()
|
2020-01-13 10:55:19 +03:00
|
|
|
->get(route('permissions.edit', $permission->id))
|
2018-10-19 12:34:14 +03:00
|
|
|
->assertStatus(200)
|
|
|
|
->assertSee($permission->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItShouldUpdatePermission()
|
|
|
|
{
|
2020-01-13 11:18:40 +03:00
|
|
|
$request = $this->getRequest();
|
2018-10-19 12:34:14 +03:00
|
|
|
|
2019-11-17 15:06:00 +03:00
|
|
|
$permission = $this->dispatch(new CreatePermission($request));
|
2018-10-19 12:34:14 +03:00
|
|
|
|
2020-01-13 17:20:28 +03:00
|
|
|
$request['display_name'] = $this->faker->word;
|
2018-10-19 12:34:14 +03:00
|
|
|
|
|
|
|
$this->loginAs()
|
|
|
|
->patch(route('permissions.update', $permission->id), $request)
|
2020-01-13 17:20:28 +03:00
|
|
|
->assertStatus(200)
|
|
|
|
->assertSee($request['display_name']);
|
2018-10-19 12:34:14 +03:00
|
|
|
|
|
|
|
$this->assertFlashLevel('success');
|
2020-06-21 01:27:20 +03:00
|
|
|
|
2020-06-21 01:34:44 +03:00
|
|
|
$this->assertDatabaseHas('permissions', $request);
|
2018-10-19 12:34:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testItShouldDeletePermission()
|
|
|
|
{
|
2020-06-21 01:34:44 +03:00
|
|
|
$request = $this->getRequest();
|
2020-06-21 01:27:20 +03:00
|
|
|
|
|
|
|
$permission = $this->dispatch(new CreatePermission($request));
|
2018-10-19 12:34:14 +03:00
|
|
|
|
|
|
|
$this->loginAs()
|
|
|
|
->delete(route('permissions.destroy', $permission->id))
|
2019-11-16 10:21:14 +03:00
|
|
|
->assertStatus(200);
|
2018-10-19 12:34:14 +03:00
|
|
|
|
|
|
|
$this->assertFlashLevel('success');
|
|
|
|
|
2020-06-21 01:34:44 +03:00
|
|
|
$this->assertDatabaseMissing('permissions', $request);
|
2018-10-19 12:34:14 +03:00
|
|
|
}
|
|
|
|
|
2020-01-13 11:18:40 +03:00
|
|
|
public function getRequest()
|
2018-10-19 12:34:14 +03:00
|
|
|
{
|
2020-10-14 17:07:59 +03:00
|
|
|
return Permission::factory()->raw();
|
2018-10-19 12:34:14 +03:00
|
|
|
}
|
2020-01-13 10:55:19 +03:00
|
|
|
}
|