Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
laravel-adminpanel
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
laravel-adminpanel
Commits
cd88c0ac
Commit
cd88c0ac
authored
Jan 02, 2018
by
Viral Solani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test cases for role module
parent
4b3a1cd8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
175 additions
and
2 deletions
+175
-2
RoleRepository.php
app/Repositories/Backend/Access/Role/RoleRepository.php
+0
-1
RoleFactory.php
database/factories/RoleFactory.php
+12
-0
ManageRolesTest.php
tests/Feature/Backend/ManageRolesTest.php
+162
-0
ManageUsersTest.php
tests/Feature/Backend/ManageUsersTest.php
+1
-1
No files found.
app/Repositories/Backend/Access/Role/RoleRepository.php
View file @
cd88c0ac
...
...
@@ -114,7 +114,6 @@ class RoleRepository extends BaseRepository
return
true
;
}
throw
new
GeneralException
(
trans
(
'exceptions.backend.access.roles.create_error'
));
});
}
...
...
database/factories/RoleFactory.php
View file @
cd88c0ac
...
...
@@ -19,3 +19,15 @@ $factory->state(Role::class, 'admin', function () {
'all'
=>
1
,
];
});
$factory
->
state
(
Role
::
class
,
'active'
,
function
()
{
return
[
'status'
=>
1
,
];
});
$factory
->
state
(
Role
::
class
,
'inactive'
,
function
()
{
return
[
'status'
=>
0
,
];
});
tests/Feature/Backend/ManageRolesTest.php
View file @
cd88c0ac
...
...
@@ -3,7 +3,169 @@
namespace
Tests\Feature\Backend
;
use
Tests\TestCase
;
use
App\Models\Access\Role\Role
;
use
App\Exceptions\GeneralException
;
use
Illuminate\Support\Facades\Event
;
use
App\Models\Access\Permission\Permission
;
use
App\Events\Backend\Access\Role\RoleCreated
;
use
App\Events\Backend\Access\Role\RoleDeleted
;
use
App\Events\Backend\Access\Role\RoleUpdated
;
class
ManageRolesTest
extends
TestCase
{
/** @test */
public
function
a_user_can_view_roles
()
{
$this
->
actingAs
(
$this
->
admin
)
->
get
(
route
(
'admin.access.role.index'
))
->
assertViewIs
(
'backend.access.roles.index'
)
->
assertSee
(
trans
(
'labels.backend.access.roles.management'
))
->
assertSee
(
'Export'
)
->
assertSee
(
'Action'
);
}
/** @test */
public
function
a_role_requires_a_name
()
{
$role
=
make
(
Role
::
class
,
[
'name'
=>
null
])
->
toArray
();
return
$this
->
withExceptionHandling
()
->
actingAs
(
$this
->
admin
)
->
post
(
route
(
'admin.access.role.store'
),
$role
)
->
assertSessionHasErrors
(
'name'
);
}
/** @test */
public
function
a_role_requires_a_permission_if_associated_permissions_is_not_set_to_all
()
{
$role
=
make
(
Role
::
class
)
->
toArray
();
$role
[
'associated_permissions'
]
=
'custom'
;
return
$this
->
withExceptionHandling
()
->
actingAs
(
$this
->
admin
)
->
post
(
route
(
'admin.access.role.store'
),
$role
)
->
assertSessionHasErrors
(
'permissions'
);
}
/** @test */
/*public function a_role_can_not_create_if_name_is_already_exists()
{
$role = make(Role::class, ['name' => $this->adminRole->name])->toArray();
return $this->withExceptionHandling()
->actingAs($this->admin)
->post(route('admin.access.role.store'), $role);
$this->assertSessionHas(['flash_danger' => trans('exceptions.backend.access.roles.already_exists')]);
$this->expectException(GeneralException::class);
}*/
/** @test */
public
function
a_user_can_create_new_role
()
{
// Make sure our events are fired
Event
::
fake
();
$role
=
make
(
Role
::
class
,
[
'name'
=>
'test Role'
])
->
toArray
();
$role
[
'associated_permissions'
]
=
'all'
;
$this
->
actingAs
(
$this
->
admin
)
->
post
(
route
(
'admin.access.role.store'
),
$role
)
->
assertRedirect
(
route
(
'admin.access.role.index'
))
->
assertSessionHas
([
'flash_success'
=>
trans
(
'alerts.backend.roles.created'
)]);
$this
->
assertDatabaseHas
(
config
(
'access.roles_table'
),
[
'name'
=>
$role
[
'name'
]
]);
Event
::
assertDispatched
(
RoleCreated
::
class
);
}
/** @test */
public
function
a_user_can_create_new_role_with_permissions
()
{
// Make sure our events are fired
Event
::
fake
();
$role
=
make
(
Role
::
class
,
[
'name'
=>
'test Role'
])
->
toArray
();
$permission
=
create
(
Permission
::
class
);
$role
[
'associated_permissions'
]
=
'custom'
;
$role
[
'permissions'
]
=
[
$permission
->
id
];
$this
->
actingAs
(
$this
->
admin
)
->
post
(
route
(
'admin.access.role.store'
),
$role
)
->
assertRedirect
(
route
(
'admin.access.role.index'
))
->
assertSessionHas
([
'flash_success'
=>
trans
(
'alerts.backend.roles.created'
)]);
$this
->
assertDatabaseHas
(
config
(
'access.roles_table'
),
[
'name'
=>
$role
[
'name'
]
]);
$this
->
assertDatabaseHas
(
config
(
'access.permissions_table'
),
[
'name'
=>
$permission
->
name
]);
$this
->
assertDatabaseHas
(
config
(
'access.permission_role_table'
),
[
'permission_id'
=>
$permission
->
id
]);
Event
::
assertDispatched
(
RoleCreated
::
class
);
}
/** @test */
public
function
it_fails_for_validation_on_update_role
()
{
$role
=
create
(
Role
::
class
);
$data
=
$role
->
toArray
();
$data
[
'name'
]
=
''
;
$this
->
withExceptionHandling
()
->
actingAs
(
$this
->
admin
)
->
patch
(
route
(
'admin.access.role.update'
,
$role
),
$data
)
->
assertSessionHasErrors
([
'name'
]);
}
/** @test */
public
function
a_user_can_update_role
()
{
Event
::
fake
();
$role
=
create
(
Role
::
class
);
$permission
=
create
(
Permission
::
class
);
$data
=
$role
->
toArray
();
$data
[
'associated_permissions'
]
=
'custom'
;
$data
[
'permissions'
]
=
[
$permission
->
id
];
$data
[
'name'
]
=
'Updated Role Name'
;
$this
->
withExceptionHandling
()
->
actingAs
(
$this
->
admin
)
->
patch
(
route
(
'admin.access.role.update'
,
$role
),
$data
)
->
assertRedirect
(
route
(
'admin.access.role.index'
))
->
assertSessionHas
([
'flash_success'
=>
trans
(
'alerts.backend.roles.updated'
)]);
$this
->
assertDatabaseHas
(
config
(
'access.roles_table'
),
[
'name'
=>
$data
[
'name'
]
]);
$this
->
assertDatabaseHas
(
config
(
'access.permissions_table'
),
[
'name'
=>
$permission
->
name
]);
$this
->
assertDatabaseHas
(
config
(
'access.permission_role_table'
),
[
'permission_id'
=>
$permission
->
id
]);
Event
::
assertDispatched
(
RoleUpdated
::
class
);
}
/** @test */
public
function
a_user_can_delete_a_role
()
{
Event
::
fake
();
$role
=
create
(
Role
::
class
);
$this
->
actingAs
(
$this
->
admin
)
->
delete
(
route
(
'admin.access.role.destroy'
,
$role
))
->
assertSessionHas
([
'flash_success'
=>
trans
(
'alerts.backend.roles.deleted'
)]);
$this
->
assertDatabaseMissing
(
config
(
'access.roles_table'
),
[
'name'
=>
$role
->
first_name
,
'id'
=>
$role
->
id
]);
Event
::
assertDispatched
(
RoleDeleted
::
class
);
}
}
tests/Feature/Backend/ManageUsersTest.php
View file @
cd88c0ac
...
...
@@ -298,7 +298,7 @@ class ManageUsersTest extends TestCase
$this
->
withExceptionHandling
()
->
actingAs
(
$this
->
admin
)
->
delete
(
route
(
'admin.access.user.destroy'
,
$this
->
admin
))
->
assertSessionHas
([
'flash_danger'
=>
trans
(
'exceptions.backend.access.users.cant_delete_self'
)]
);
->
expectException
(
'Exception'
);
$this
->
assertDatabaseHas
(
config
(
'access.users_table'
),
[
'id'
=>
$this
->
admin
->
id
,
'deleted_at'
=>
null
]);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment