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
344655cd
Commit
344655cd
authored
Dec 28, 2017
by
Viral Solani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More Test Cases For User Module
parent
18250270
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
81 additions
and
19 deletions
+81
-19
UserRepository.php
app/Repositories/Backend/Access/User/UserRepository.php
+0
-14
ManageUsersTest.php
tests/Feature/Backend/ManageUsersTest.php
+81
-5
No files found.
app/Repositories/Backend/Access/User/UserRepository.php
View file @
344655cd
...
...
@@ -97,8 +97,6 @@ class UserRepository extends BaseRepository
$user
=
$this
->
createUserStub
(
$data
);
DB
::
transaction
(
function
()
use
(
$user
,
$data
,
$roles
,
$permissions
)
{
// Set email type 2
$email_type
=
2
;
if
(
$user
->
save
())
{
...
...
@@ -120,18 +118,6 @@ class UserRepository extends BaseRepository
event
(
new
UserCreated
(
$user
));
/*if (isset($data['confirmation_email']) && $user->confirmed == 0) {
$email_type = 1;
}*/
// Send email to the user
/* $options = [
'data' => $user->toArray(),
'email_template_type' => $email_type,
];*/
//createNotification('', 1, 2, $options);
return
true
;
}
...
...
tests/Feature/Backend/ManageUsersTest.php
View file @
344655cd
...
...
@@ -2,10 +2,14 @@
namespace
Tests\Feature\Backend
;
use
App\Models\Access\Permission\Permission
;
use
Tests\TestCase
;
use
App\Models\Access\Role\Role
;
use
App\Models\Access\User\User
;
use
Tests\TestCase
;
use
Illuminate\Support\Facades\Event
;
use
Illuminate\Support\Facades\Notification
;
use
App\Models\Access\Permission\Permission
;
use
App\Events\Backend\Access\User\UserCreated
;
use
App\Notifications\Frontend\Auth\UserNeedsConfirmation
;
class
ManageUsersTest
extends
TestCase
{
...
...
@@ -87,6 +91,21 @@ class ManageUsersTest extends TestCase
->
assertSessionHasErrors
(
'password'
);
}
/** @test */
function
a_user_requires_a_confirm_password
()
{
$user
=
factory
(
User
::
class
)
->
states
(
'active'
,
'confirmed'
)
->
make
()
->
toArray
();
$user
[
'password'
]
=
'Viral@1234'
;
$user
[
'password_confirmation'
]
=
'Viral@1235'
;
$this
->
withExceptionHandling
()
->
actingAs
(
$this
->
admin
)
->
post
(
route
(
'admin.access.user.store'
),
$user
)
->
assertSessionHasErrors
(
'password'
);
}
/** @test */
function
a_user_requires_a_role
()
{
...
...
@@ -104,12 +123,54 @@ class ManageUsersTest extends TestCase
/** @test */
public
function
a_user_can_create_new_user
()
{
// Make sure our events are fired
Event
::
fake
();
$user
=
factory
(
User
::
class
)
->
states
(
'active'
,
'confirmed'
)
->
make
()
->
toArray
();
$role
=
create
(
Role
::
class
);
$permission
=
create
(
Permission
::
class
);
$user
[
'password'
]
=
'Viral@1234'
;
$user
[
'password_confirmation'
]
=
'Viral@1234'
;
$user
[
'assignees_roles'
]
=
[
$role
->
id
];
$user
[
'permissions'
]
=
[
$permission
->
id
];
$this
->
actingAs
(
$this
->
admin
)
->
post
(
route
(
'admin.access.user.store'
),
$user
)
->
assertRedirect
(
route
(
'admin.access.user.index'
));
$this
->
assertDatabaseHas
(
config
(
'access.users_table'
),
[
'first_name'
=>
$user
[
'first_name'
],
'last_name'
=>
$user
[
'last_name'
],
'email'
=>
$user
[
'email'
],
'status'
=>
1
,
'confirmed'
=>
1
,
]);
$this
->
assertDatabaseHas
(
config
(
'access.roles_table'
),
[
'name'
=>
$role
->
name
]);
$this
->
assertDatabaseHas
(
config
(
'access.permissions_table'
),
[
'name'
=>
$permission
->
name
]);
$this
->
assertDatabaseHas
(
config
(
'access.role_user_table'
),
[
'role_id'
=>
$role
->
id
]);
Event
::
assertDispatched
(
UserCreated
::
class
);
}
/** @test */
public
function
an_email_will_be_sent_to_uncomfirmed_user
()
{
// Make sure our events are fired
Event
::
fake
();
// Make sure our notifications are sent
Notification
::
fake
();
$user
=
factory
(
User
::
class
)
->
states
(
'active'
)
->
make
()
->
toArray
();
$role
=
create
(
Role
::
class
);
$permission
=
create
(
Permission
::
class
);
$user
[
'password'
]
=
'Viral@1234'
;
$user
[
'password_confirmation'
]
=
'Viral@1234'
;
$user
[
'confirmation_email'
]
=
1
;
$user
[
'assignees_roles'
]
=
[
$role
->
id
];
$user
[
'permissions'
]
=
[
$permission
->
id
];
...
...
@@ -117,9 +178,24 @@ class ManageUsersTest extends TestCase
->
post
(
route
(
'admin.access.user.store'
),
$user
)
->
assertRedirect
(
route
(
'admin.access.user.index'
));
$this
->
assertDatabaseHas
(
'users'
,
[
'first_name'
=>
$user
[
'first_name'
],
'last_name'
=>
$user
[
'last_name'
]]);
$this
->
assertDatabaseHas
(
'roles'
,
[
'name'
=>
$role
->
name
]);
$this
->
assertDatabaseHas
(
'permissions'
,
[
'name'
=>
$permission
->
name
]);
$this
->
assertDatabaseHas
(
config
(
'access.users_table'
),
[
'first_name'
=>
$user
[
'first_name'
],
'last_name'
=>
$user
[
'last_name'
],
'email'
=>
$user
[
'email'
],
'status'
=>
1
,
'confirmed'
=>
0
,
]);
$this
->
assertDatabaseHas
(
config
(
'access.roles_table'
),
[
'name'
=>
$role
->
name
]);
$this
->
assertDatabaseHas
(
config
(
'access.permissions_table'
),
[
'name'
=>
$permission
->
name
]);
$this
->
assertDatabaseHas
(
config
(
'access.role_user_table'
),
[
'role_id'
=>
$role
->
id
]);
// Get the user that was inserted into the database
$insertedUser
=
User
::
where
(
'email'
,
$user
[
'email'
])
->
first
();
// Check that the user was sent the confirmation email
Notification
::
assertSentTo
([
$insertedUser
],
UserNeedsConfirmation
::
class
);
Event
::
assertDispatched
(
UserCreated
::
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