Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Platform
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
Platform
Commits
cf91ffdd
Unverified
Commit
cf91ffdd
authored
Jun 28, 2017
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Testing the role repository
parent
67d873e2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
85 additions
and
0 deletions
+85
-0
SentinelRoleRepositoryTest.php
Modules/User/Tests/SentinelRoleRepositoryTest.php
+85
-0
No files found.
Modules/User/Tests/SentinelRoleRepositoryTest.php
0 → 100644
View file @
cf91ffdd
<?php
namespace
Modules\User\Tests
;
use
Illuminate\Support\Facades\Event
;
use
Modules\User\Events\RoleWasUpdated
;
use
Modules\User\Repositories\RoleRepository
;
class
SentinelRoleRepositoryTest
extends
BaseUserTestCase
{
/**
* @var RoleRepository
*/
private
$role
;
public
function
setUp
()
{
parent
::
setUp
();
$this
->
role
=
app
(
RoleRepository
::
class
);
}
/** @test */
public
function
it_creates_a_role
()
{
$this
->
role
->
create
([
'name'
=>
'Admin'
,
'slug'
=>
'admin'
]);
$this
->
assertCount
(
1
,
$this
->
role
->
all
());
}
/** @test */
public
function
it_finds_a_role_by_id
()
{
$this
->
role
->
create
([
'name'
=>
'Admin'
,
'slug'
=>
'admin'
]);
$role
=
$this
->
role
->
find
(
1
);
$this
->
assertEquals
(
'Admin'
,
$role
->
name
);
}
/** @test */
public
function
it_updates_a_role
()
{
$role
=
$this
->
role
->
create
([
'name'
=>
'Admin'
,
'slug'
=>
'admin'
]);
$this
->
role
->
update
(
$role
->
id
,
[
'name'
=>
'Better Admin'
]);
$role
->
refresh
();
$this
->
assertEquals
(
'Better Admin'
,
$role
->
name
);
}
/** @test */
public
function
it_triggers_role_updated_event
()
{
$role
=
$this
->
role
->
create
([
'name'
=>
'Admin'
,
'slug'
=>
'admin'
]);
Event
::
fake
();
$this
->
role
->
update
(
$role
->
id
,
[
'name'
=>
'Better Admin'
]);
Event
::
assertDispatched
(
RoleWasUpdated
::
class
,
function
(
$e
)
use
(
$role
)
{
return
$e
->
role
->
id
===
$role
->
id
;
});
}
/** @test */
public
function
it_deletes_a_role
()
{
$this
->
role
->
create
([
'name'
=>
'Admin'
,
'slug'
=>
'admin'
]);
$this
->
assertCount
(
1
,
$this
->
role
->
all
());
$this
->
role
->
delete
(
1
);
$this
->
assertCount
(
0
,
$this
->
role
->
all
());
}
/** @test */
public
function
it_finds_a_role_by_its_name
()
{
$this
->
role
->
create
([
'name'
=>
'Admin'
,
'slug'
=>
'admin'
]);
$role
=
$this
->
role
->
findByName
(
'Admin'
);
$this
->
assertEquals
(
'Admin'
,
$role
->
name
);
}
}
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