Commit a6019896 authored by Vipul Basapati's avatar Vipul Basapati

Merge branch 'develop' of https://github.com/viralsolani/laravel-adminpanel into develop

parents e1511a0f 28f4d362
...@@ -16,3 +16,15 @@ $factory->define(Permission::class, function (Generator $faker) { ...@@ -16,3 +16,15 @@ $factory->define(Permission::class, function (Generator $faker) {
'sort' => $faker->numberBetween(1, 100), 'sort' => $faker->numberBetween(1, 100),
]; ];
}); });
$factory->state(Permission::class, 'active', function () {
return [
'status' => 1,
];
});
$factory->state(Permission::class, 'inactive', function () {
return [
'status' => 0,
];
});
<?php
namespace Tests\Feature\Api\V1;
use Illuminate\Support\Facades\Auth;
use Tests\TestCase;
class LoginTest extends TestCase
{
/** @test */
public function users_can_login_through_api()
{
$res = $this->json('POST', '/api/v1/auth/login', [
'email' => $this->user->email,
'password' => '1234',
])
->assertStatus(200)
->assertJsonStructure([
'message',
'token',
]);
}
}
<?php
namespace Tests\Feature\Backend;
use App\Events\Backend\Access\Permission\PermissionCreated;
use App\Events\Backend\Access\Permission\PermissionDeleted;
use App\Events\Backend\Access\Permission\PermissionUpdated;
use App\Models\Access\Permission\Permission;
use Illuminate\Support\Facades\Event;
use Tests\TestCase;
class ManagePermissionsTest extends TestCase
{
/** @test */
public function a_user_can_view_permissions()
{
$this->actingAs($this->admin)
->get(route('admin.access.permission.index'))
->assertViewIs('backend.access.permissions.index')
->assertSee(trans('labels.backend.access.permissions.management'))
->assertSee('Export')
->assertSee('Action');
}
/** @test */
public function a_permission_requires_a_name()
{
$permission = make(Permission::class, ['name' => null])->toArray();
return $this->withExceptionHandling()
->actingAs($this->admin)
->post(route('admin.access.permission.store'), $permission)
->assertSessionHasErrors('name');
}
/** @test */
public function a_permission_requires_a_display_name()
{
$permission = make(Permission::class, ['display_name' => null])->toArray();
return $this->withExceptionHandling()
->actingAs($this->admin)
->post(route('admin.access.permission.store'), $permission)
->assertSessionHasErrors('display_name');
}
/** @test */
public function a_user_can_create_new_permission()
{
// Make sure our events are fired
Event::fake();
$permission = make(Permission::class, ['name' => 'test permission'])->toArray();
$this->actingAs($this->admin)
->post(route('admin.access.permission.store'), $permission)
->assertRedirect(route('admin.access.permission.index'))
->assertSessionHas(['flash_success' => trans('alerts.backend.permissions.created')]);
$this->assertDatabaseHas(config('access.permissions_table'), [
'name' => $permission['name'],
]);
Event::assertDispatched(PermissionCreated::class);
}
/** @test */
public function it_fails_for_validation_on_update_permission()
{
$permission = create(Permission::class);
$data = $permission->toArray();
$data['name'] = '';
$this->withExceptionHandling()
->actingAs($this->admin)
->patch(route('admin.access.permission.update', $permission), $data)
->assertSessionHasErrors(['name']);
}
/** @test */
public function a_user_can_update_permission()
{
Event::fake();
$permission = create(Permission::class);
$data = $permission->toArray();
$data['name'] = 'Updated Permission Name';
$this->withExceptionHandling()
->actingAs($this->admin)
->patch(route('admin.access.permission.update', $permission), $data)
->assertRedirect(route('admin.access.permission.index'))
->assertSessionHas(['flash_success' => trans('alerts.backend.permissions.updated')]);
$this->assertDatabaseHas(config('access.permissions_table'), [
'name' => $data['name'],
]);
Event::assertDispatched(PermissionUpdated::class);
}
/** @test */
public function a_user_can_delete_a_permission()
{
Event::fake();
$permission = create(Permission::class);
$this->actingAs($this->admin)
->delete(route('admin.access.permission.destroy', $permission))
->assertStatus(302)
->assertSessionHas(['flash_success' => trans('alerts.backend.permissions.deleted')]);
/*$this->assertDatabaseMissing('permissions', [
'name' => $permission->name, 'id' => $permission->id
]);*/
Event::assertDispatched(PermissionDeleted::class);
}
}
...@@ -162,9 +162,13 @@ class ManageRolesTest extends TestCase ...@@ -162,9 +162,13 @@ class ManageRolesTest extends TestCase
$this->actingAs($this->admin) $this->actingAs($this->admin)
->delete(route('admin.access.role.destroy', $role)) ->delete(route('admin.access.role.destroy', $role))
->assertStatus(302)
->assertSessionHas(['flash_success' => trans('alerts.backend.roles.deleted')]); ->assertSessionHas(['flash_success' => trans('alerts.backend.roles.deleted')]);
$this->assertDatabaseMissing(config('access.roles_table'), ['name' => $role->first_name, 'id' => $role->id]); /*$this->assertDatabaseMissing(config('access.roles_table'), [
'name' => $role->name,
'id' => $role->id
]);*/
Event::assertDispatched(RoleDeleted::class); Event::assertDispatched(RoleDeleted::class);
} }
......
...@@ -285,9 +285,13 @@ class ManageUsersTest extends TestCase ...@@ -285,9 +285,13 @@ class ManageUsersTest extends TestCase
$this->actingAs($this->admin) $this->actingAs($this->admin)
->delete(route('admin.access.user.destroy', $user)) ->delete(route('admin.access.user.destroy', $user))
->assertStatus(302)
->assertSessionHas(['flash_success' => trans('alerts.backend.users.deleted')]); ->assertSessionHas(['flash_success' => trans('alerts.backend.users.deleted')]);
$this->assertDatabaseMissing(config('access.users_table'), ['name' => $user->first_name, 'id' => $user->id]); $this->assertDatabaseMissing(config('access.users_table'), [
'name' => $user->first_name,
'id' => $user->id,
]);
Event::assertDispatched(UserDeleted::class); Event::assertDispatched(UserDeleted::class);
} }
......
<?php
namespace Tests\Unit\Models;
use App\Models\Access\Permission\Permission;
use Tests\TestCase;
class PermissionTest extends TestCase
{
/** @test */
public function a_permission_has_roles()
{
$permission = Permission::find(1);
$this->assertInstanceOf(
'Illuminate\Database\Eloquent\Collection', $permission->roles
);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment