diff --git a/app/Http/Controllers/Backend/UserController.php b/app/Http/Controllers/Backend/UserController.php index c55741f19..7914b77c0 100644 --- a/app/Http/Controllers/Backend/UserController.php +++ b/app/Http/Controllers/Backend/UserController.php @@ -348,10 +348,6 @@ public function changePassword($id) */ public function changePasswordUpdate(Request $request, $id) { - $request->validate([ - 'password' => 'required|confirmed|min:6', - ]); - $module_title = $this->module_title; $module_name = $this->module_name; $module_path = $this->module_path; @@ -361,6 +357,10 @@ public function changePasswordUpdate(Request $request, $id) $module_action = 'Change Password Update'; + $request->validate([ + 'password' => 'required|confirmed|min:6', + ]); + if (! auth()->user()->can('edit_users')) { $id = auth()->user()->id; } @@ -376,7 +376,7 @@ public function changePasswordUpdate(Request $request, $id) logUserAccess("{$module_title} {$module_action} {$$module_name_singular->name} ($id)"); - return redirect("admin/{$module_name}"); + return redirect("admin/{$module_name}/{$id}"); } /** diff --git a/tests/Feature/BackendViewSuperAdminTest.php b/tests/Feature/BackendViewSuperAdminTest.php index 0a47b16b1..51d64ac46 100644 --- a/tests/Feature/BackendViewSuperAdminTest.php +++ b/tests/Feature/BackendViewSuperAdminTest.php @@ -21,9 +21,7 @@ protected function setUp(): void // seed the database $this->seed(); - // Artisan::call('db:seed'); - Artisan::call('laravel-starter:insert-demo-data'); // Get Super Admin $user = User::whereId(1)->first(); @@ -177,7 +175,7 @@ public function test_super_admin_user_can_restore_user(): void $this->assertSoftDeleted($user); } - public function test_super_admin_user_can_change_password_user(): void + public function test_super_admin_user_can_view_change_password_user(): void { for ($i = 1; $i <= 5; $i++) { $response = $this->get('/admin/users/'.$i.'/change-password'); @@ -186,6 +184,22 @@ public function test_super_admin_user_can_change_password_user(): void } } + public function test_super_admin_user_can_update_user_password(): void + { + $user_id = 5; + + $response = $this + ->postJson(route('backend.users.changePasswordUpdate', $user_id), [ + '_method' => 'PATCH', + 'password' => '123456', + 'password_confirmation' => '123456', + ]); + + $response->assertStatus(302); + + $response->assertRedirect(route('backend.users.show', $user_id)); + } + /** * Roles Test. * @@ -269,6 +283,8 @@ public function test_super_admin_user_can_view_logs_view(): void */ public function test_super_admin_user_can_view_posts_index(): void { + Artisan::call('laravel-starter:insert-demo-data'); + $response = $this->get('/admin/posts'); $response->assertStatus(200); @@ -276,6 +292,8 @@ public function test_super_admin_user_can_view_posts_index(): void public function test_super_admin_user_can_create_post(): void { + Artisan::call('laravel-starter:insert-demo-data'); + $response = $this->get('/admin/posts/create'); $response->assertStatus(200); @@ -283,6 +301,8 @@ public function test_super_admin_user_can_create_post(): void public function test_super_admin_user_can_show_post(): void { + Artisan::call('laravel-starter:insert-demo-data'); + $response = $this->get('/admin/posts/1'); $response->assertStatus(200); @@ -290,6 +310,8 @@ public function test_super_admin_user_can_show_post(): void public function test_super_admin_user_can_edit_post(): void { + Artisan::call('laravel-starter:insert-demo-data'); + $response = $this->get('/admin/posts/1/edit'); $response->assertStatus(200); @@ -297,6 +319,8 @@ public function test_super_admin_user_can_edit_post(): void public function test_super_admin_user_can_delete_post(): void { + Artisan::call('laravel-starter:insert-demo-data'); + $model_id = 5; $model = Post::find($model_id); @@ -310,6 +334,8 @@ public function test_super_admin_user_can_delete_post(): void public function test_super_admin_user_can_view_trashed_post(): void { + Artisan::call('laravel-starter:insert-demo-data'); + $model_id = 5; $model = Post::find($model_id); @@ -326,6 +352,8 @@ public function test_super_admin_user_can_view_trashed_post(): void public function test_super_admin_user_can_restore_trashed_post(): void { + Artisan::call('laravel-starter:insert-demo-data'); + $model_id = 5; $response = $this->delete('/admin/posts/'.$model_id); @@ -343,6 +371,8 @@ public function test_super_admin_user_can_restore_trashed_post(): void public function test_super_admin_user_can_restore_post(): void { + Artisan::call('laravel-starter:insert-demo-data'); + $model_id = 5; $model = Post::find($model_id); @@ -361,6 +391,8 @@ public function test_super_admin_user_can_restore_post(): void */ public function test_super_admin_user_can_view_categories_index(): void { + Artisan::call('laravel-starter:insert-demo-data'); + $response = $this->get('/admin/categories'); $response->assertStatus(200); @@ -368,6 +400,8 @@ public function test_super_admin_user_can_view_categories_index(): void public function test_super_admin_user_can_create_category(): void { + Artisan::call('laravel-starter:insert-demo-data'); + $response = $this->get('/admin/categories/create'); $response->assertStatus(200); @@ -375,6 +409,8 @@ public function test_super_admin_user_can_create_category(): void public function test_super_admin_user_can_show_category(): void { + Artisan::call('laravel-starter:insert-demo-data'); + $response = $this->get('/admin/categories/1'); $response->assertStatus(200); @@ -382,6 +418,8 @@ public function test_super_admin_user_can_show_category(): void public function test_super_admin_user_can_edit_category(): void { + Artisan::call('laravel-starter:insert-demo-data'); + $response = $this->get('/admin/categories/1/edit'); $response->assertStatus(200); @@ -389,6 +427,8 @@ public function test_super_admin_user_can_edit_category(): void public function test_super_admin_user_can_delete_category(): void { + Artisan::call('laravel-starter:insert-demo-data'); + $model_id = 5; $model = Category::find($model_id); @@ -402,6 +442,8 @@ public function test_super_admin_user_can_delete_category(): void public function test_super_admin_user_can_view_trashed_category(): void { + Artisan::call('laravel-starter:insert-demo-data'); + $model_id = 5; $model = Category::find($model_id); @@ -418,6 +460,8 @@ public function test_super_admin_user_can_view_trashed_category(): void public function test_super_admin_user_can_restore_trashed_category(): void { + Artisan::call('laravel-starter:insert-demo-data'); + $model_id = 5; $response = $this->delete('/admin/categories/'.$model_id); @@ -435,6 +479,8 @@ public function test_super_admin_user_can_restore_trashed_category(): void public function test_super_admin_user_can_restore_category(): void { + Artisan::call('laravel-starter:insert-demo-data'); + $model_id = 5; $model = Category::find($model_id); @@ -453,6 +499,8 @@ public function test_super_admin_user_can_restore_category(): void */ public function test_super_admin_user_can_view_tags_index(): void { + Artisan::call('laravel-starter:insert-demo-data'); + $response = $this->get('/admin/tags'); $response->assertStatus(200); @@ -460,6 +508,8 @@ public function test_super_admin_user_can_view_tags_index(): void public function test_super_admin_user_can_create_tag(): void { + Artisan::call('laravel-starter:insert-demo-data'); + $response = $this->get('/admin/tags/create'); $response->assertStatus(200); @@ -467,6 +517,8 @@ public function test_super_admin_user_can_create_tag(): void public function test_super_admin_user_can_show_tag(): void { + Artisan::call('laravel-starter:insert-demo-data'); + $response = $this->get('/admin/tags/1'); $response->assertStatus(200); @@ -474,6 +526,8 @@ public function test_super_admin_user_can_show_tag(): void public function test_super_admin_user_can_edit_tag(): void { + Artisan::call('laravel-starter:insert-demo-data'); + $response = $this->get('/admin/tags/1/edit'); $response->assertStatus(200); @@ -481,6 +535,8 @@ public function test_super_admin_user_can_edit_tag(): void public function test_super_admin_user_can_delete_tag(): void { + Artisan::call('laravel-starter:insert-demo-data'); + $model_id = 5; $model = Tag::find($model_id); @@ -494,6 +550,8 @@ public function test_super_admin_user_can_delete_tag(): void public function test_super_admin_user_can_view_trashed_tag(): void { + Artisan::call('laravel-starter:insert-demo-data'); + $model_id = 5; $model = Tag::find($model_id); @@ -510,6 +568,8 @@ public function test_super_admin_user_can_view_trashed_tag(): void public function test_super_admin_user_can_restore_trashed_tag(): void { + Artisan::call('laravel-starter:insert-demo-data'); + $model_id = 5; $response = $this->delete('/admin/tags/'.$model_id); @@ -527,6 +587,8 @@ public function test_super_admin_user_can_restore_trashed_tag(): void public function test_super_admin_user_can_restore_tag(): void { + Artisan::call('laravel-starter:insert-demo-data'); + $model_id = 5; $model = Tag::find($model_id);