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
6ebc1d3b
Commit
6ebc1d3b
authored
Jan 02, 2018
by
Viral Solani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Manger User Tests
Change Password Tests
parent
00e52fdf
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
152 additions
and
26 deletions
+152
-26
UserRepository.php
app/Repositories/Backend/Access/User/UserRepository.php
+8
-13
labels.php
resources/lang/en/labels.php
+1
-1
ChangePasswordTest.php
tests/Feature/Backend/ChangePasswordTest.php
+57
-0
ManageUsersTest.php
tests/Feature/Backend/ManageUsersTest.php
+86
-12
No files found.
app/Repositories/Backend/Access/User/UserRepository.php
View file @
6ebc1d3b
...
...
@@ -160,30 +160,25 @@ class UserRepository extends BaseRepository
}
/**
* @param Model $user
* Change Password
*
* @param $user
* @param $input
*
* @throws GeneralException
*
* @return bool
*/
public
function
updatePassword
(
Model
$user
,
$input
)
public
function
updatePassword
(
$user
,
$input
)
{
$user
=
$this
->
find
(
access
()
->
id
());
if
(
Hash
::
check
(
$input
[
'old_password'
],
$user
->
password
))
{
$user
->
password
=
bcrypt
(
$input
[
'password'
]);
if
(
$user
->
save
())
{
$input
[
'email'
]
=
$user
->
email
;
// Send email to the user
$options
=
[
'data'
=>
$input
,
'email_template_type'
=>
4
,
];
createNotification
(
''
,
$user
->
id
,
2
,
$options
);
$user
->
password
=
bcrypt
(
$input
[
'password'
]);
if
(
$user
->
save
())
{
event
(
new
UserPasswordChanged
(
$user
));
return
true
;
}
...
...
@@ -200,7 +195,7 @@ class UserRepository extends BaseRepository
*
* @return bool
*/
public
function
delete
(
Model
$user
)
public
function
delete
(
$user
)
{
if
(
access
()
->
id
()
==
$user
->
id
)
{
throw
new
GeneralException
(
trans
(
'exceptions.backend.access.users.cant_delete_self'
));
...
...
resources/lang/en/labels.php
View file @
6ebc1d3b
...
...
@@ -66,7 +66,7 @@ return [
'active'
=>
'Active Users'
,
'all_permissions'
=>
'All Permissions'
,
'change_password'
=>
'Change Password'
,
'change_password_for'
=>
'Change Password :user'
,
'change_password_for'
=>
'Change Password
for
:user'
,
'create'
=>
'Create User'
,
'deactivated'
=>
'Deactivated Users'
,
'deleted'
=>
'Deleted Users'
,
...
...
tests/Feature/Backend/ChangePasswordTest.php
0 → 100644
View file @
6ebc1d3b
<?php
namespace
Tests\Feature\Backend
;
use
Tests\TestCase
;
use
Illuminate\Support\Facades\Event
;
use
App\Events\Backend\Access\User\UserPasswordChanged
;
class
ChangePasswordTest
extends
TestCase
{
/** @test */
public
function
a_user_require_old_password_to_change_password
()
{
$data
=
[];
$data
[
'old_password'
]
=
'12345'
;
$data
[
'password'
]
=
'Viral@1234'
;
$data
[
'password_confirmation'
]
=
'Viral@1234'
;
$this
->
withExceptionHandling
()
->
actingAs
(
$this
->
admin
)
->
patch
(
route
(
'admin.access.user.change-password'
,
$this
->
admin
),
$data
)
->
assertSessionHas
([
'flash_danger'
=>
trans
(
'exceptions.backend.access.users.change_mismatch'
)]);
}
/** @test */
public
function
a_user_require_strong_password_to_change_password
()
{
$data
=
[];
$data
[
'old_password'
]
=
'1234'
;
$data
[
'password'
]
=
'12345678'
;
$data
[
'password_confirmation'
]
=
'12345678'
;
$this
->
withExceptionHandling
()
->
actingAs
(
$this
->
admin
)
->
patch
(
route
(
'admin.access.user.change-password'
,
$this
->
admin
),
$data
)
->
assertSessionHas
(
'The given data was invalid.'
);
}
/** @test */
public
function
a_user_can_change_password
()
{
Event
::
fake
();
$data
=
[];
$data
[
'old_password'
]
=
'1234'
;
$data
[
'password'
]
=
'Viral@1234'
;
$data
[
'password_confirmation'
]
=
'Viral@1234'
;
$this
->
actingAs
(
$this
->
admin
)
->
patch
(
route
(
'admin.access.user.change-password'
,
$this
->
admin
),
$data
)
->
assertSessionHas
([
'flash_success'
=>
trans
(
'alerts.backend.users.updated_password'
)]);
Event
::
assertDispatched
(
UserPasswordChanged
::
class
);
}
}
tests/Feature/Backend/ManageUsersTest.php
View file @
6ebc1d3b
...
...
@@ -2,14 +2,16 @@
namespace
Tests\Feature\Backend
;
use
App\Events\Backend\Access\User\UserCreated
;
use
App\Models\Access\Permission\Permission
;
use
Tests\TestCase
;
use
App\Models\Access\Role\Role
;
use
App\Models\Access\User\User
;
use
App\Notifications\Frontend\Auth\UserNeedsConfirmation
;
use
Illuminate\Support\Facades\Event
;
use
App\Models\Access\Permission\Permission
;
use
Illuminate\Support\Facades\Notification
;
use
Tests\TestCase
;
use
App\Events\Backend\Access\User\UserCreated
;
use
App\Events\Backend\Access\User\UserDeleted
;
use
App\Events\Backend\Access\User\UserUpdated
;
use
App\Notifications\Frontend\Auth\UserNeedsConfirmation
;
class
ManageUsersTest
extends
TestCase
{
...
...
@@ -150,7 +152,6 @@ class ManageUsersTest extends TestCase
$user
=
factory
(
User
::
class
)
->
states
(
'active'
,
'confirmed'
)
->
make
()
->
toArray
();
$role
=
create
(
Role
::
class
);
$permission
=
create
(
Permission
::
class
);
$user
[
'password'
]
=
'Viral@1234'
;
...
...
@@ -160,7 +161,8 @@ class ManageUsersTest extends TestCase
$this
->
actingAs
(
$this
->
admin
)
->
post
(
route
(
'admin.access.user.store'
),
$user
)
->
assertRedirect
(
route
(
'admin.access.user.index'
));
->
assertRedirect
(
route
(
'admin.access.user.index'
))
->
assertSessionHas
([
'flash_success'
=>
trans
(
'alerts.backend.users.created'
)]);
$this
->
assertDatabaseHas
(
config
(
'access.users_table'
),
[
'first_name'
=>
$user
[
'first_name'
],
...
...
@@ -187,7 +189,6 @@ class ManageUsersTest extends TestCase
$user
=
factory
(
User
::
class
)
->
states
(
'active'
)
->
make
()
->
toArray
();
$role
=
create
(
Role
::
class
);
$permission
=
create
(
Permission
::
class
);
$user
[
'password'
]
=
'Viral@1234'
;
...
...
@@ -198,7 +199,8 @@ class ManageUsersTest extends TestCase
$this
->
actingAs
(
$this
->
admin
)
->
post
(
route
(
'admin.access.user.store'
),
$user
)
->
assertRedirect
(
route
(
'admin.access.user.index'
));
->
assertRedirect
(
route
(
'admin.access.user.index'
))
->
assertSessionHas
([
'flash_success'
=>
trans
(
'alerts.backend.users.created'
)]);
$this
->
assertDatabaseHas
(
config
(
'access.users_table'
),
[
'first_name'
=>
$user
[
'first_name'
],
...
...
@@ -220,10 +222,82 @@ class ManageUsersTest extends TestCase
Event
::
assertDispatched
(
UserCreated
::
class
);
}
//@todo
// update user
// delete user
// user can not delete himself
/** @test */
public
function
it_fails_for_validation_on_update_user
()
{
$user
=
create
(
User
::
class
);
$user1
=
$user
->
toArray
();
$user1
[
'first_name'
]
=
''
;
$user1
[
'last_name'
]
=
''
;
$user1
[
'email'
]
=
''
;
$user1
[
'assignees_roles'
]
=
''
;
$user1
[
'permissions'
]
=
''
;
$this
->
withExceptionHandling
()
->
actingAs
(
$this
->
admin
)
->
patch
(
route
(
'admin.access.user.update'
,
$user
),
$user1
)
->
assertSessionHasErrors
([
'first_name'
,
'last_name'
,
'email'
,
'assignees_roles'
,
'permissions'
]);
}
/** @test */
public
function
a_user_can_update_new_user
()
{
Event
::
fake
();
$user
=
create
(
User
::
class
);
$role
=
create
(
Role
::
class
);
$permission
=
create
(
Permission
::
class
);
$data
=
$user
->
toArray
();
$data
[
'first_name'
]
=
'updated first_name'
;
$data
[
'last_name'
]
=
'updated last_name'
;
$data
[
'assignees_roles'
]
=
[
$role
->
id
];
$data
[
'permissions'
]
=
[
$permission
->
id
];
$this
->
actingAs
(
$this
->
admin
)
->
patch
(
route
(
'admin.access.user.update'
,
$user
),
$data
)
->
assertRedirect
(
route
(
'admin.access.user.index'
))
->
assertSessionHas
([
'flash_success'
=>
trans
(
'alerts.backend.users.updated'
)]);
$this
->
assertDatabaseHas
(
config
(
'access.users_table'
),[
'id'
=>
$user
->
id
,
'first_name'
=>
$data
[
'first_name'
],
'last_name'
=>
$data
[
'last_name'
],
]);
Event
::
assertDispatched
(
UserUpdated
::
class
);
}
/** @test */
public
function
a_user_can_delete_a_user
()
{
Event
::
fake
();
$user
=
create
(
User
::
class
);
$this
->
actingAs
(
$this
->
admin
)
->
delete
(
route
(
'admin.access.user.destroy'
,
$user
))
->
assertSessionHas
([
'flash_success'
=>
trans
(
'alerts.backend.users.deleted'
)]);
$this
->
assertDatabaseMissing
(
config
(
'access.users_table'
),
[
'name'
=>
$user
->
first_name
,
'id'
=>
$user
->
id
]);
Event
::
assertDispatched
(
UserDeleted
::
class
);
}
/** @test */
public
function
a_user_can_not_delete_himself
()
{
$this
->
withExceptionHandling
()
->
actingAs
(
$this
->
admin
)
->
delete
(
route
(
'admin.access.user.destroy'
,
$this
->
admin
))
->
assertSessionHas
([
'flash_danger'
=>
trans
(
'exceptions.backend.access.users.cant_delete_self'
)]);
$this
->
assertDatabaseHas
(
config
(
'access.users_table'
),
[
'id'
=>
$this
->
admin
->
id
,
'deleted_at'
=>
null
]);
}
// change password
// export / import feature
}
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