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
79c3758e
Commit
79c3758e
authored
Jan 03, 2018
by
Viral Solani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More Feature tests for Permission Module
parent
3bc49c56
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
91 additions
and
3 deletions
+91
-3
PermissionRepository.php
...tories/Backend/Access/Permission/PermissionRepository.php
+0
-1
ManagePermissionsTest.php
tests/Feature/Backend/ManagePermissionsTest.php
+86
-1
ManageRolesTest.php
tests/Feature/Backend/ManageRolesTest.php
+5
-1
No files found.
app/Repositories/Backend/Access/Permission/PermissionRepository.php
View file @
79c3758e
...
...
@@ -109,7 +109,6 @@ class PermissionRepository extends BaseRepository
DB
::
transaction
(
function
()
use
(
$permission
)
{
if
(
$permission
->
delete
())
{
event
(
new
PermissionDeleted
(
$permission
));
return
true
;
}
...
...
tests/Feature/Backend/ManagePermissionsTest.php
View file @
79c3758e
...
...
@@ -2,8 +2,12 @@
namespace
Tests\Feature\Backend
;
use
App\Models\Access\Permission\Permission
;
use
Tests\TestCase
;
use
Illuminate\Support\Facades\Event
;
use
App\Models\Access\Permission\Permission
;
use
App\Events\Backend\Access\Permission\PermissionCreated
;
use
App\Events\Backend\Access\Permission\PermissionDeleted
;
use
App\Events\Backend\Access\Permission\PermissionUpdated
;
class
ManagePermissionsTest
extends
TestCase
{
...
...
@@ -39,4 +43,85 @@ class ManagePermissionsTest extends TestCase
->
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->assertDatabaseHas(config('access.permissions_table'), [
['name' => $permission->name, 'id' => $permission->id]
]);*/
$this
->
actingAs
(
$this
->
admin
)
->
delete
(
route
(
'admin.access.permission.destroy'
,
$permission
))
->
assertSessionHas
([
'flash_success'
=>
trans
(
'alerts.backend.permissions.deleted'
)]);
/*$this->assertDatabaseMissing('permissions', [
'name' => $permission->name, 'id' => $permission->id
]);*/
Event
::
assertDispatched
(
PermissionDeleted
::
class
);
}
}
tests/Feature/Backend/ManageRolesTest.php
View file @
79c3758e
...
...
@@ -160,11 +160,15 @@ class ManageRolesTest extends TestCase
$role
=
create
(
Role
::
class
);
/*$this->assertDatabaseHas(config('access.roles_table'), [
['name' => $role->name, 'id' => $role->id]
]);*/
$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
]);
//$this->assertDatabaseMissing(config('access.roles_table'), ['name' => $role->
name, 'id' => $role->id]);
Event
::
assertDispatched
(
RoleDeleted
::
class
);
}
...
...
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