Commit cc559d77 authored by Viral Solani's avatar Viral Solani

remove unwanted test cases

parent fc135fb9
<?php
use Tests\BrowserKitTestCase;
/**
* Class AccessHelperTest.
*/
class AccessHelperTest extends BrowserKitTestCase
{
public function testAccessUser()
{
$this->actingAs($this->user);
$this->assertEquals(auth()->user(), access()->user());
}
public function testAccessGuest()
{
$this->assertEquals(auth()->guest(), access()->guest());
}
public function testAccessLogout()
{
$this->actingAs($this->user);
$this->assertFalse(access()->guest());
access()->logout();
$this->assertTrue(access()->guest());
}
public function testAccessGetsUserId()
{
$this->actingAs($this->user);
$this->assertEquals(auth()->id(), access()->id());
}
public function testAccessLogsUserInById()
{
access()->loginUsingId(3);
$this->assertEquals(auth()->user(), access()->user());
}
public function testAccessHasRole()
{
$this->actingAs($this->executive);
$this->assertTrue(access()->hasRole('Executive'));
$this->assertFalse(access()->hasRole('Administrator'));
$this->assertTrue(access()->hasRole(2));
$this->assertFalse(access()->hasRole(1));
}
public function testAdminHasAllRoles()
{
$this->actingAs($this->admin);
$this->assertTrue(access()->hasRole('Administrator'));
$this->assertTrue(access()->hasRole('Non-Existing Role'));
$this->assertTrue(access()->hasRole(1));
$this->assertTrue(access()->hasRole(123));
}
public function testAccessHasRoles()
{
$this->actingAs($this->executive);
$this->assertTrue(access()->hasRoles(['Executive', 'User']));
$this->assertTrue(access()->hasRoles([2, 3]));
}
public function testAccessHasRolesNeedsAll()
{
$this->actingAs($this->executive);
$this->assertFalse(access()->hasRoles(['Executive', 'User'], true));
$this->assertFalse(access()->hasRoles([2, 3], true));
}
public function testAccessAllow()
{
$this->actingAs($this->executive);
$this->assertTrue(access()->allow('view-backend'));
$this->assertTrue(access()->allow(1));
}
public function testAdminHasAllAccess()
{
$this->actingAs($this->admin);
$this->assertTrue(access()->allow('view-backend'));
$this->assertTrue(access()->allow('view-something-that-doesnt-exist'));
$this->assertTrue(access()->allow(1));
$this->assertTrue(access()->allow(123));
}
public function testAccessAllowMultiple()
{
$this->actingAs($this->executive);
$this->assertTrue(access()->allowMultiple(['view-backend']));
$this->assertTrue(access()->allowMultiple([1]));
}
public function testAccessAllowMultipleNeedsAll()
{
$this->actingAs($this->executive);
$this->assertTrue(access()->allowMultiple(['view-backend'], true));
$this->assertTrue(access()->allowMultiple([1], true));
}
public function testAccessHasPermission()
{
$this->actingAs($this->executive);
$this->assertTrue(access()->hasPermission('view-backend'));
$this->assertTrue(access()->hasPermission(1));
}
public function testAccessHasPermissions()
{
$this->actingAs($this->executive);
$this->assertTrue(access()->hasPermissions(['view-backend']));
$this->assertTrue(access()->hasPermissions([1]));
}
public function testAccessHasPermissionsNeedsAll()
{
$this->actingAs($this->executive);
$this->assertTrue(access()->hasPermissions(['view-backend'], true));
$this->assertTrue(access()->hasPermissions([1], true));
}
}
<?php
use Tests\BrowserKitTestCase;
/**
* Class AccessRepositoryTest.
*/
class AccessRepositoryTest extends BrowserKitTestCase
{
public function testGetUsersByPermissionUsingName()
{
$results = app()->make(\App\Repositories\Backend\Access\User\UserRepository::class)
->getByPermission('view-backend')
->toArray();
$this->assertCount(1, $results);
$this->assertArraySubset(['first_name' => $this->executive->first_name], $results[0]);
$this->assertArraySubset(['last_name' => $this->executive->last_name], $results[0]);
}
public function testGetUsersByPermissionsUsingNames()
{
$this->userRole->permissions()->sync([1]);
$results = app()->make(\App\Repositories\Backend\Access\User\UserRepository::class)
->getByPermission(['view-backend'])
->toArray();
$this->assertCount(2, $results);
$this->assertArraySubset(['first_name' => $this->executive->first_name], $results[0]);
$this->assertArraySubset(['first_name' => $this->user->first_name], $results[1]);
}
public function testGetUsersByPermissionUsingId()
{
$results = app()->make(\App\Repositories\Backend\Access\User\UserRepository::class)
->getByPermission(1, 'id')
->toArray();
$this->assertCount(1, $results);
$this->assertArraySubset(['first_name' => $this->executive->first_name], $results[0]);
}
public function testGetUsersByPermissionsUsingIds()
{
$this->userRole->permissions()->sync([1]);
$results = app()->make(\App\Repositories\Backend\Access\User\UserRepository::class)
->getByPermission([1], 'id')
->toArray();
$this->assertCount(2, $results);
$this->assertArraySubset(['first_name' => $this->executive->first_name], $results[0]);
$this->assertArraySubset(['first_name' => $this->user->first_name], $results[1]);
}
public function testGetUsersByRoleUsingName()
{
$results = app()->make(\App\Repositories\Backend\Access\User\UserRepository::class)
->getByRole('User')
->toArray();
$this->assertCount(1, $results);
$this->assertArraySubset(['first_name' => $this->user->first_name], $results[0]);
}
public function testGetUsersByRolesUsingNames()
{
$results = app()->make(\App\Repositories\Backend\Access\User\UserRepository::class)
->getByRole(['User', 'Executive'])
->toArray();
$this->assertCount(2, $results);
$this->assertArraySubset(['first_name' => $this->executive->first_name], $results[0]);
$this->assertArraySubset(['first_name' => $this->user->first_name], $results[1]);
}
public function testGetUsersByRoleUsingId()
{
$results = app()->make(\App\Repositories\Backend\Access\User\UserRepository::class)
->getByRole(1, 'id')
->toArray();
$this->assertCount(1, $results);
$this->assertArraySubset(['first_name' => $this->admin->first_name], $results[0]);
}
public function testGetUsersByRolesUsingIds()
{
$results = app()->make(\App\Repositories\Backend\Access\User\UserRepository::class)
->getByRole([1, 3], 'id')
->toArray();
$this->assertCount(2, $results);
$this->assertArraySubset(['first_name' => $this->admin->first_name], $results[0]);
$this->assertArraySubset(['first_name' => $this->user->first_name], $results[1]);
}
}
<?php
use App\Models\Access\Permission\Permission;
use Tests\BrowserKitTestCase;
class RolePermissionTest extends BrowserKitTestCase
{
public function testSavePermissionsToRole()
{
$this->notSeeInDatabase(config('access.permission_role_table'), ['permission_id' => 1, 'role_id' => $this->userRole->id]);
$this->userRole->permissions()->sync([1]);
$this->seeInDatabase(config('access.permission_role_table'), ['permission_id' => 1, 'role_id' => $this->userRole->id]);
}
public function testEmptyPermissionsFromRole()
{
$this->notSeeInDatabase(config('access.permission_role_table'), ['permission_id' => 1, 'role_id' => $this->userRole->id]);
$this->userRole->permissions()->sync([1]);
$this->seeInDatabase(config('access.permission_role_table'), ['permission_id' => 1, 'role_id' => $this->userRole->id]);
$this->userRole->permissions()->sync([]);
$this->notSeeInDatabase(config('access.permission_role_table'), ['permission_id' => 1, 'role_id' => $this->userRole->id]);
}
public function testAttachPermissionToRoleById()
{
$this->notSeeInDatabase(config('access.permission_role_table'), ['permission_id' => 1, 'role_id' => $this->userRole->id]);
$this->userRole->attachPermission(1);
$this->seeInDatabase(config('access.permission_role_table'), ['permission_id' => 1, 'role_id' => $this->userRole->id]);
}
public function testAttachPermissionToRoleByObject()
{
$this->notSeeInDatabase(config('access.permission_role_table'), ['permission_id' => 1, 'role_id' => $this->userRole->id]);
$this->userRole->attachPermission(Permission::findOrFail(1));
$this->seeInDatabase(config('access.permission_role_table'), ['permission_id' => 1, 'role_id' => $this->userRole->id]);
}
public function testDetachPermissionFromRoleById()
{
$this->notSeeInDatabase(config('access.permission_role_table'), ['permission_id' => 1, 'role_id' => $this->userRole->id]);
$this->userRole->attachPermission(1);
$this->seeInDatabase(config('access.permission_role_table'), ['permission_id' => 1, 'role_id' => $this->userRole->id]);
$this->userRole->detachPermission(1);
$this->notSeeInDatabase(config('access.permission_role_table'), ['permission_id' => 1, 'role_id' => $this->userRole->id]);
}
public function testDetachPermissionFromRoleByObject()
{
$this->notSeeInDatabase(config('access.permission_role_table'), ['permission_id' => 1, 'role_id' => $this->userRole->id]);
$this->userRole->attachPermission(Permission::findOrFail(1));
$this->seeInDatabase(config('access.permission_role_table'), ['permission_id' => 1, 'role_id' => $this->userRole->id]);
$this->userRole->detachPermission(Permission::findOrFail(1));
$this->notSeeInDatabase(config('access.permission_role_table'), ['permission_id' => 1, 'role_id' => $this->userRole->id]);
}
public function testAttachPermissionsToRoleById()
{
$this->notSeeInDatabase(config('access.permission_role_table'), ['permission_id' => 1, 'role_id' => $this->userRole->id]);
$this->userRole->attachPermissions([1]);
$this->seeInDatabase(config('access.permission_role_table'), ['permission_id' => 1, 'role_id' => $this->userRole->id]);
}
public function testAttachPermissionsToRoleByObject()
{
$this->notSeeInDatabase(config('access.permission_role_table'), ['permission_id' => 1, 'role_id' => $this->userRole->id]);
$this->userRole->attachPermissions([Permission::findOrFail(1)]);
$this->seeInDatabase(config('access.permission_role_table'), ['permission_id' => 1, 'role_id' => $this->userRole->id]);
}
public function testDetachPermissionsFromRoleById()
{
$this->notSeeInDatabase(config('access.permission_role_table'), ['permission_id' => 1, 'role_id' => $this->userRole->id]);
$this->userRole->attachPermissions([1]);
$this->seeInDatabase(config('access.permission_role_table'), ['permission_id' => 1, 'role_id' => $this->userRole->id]);
$this->userRole->detachPermissions([1]);
$this->notSeeInDatabase(config('access.permission_role_table'), ['permission_id' => 1, 'role_id' => $this->userRole->id]);
}
public function testDetachPermissionsFromRoleByObject()
{
$this->notSeeInDatabase(config('access.permission_role_table'), ['permission_id' => 1, 'role_id' => $this->userRole->id]);
$this->userRole->attachPermissions([Permission::findOrFail(1)]);
$this->seeInDatabase(config('access.permission_role_table'), ['permission_id' => 1, 'role_id' => $this->userRole->id]);
$this->userRole->detachPermissions([Permission::findOrFail(1)]);
$this->notSeeInDatabase(config('access.permission_role_table'), ['permission_id' => 1, 'role_id' => $this->userRole->id]);
}
}
<?php
use Tests\BrowserKitTestCase;
/**
* Class UserAccessTest.
*/
class UserAccessTest extends BrowserKitTestCase
{
public function testUserCantAccessAdminDashboard()
{
$this->visit('/')
->actingAs($this->user)
->visit('/admin/dashboard')
->seePageIs('/')
->see('You do not have access to do that.');
}
public function testExecutiveCanAccessAdminDashboard()
{
$this->visit('/')
->actingAs($this->executive)
->visit('/admin/dashboard')
->seePageIs('/admin/dashboard')
->see($this->executive->first_nam);
}
/*public function testExecutiveCantAccessManageRoles()
{
$this->visit('/')
->actingAs($this->executive)
->visit('/admin/dashboard')
->seePageIs('/admin/dashboard')
->visit('/admin/access/role')
->seePageIs('/')
->see('You do not have access to do that.');
}*/
}
<?php
use Tests\BrowserKitTestCase;
/**
* Class UserRoleTest.
*/
class UserRoleTest extends BrowserKitTestCase
{
public function testAttachRoleToUserById()
{
$this->notSeeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
$this->user->attachRole($this->adminRole->id);
$this->seeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
}
public function testAttachRoleToUserByObject()
{
$this->notSeeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
$this->user->attachRole($this->adminRole);
$this->seeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
}
public function testDetachRoleByIdFromUser()
{
$this->notSeeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
$this->user->attachRole($this->adminRole->id);
$this->seeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
$this->user->detachRole($this->adminRole->id);
$this->notSeeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
}
public function testDetachRoleByObjectFromUser()
{
$this->notSeeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
$this->user->attachRole($this->adminRole);
$this->seeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
$this->user->detachRole($this->adminRole);
$this->notSeeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
}
public function testAttachRolesByIdToUser()
{
$this->notSeeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
$this->notSeeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->executiveRole->id]);
$this->user->attachRoles([$this->adminRole->id, $this->executiveRole->id]);
$this->seeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
$this->seeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->executiveRole->id]);
}
public function testAttachRolesByObjectToUser()
{
$this->notSeeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
$this->notSeeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->executiveRole->id]);
$this->user->attachRoles([$this->adminRole, $this->executiveRole]);
$this->seeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
$this->seeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->executiveRole->id]);
}
public function testDetachRolesByIdFromUser()
{
$this->notSeeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
$this->notSeeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->executiveRole->id]);
$this->user->attachRoles([$this->adminRole->id, $this->executiveRole->id]);
$this->seeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
$this->seeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->executiveRole->id]);
$this->user->detachRoles([$this->adminRole->id, $this->executiveRole->id]);
$this->notSeeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
$this->notSeeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->executiveRole->id]);
}
public function testDetachRolesByObjectFromUser()
{
$this->notSeeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
$this->notSeeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->executiveRole->id]);
$this->user->attachRoles([$this->adminRole, $this->executiveRole]);
$this->seeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
$this->seeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->executiveRole->id]);
$this->user->detachRoles([$this->adminRole, $this->executiveRole]);
$this->notSeeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->adminRole->id]);
$this->notSeeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => $this->executiveRole->id]);
}
}
<?php
use App\Events\Backend\Access\Role\RoleCreated;
use App\Events\Backend\Access\Role\RoleDeleted;
use App\Events\Backend\Access\Role\RoleUpdated;
use App\Models\Access\Role\Role;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Event;
use Tests\BrowserKitTestCase;
/**
* Class RoleFormTest.
*/
class RoleFormTest extends BrowserKitTestCase
{
public function testCreateRoleRequiredFieldsAll()
{
// All Permissions
$this->actingAs($this->admin)
->visit('/admin/access/role/create')
->type('', 'name')
->press('Create')
->seePageIs('/admin/access/role/create')
->see('The name field is required.');
}
public function testCreateRoleRequiredFieldsSpecificPermissions()
{
// Custom Permissions
$this->actingAs($this->admin)
->visit('/admin/access/role/create')
->type('Test Role', 'name')
->select('custom', 'associated_permissions')
->press('Create')
->seePageIs('/admin/access/role/create')
->see('You must select at least one permission for this role.');
}
public function testCreateRoleFormAll()
{
// Make sure our events are fired
Event::fake();
// Test create with all permissions
$this->actingAs($this->admin)
->visit('/admin/access/role/create')
->type('Test Role', 'name')
->type('999', 'sort')
->press('Create')
->seePageIs('/admin/access/role')
->see('The role was successfully created.')
->seeInDatabase(config('access.roles_table'), ['name' => 'Test Role', 'all' => 1, 'sort' => 999]);
Event::assertDispatched(RoleCreated::class);
}
public function testCreateRoleFormSpecificPermissions()
{
// Make sure our events are fired
Event::fake();
// Test create with some permissions
$this->actingAs($this->admin)
->visit('/admin/access/role/create')
->type('Test Role', 'name')
->select('custom', 'associated_permissions')
->check('permissions[1]')
->press('Create')
->seePageIs('/admin/access/role')
->see('The role was successfully created.')
->seeInDatabase(config('access.roles_table'), ['name' => 'Test Role', 'all' => 0])
->seeInDatabase(config('access.permission_role_table'), ['permission_id' => 1, 'role_id' => 4]);
Event::assertDispatched(RoleCreated::class);
}
public function testRoleAlreadyExists()
{
$this->actingAs($this->admin)
->visit('/admin/access/role/create')
->type('Administrator', 'name')
->press('Create')
->seePageIs('/admin/access/role/create')
->see('That role already exists. Please choose a different name.');
}
public function testRoleRequiresPermission()
{
if (config('access.roles.role_must_contain_permission')) {
$this->actingAs($this->admin)
->visit('/admin/access/role/create')
->type('Test Role', 'name')
->select('custom', 'associated_permissions')
->press('Create')
->seePageIs('/admin/access/role/create')
->see('You must select at least one permission for this role.');
}
}
public function testUpdateRoleRequiredFields()
{
$this->actingAs($this->admin)
->visit('/admin/access/role/1/edit')
->type('', 'name')
->press('Update')
->seePageIs('/admin/access/role/1/edit')
->see('The name field is required.');
}
public function testUpdateRoleFormAll()
{
// Make sure our events are fired
Event::fake();
$this->actingAs($this->admin)
->visit('/admin/access/role/1/edit')
->type('Administrator Edited', 'name')
->type('123', 'sort')
->press('Update')
->seePageIs('/admin/access/role')
->see('The role was successfully updated.')
->seeInDatabase(config('access.roles_table'), ['id' => 1, 'name' => 'Administrator Edited', 'sort' => 123]);
Event::assertDispatched(RoleUpdated::class);
}
public function testUpdateRoleFormSpecificPermissions()
{
// Make sure our events are fired
Event::fake();
$this->actingAs($this->admin)
->notSeeInDatabase(config('access.permission_role_table'), ['permission_id' => 1, 'role_id' => 3])
->visit('/admin/access/role/3/edit')
->check('permissions[1]')
->press('Update')
->seePageIs('/admin/access/role')
->see('The role was successfully updated.')
->seeInDatabase(config('access.permission_role_table'), ['permission_id' => 1, 'role_id' => 3]);
Event::assertDispatched(RoleUpdated::class);
}
public function testUpdateRoleRequiresPermission()
{
$this->actingAs($this->admin)
->visit('/admin/access/role/3/edit')
->uncheck('permissions[2]')
->press('Update')
->seePageIs('/admin/access/role/3/edit')
->see('You must select at least one permission for this role.');
}
public function testDeleteRoleForm()
{
// Make sure our events are fired
Event::fake();
$this->actingAs($this->admin);
$role = factory(Role::class)->create([
'created_by' => $this->admin->id,
]);
$this->seeInDatabase(config('access.roles_table'), ['id' => $role->id])
->delete(route('admin.access.role.destroy', $role))
->assertRedirectedTo(route('admin.access.role.index'))
->notSeeInDatabase(config('access.roles_table'), ['id' => $role->id, 'deleted_at' => null])
->seeInSession(['flash_success' => 'The role was successfully deleted.']);
$this->assertCount(3, Role::all());
Event::assertDispatched(RoleDeleted::class);
}
public function testDeleteRoleWithPermissions()
{
// Make sure our events are fired
Event::fake();
// Remove users from role first because it will error on that first
DB::table(config('access.role_user_table'))->where('role_id', 2)->delete();
$this->actingAs($this->admin)
->visit('/admin/access/role')
->delete('/admin/access/role/2')
->assertRedirectedTo('/admin/access/role')
->notSeeInDatabase(config('access.roles_table'), ['id' => 2, 'deleted_at' => null])
->notSeeInDatabase(config('access.permission_role_table'), ['permission_id' => 1, 'role_id' => 2])
->seeInSession(['flash_success' => 'The role was successfully deleted.']);
Event::assertDispatched(RoleDeleted::class);
}
public function testCanNotDeleteAdministratorRole()
{
$this->actingAs($this->admin)
->visit('/admin/access/role')
->delete('/admin/access/role/1')
->assertRedirectedTo('/admin/access/role')
->seeInDatabase(config('access.roles_table'), ['id' => 1, 'name' => 'Administrator'])
->seeInSession(['flash_danger' => 'You can not delete the Administrator role.']);
}
public function testCanNotDeleteRoleWithUsers()
{
$this->actingAs($this->admin)
->visit('/admin/access/role')
->delete('/admin/access/role/2')
->assertRedirectedTo('/admin/access/role')
->seeInDatabase(config('access.roles_table'), ['id' => 2])
->seeInSession(['flash_danger' => 'You can not delete a role with associated users.']);
}
}
<?php
use App\Events\Backend\Access\User\UserCreated;
use App\Events\Backend\Access\User\UserDeleted;
use App\Events\Backend\Access\User\UserPasswordChanged;
use App\Events\Backend\Access\User\UserUpdated;
use App\Models\Access\User\User;
use App\Notifications\Frontend\Auth\UserNeedsConfirmation;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Notification;
use Tests\BrowserKitTestCase;
/**
* Class UserFormTest.
*/
class UserFormTest extends BrowserKitTestCase
{
public function testCreateUserRequiredFields()
{
$this->actingAs($this->admin)
->visit('/admin/access/user/create')
->type('', 'first_name')
->type('', 'last_name')
->type('', 'email')
->type('', 'password')
->type('', 'password_confirmation')
->press('Create')
->see('The first name field is required.')
->see('The last name field is required.')
->see('The email field is required.')
->see('The password field is required.');
}
public function testCreateUserPasswordsDoNotMatch()
{
$this->actingAs($this->admin)
->visit('/admin/access/user/create')
->type('Test', 'first_name')
->type('User', 'last_name')
->type('test@test.com', 'email')
->type('123456', 'password')
->type('1234567', 'password_confirmation')
->press('Create')
->see('The password confirmation does not match.');
}
public function testCreateUserConfirmedForm()
{
// Make sure our events are fired
Event::fake();
// Create any needed resources
$faker = Faker\Factory::create();
$name = $faker->name;
$email = $faker->safeEmail;
$password = 'Admin@123';
$this->actingAs($this->admin)
->visit('/admin/access/user/create')
->type(explode(' ', $name)[0], 'first_name')
->type(explode(' ', $name)[1], 'last_name')
->type($email, 'email')
->type($password, 'password')
->type($password, 'password_confirmation')
->seeIsChecked('status')
->seeIsChecked('confirmed')
->seeIsChecked('permissions[2]')
->dontSeeIsChecked('confirmation_email')
->press('Create')
->seePageIs('/admin/access/user')
->see('The user was successfully created.')
->seeInDatabase(config('access.users_table'), ['name' => $name, 'email' => $email, 'status' => 1, 'confirmed' => 1])
->seeInDatabase(config('access.role_user_table'), ['user_id' => 4, 'role_id' => 2])
->seeInDatabase(config('access.role_user_table'), ['user_id' => 4, 'role_id' => 3]);
Event::assertDispatched(UserCreated::class);
}
public function testCreateUserUnconfirmedForm()
{
// Make sure our events are fired
Event::fake();
// Make sure our notifications are sent
Notification::fake();
// Create any needed resources
$faker = Faker\Factory::create();
$name = $faker->name;
$email = $faker->safeEmail;
$password = $faker->password(8);
$this->actingAs($this->admin)
->visit('/admin/access/user/create')
->type($name, 'name')
->type($email, 'email')
->type($password, 'password')
->type($password, 'password_confirmation')
->seeIsChecked('status')
->uncheck('confirmed')
->check('confirmation_email')
->check('assignees_roles[2]')
->check('assignees_roles[3]')
->press('Create')
->seePageIs('/admin/access/user')
->see('The user was successfully created.')
->seeInDatabase(config('access.users_table'), ['name' => $name, 'email' => $email, 'status' => 1, 'confirmed' => 0])
->seeInDatabase(config('access.role_user_table'), ['user_id' => 4, 'role_id' => 2])
->seeInDatabase(config('access.role_user_table'), ['user_id' => 4, 'role_id' => 3]);
// Get the user that was inserted into the database
$user = User::where('email', $email)->first();
// Check that the user was sent the confirmation email
Notification::assertSentTo([$user],
UserNeedsConfirmation::class);
Event::assertDispatched(UserCreated::class);
}
public function testCreateUserFailsIfEmailExists()
{
$this->actingAs($this->admin)
->visit('/admin/access/user/create')
->type('User', 'name')
->type('user@user.com', 'email')
->type('123456', 'password')
->type('123456', 'password_confirmation')
->press('Create')
->seePageIs('/admin/access/user/create')
->see('The email has already been taken.');
}
public function testUpdateUserRequiredFields()
{
$this->actingAs($this->admin)
->visit('/admin/access/user/3/edit')
->type('', 'name')
->type('', 'email')
->press('Update')
->see('The name field is required.')
->see('The email field is required.');
}
public function testUpdateUserForm()
{
// Make sure our events are fired
Event::fake();
$this->actingAs($this->admin)
->visit('/admin/access/user/'.$this->user->id.'/edit')
->see($this->user->name)
->see($this->user->email)
->type('User New', 'name')
->type('user2@user.com', 'email')
->uncheck('status')
->uncheck('confirmed')
->check('assignees_roles[2]')
->uncheck('assignees_roles[3]')
->press('Update')
->seePageIs('/admin/access/user')
->see('The user was successfully updated.')
->seeInDatabase(config('access.users_table'),
[
'id' => $this->user->id,
'name' => 'User New',
'email' => 'user2@user.com',
'status' => 0,
'confirmed' => 0,
])
->seeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => 2])
->notSeeInDatabase(config('access.role_user_table'), ['user_id' => $this->user->id, 'role_id' => 3]);
Event::assertDispatched(UserUpdated::class);
}
public function testDeleteUserForm()
{
// Make sure our events are fired
Event::fake();
$this->actingAs($this->admin)
->delete('/admin/access/user/'.$this->user->id)
->assertRedirectedTo('/admin/access/user/deleted')
->notSeeInDatabase(config('access.users_table'), ['id' => $this->user->id, 'deleted_at' => null]);
Event::assertDispatched(UserDeleted::class);
}
public function testUserCanNotDeleteSelf()
{
$this->actingAs($this->admin)
->visit('/admin/access/user')
->delete('/admin/access/user/'.$this->admin->id)
->assertRedirectedTo('/admin/access/user')
->seeInDatabase(config('access.users_table'), ['id' => $this->admin->id, 'deleted_at' => null])
->seeInSession(['flash_danger' => 'You can not delete yourself.']);
}
public function testChangeUserPasswordRequiredFields()
{
$this->actingAs($this->admin)
->visit('/admin/access/user/'.$this->user->id.'/password/change')
->see('Change Password for '.$this->user->name)
->type('', 'password')
->type('', 'password_confirmation')
->press('Update')
->seePageIs('/admin/access/user/'.$this->user->id.'/password/change')
->see('The password field is required.');
}
public function testChangeUserPasswordForm()
{
// Make sure our events are fired
Event::fake();
$password = '87654321';
$this->actingAs($this->admin)
->visit('/admin/access/user/'.$this->user->id.'/password/change')
->see('Change Password for '.$this->user->name)
->type($password, 'password')
->type($password, 'password_confirmation')
->press('Update')
->seePageIs('/admin/access/user')
->see('The user\'s password was successfully updated.');
Event::assertDispatched(UserPasswordChanged::class);
}
public function testChangeUserPasswordDoNotMatch()
{
$this->actingAs($this->admin)
->visit('/admin/access/user/'.$this->user->id.'/password/change')
->see('Change Password for '.$this->user->name)
->type('123456', 'password')
->type('1234567', 'password_confirmation')
->press('Update')
->seePageIs('/admin/access/user/'.$this->user->id.'/password/change')
->see('The password confirmation does not match.');
}
}
<?php
use Tests\BrowserKitTestCase;
/**
* Class SearchFormTest.
*/
class SearchFormTest extends BrowserKitTestCase
{
public function testSearchPageWithNoQuery()
{
$this->actingAs($this->admin)
->visit('/admin/search')
->seePageIs('/admin/dashboard')
->see('Please enter a search term.');
}
// public function testSearchFormRedirectsToResults()
// {
// $this->actingAs($this->admin)
// ->visit('/admin/dashboard')
// ->type('Test Query', 'q')
// ->press('search-btn')
// ->seePageIs('/admin/search?q=Test%20Query')
// ->see('Search Results for Test Query');
// }
}
<?php
use Tests\BrowserKitTestCase;
/**
* Class RoleRouteTest.
*/
class RoleRouteTest extends BrowserKitTestCase
{
public function testRolesIndex()
{
$this->actingAs($this->admin)->visit('/admin/access/role')->see('Role Management');
}
public function testCreateRole()
{
$this->actingAs($this->admin)->visit('/admin/access/role/create')->see('Create Role');
}
public function testEditRole()
{
$this->actingAs($this->admin)
->visit('/admin/access/role/'.$this->adminRole->id.'/edit')
->see('Edit Role')
->see($this->adminRole->name);
}
}
<?php
use App\Events\Backend\Access\User\UserDeactivated;
use App\Events\Backend\Access\User\UserPermanentlyDeleted;
use App\Events\Backend\Access\User\UserReactivated;
use App\Events\Backend\Access\User\UserRestored;
use App\Notifications\Frontend\Auth\UserNeedsConfirmation;
use Carbon\Carbon;
use Illuminate\Support\Facades\Event;
use Tests\BrowserKitTestCase;
/**
* Class UserRouteTest.
*/
class UserRouteTest extends BrowserKitTestCase
{
public function testActiveUsers()
{
$this->actingAs($this->admin)->visit('/admin/access/user')->see('Active Users');
}
public function testDeactivatedUsers()
{
$this->actingAs($this->admin)->visit('/admin/access/user/deactivated')->see('Deactivated Users');
}
public function testDeletedUsers()
{
$this->actingAs($this->admin)->visit('/admin/access/user/deleted')->see('Deleted Users');
}
public function testCreateUser()
{
$this->actingAs($this->admin)->visit('/admin/access/user/create')->see('Create User');
}
public function testViewUser()
{
$this->actingAs($this->admin)
->visit('/admin/access/user/'.$this->user->id)
->see('View User')
->see('Overview')
->see('History')
->see($this->user->name)
->see($this->user->email);
}
public function testEditUser()
{
$this->actingAs($this->admin)
->visit('/admin/access/user/'.$this->user->id.'/edit')
->see('Edit User')
->see($this->user->name)
->see($this->user->email);
}
public function testChangeUserPassword()
{
$this->actingAs($this->admin)
->visit('/admin/access/user/'.$this->user->id.'/password/change')
->see('Change Password for '.$this->user->name);
}
public function testResendUserConfirmationEmail()
{
Notification::fake();
$this->actingAs($this->admin)
->visit('/admin/access/user')
->visit('/admin/access/user/'.$this->user->id.'/account/confirm/resend')
->seePageIs('/admin/access/user')
->see('A new confirmation e-mail has been sent to the address on file.');
Notification::assertSentTo($this->user, UserNeedsConfirmation::class);
}
public function testLoginAsUser()
{
$this->actingAs($this->admin)
->visit('/admin/access/user/'.$this->user->id.'/login-as')
->seePageIs('/')
->see('You are currently logged in as '.$this->user->name.'.')
->see($this->admin->name)
->assertTrue(access()->id() == $this->user->id);
}
public function testCantLoginAsSelf()
{
$this->actingAs($this->admin)
->visit('/admin/access/user/'.$this->admin->id.'/login-as')
->see('Do not try to login as yourself.');
}
public function testLogoutAsUser()
{
$this->actingAs($this->admin)
->visit('/admin/access/user/'.$this->user->id.'/login-as')
->seePageIs('/')
->see('You are currently logged in as '.$this->user->name.'.')
->click('Re-Login as '.$this->admin->name)
->seePageIs('/admin/access/user')
->assertTrue(access()->id() == $this->admin->id);
}
public function testDeactivateReactivateUser()
{
// Make sure our events are fired
Event::fake();
$this->actingAs($this->admin)
->visit('/admin/access/user/'.$this->user->id.'/mark/0')
->seePageIs('/admin/access/user/deactivated')
->see('The user was successfully updated.')
->seeInDatabase(config('access.users_table'), ['id' => $this->user->id, 'status' => 0])
->visit('/admin/access/user/'.$this->user->id.'/mark/1')
->seePageIs('/admin/access/user')
->see('The user was successfully updated.')
->seeInDatabase(config('access.users_table'), ['id' => $this->user->id, 'status' => 1]);
Event::assertDispatched(UserDeactivated::class);
Event::assertDispatched(UserReactivated::class);
}
public function testRestoreUser()
{
// Make sure our events are fired
Event::fake();
$this->user->deleted_at = Carbon::now();
$this->user->save();
$this->actingAs($this->admin)
->notSeeInDatabase(config('access.users_table'), ['id' => $this->user->id, 'deleted_at' => null])
->visit('/admin/access/user/'.$this->user->id.'/restore')
->seePageIs('/admin/access/user')
->see('The user was successfully restored.')
->seeInDatabase(config('access.users_table'), ['id' => $this->user->id, 'deleted_at' => null]);
Event::assertDispatched(UserRestored::class);
}
public function testUserIsDeletedBeforeBeingRestored()
{
$this->actingAs($this->admin)
->seeInDatabase(config('access.users_table'), ['id' => $this->user->id, 'deleted_at' => null])
->visit('/admin/access/user')
->visit('/admin/access/user/'.$this->user->id.'/restore')
->seePageIs('/admin/access/user')
->see('This user is not deleted so it can not be restored.')
->seeInDatabase(config('access.users_table'), ['id' => $this->user->id, 'deleted_at' => null]);
}
public function testPermanentlyDeleteUser()
{
// Make sure our events are fired
Event::fake();
$this->actingAs($this->admin)
->delete('/admin/access/user/'.$this->user->id)
->notSeeInDatabase(config('access.users_table'), ['id' => $this->user->id, 'deleted_at' => null])
->visit('/admin/access/user/'.$this->user->id.'/delete')
->seePageIs('/admin/access/user/deleted')
->see('The user was deleted permanently.')
->notSeeInDatabase(config('access.users_table'), ['id' => $this->user->id]);
Event::assertDispatched(UserPermanentlyDeleted::class);
}
public function testUserIsDeletedBeforeBeingPermanentlyDeleted()
{
$this->actingAs($this->admin)
->seeInDatabase(config('access.users_table'), ['id' => $this->user->id, 'deleted_at' => null])
->visit('/admin/access/user')
->visit('/admin/access/user/'.$this->user->id.'/delete')
->seePageIs('/admin/access/user')
->see('This user must be deleted first before it can be destroyed permanently.')
->seeInDatabase(config('access.users_table'), ['id' => $this->user->id, 'deleted_at' => null]);
}
public function testCantNotDeactivateSelf()
{
$this->actingAs($this->admin)
->visit('/admin/access/user')
->visit('/admin/access/user/'.$this->admin->id.'/mark/0')
->seePageIs('/admin/access/user')
->see('You can not do that to yourself.');
}
}
<?php
use Tests\BrowserKitTestCase;
/**
* Class DashboardRouteTest.
*/
class DashboardRouteTest extends BrowserKitTestCase
{
public function testAdminDashboard()
{
$this->actingAs($this->admin)->visit('/admin/dashboard')->see('Access Management')->see($this->admin->name);
}
}
<?php
use Tests\BrowserKitTestCase;
/**
* Class LogViewerRouteTest.
*/
class LogViewerRouteTest extends BrowserKitTestCase
{
public function testLogViewerDashboard()
{
$this->actingAs($this->admin)
->visit('/admin/log-viewer')
->see('Log Viewer');
}
public function testLogViewerList()
{
$this->actingAs($this->admin)
->visit('/admin/log-viewer/logs')
->see('Logs');
}
public function testLogViewerSingle()
{
$this->actingAs($this->admin)
->visit('/admin/log-viewer/logs/'.date('Y-m-d'))
->see('Log ['.date('Y-m-d').']');
}
public function testLogViewerSingleType()
{
$this->actingAs($this->admin)
->visit('/admin/log-viewer/logs/'.date('Y-m-d').'/error')
->see('Log ['.date('Y-m-d').']');
}
}
......@@ -23,7 +23,7 @@ class ChangePasswordTest extends TestCase
}
/** @test */
public function a_user_require_strong_password_to_change_password()
/*public function a_user_require_strong_password_to_change_password()
{
$data = [];
$data['old_password'] = '1234';
......@@ -31,10 +31,10 @@ class ChangePasswordTest extends TestCase
$data['password_confirmation'] = '12345678';
$this->withExceptionHandling()
->actingAs($this->admin)
->patch(route('admin.access.user.change-password', $this->admin), $data)
->actingAs($this->executive)
->patch(route('admin.access.user.change-password', $this->executive), $data)
->assertSessionHas('The given data was invalid.');
}
}*/
/** @test */
public function a_user_can_change_password()
......
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