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
e1511a0f
Commit
e1511a0f
authored
Jan 02, 2018
by
Vipul Basapati
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' of
https://github.com/viralsolani/laravel-adminpanel
into develop
parents
d16f91bd
ff673f47
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
174 additions
and
0 deletions
+174
-0
RoleFactory.php
database/factories/RoleFactory.php
+12
-0
ManageRolesTest.php
tests/Feature/Backend/ManageRolesTest.php
+162
-0
No files found.
database/factories/RoleFactory.php
View file @
e1511a0f
...
@@ -19,3 +19,15 @@ $factory->state(Role::class, 'admin', function () {
...
@@ -19,3 +19,15 @@ $factory->state(Role::class, 'admin', function () {
'all'
=>
1
,
'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 @
e1511a0f
...
@@ -2,8 +2,170 @@
...
@@ -2,8 +2,170 @@
namespace
Tests\Feature\Backend
;
namespace
Tests\Feature\Backend
;
use
App\Events\Backend\Access\Role\RoleCreated
;
use
App\Events\Backend\Access\Role\RoleDeleted
;
use
App\Events\Backend\Access\Role\RoleUpdated
;
use
App\Exceptions\GeneralException
;
use
App\Models\Access\Permission\Permission
;
use
App\Models\Access\Role\Role
;
use
Illuminate\Support\Facades\Event
;
use
Tests\TestCase
;
use
Tests\TestCase
;
class
ManageRolesTest
extends
TestCase
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
);
}
}
}
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