From 40ff04855e7191b109d5cca39720cfc469520942 Mon Sep 17 00:00:00 2001 From: Nasir Khan Saikat Date: Thu, 16 May 2024 20:45:48 +0600 Subject: [PATCH 1/3] Change Password Test --- .../Controllers/Backend/UserController.php | 10 +++--- tests/Feature/BackendViewSuperAdminTest.php | 36 +++++++++++++------ 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/app/Http/Controllers/Backend/UserController.php b/app/Http/Controllers/Backend/UserController.php index c55741f1..7914b77c 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 0a47b16b..1154af82 100644 --- a/tests/Feature/BackendViewSuperAdminTest.php +++ b/tests/Feature/BackendViewSuperAdminTest.php @@ -103,7 +103,7 @@ public function test_super_admin_user_can_create_user(): void public function test_super_admin_user_can_show_user(): void { for ($i = 1; $i <= 5; $i++) { - $response = $this->get('/admin/users/'.$i); + $response = $this->get('/admin/users/' . $i); $response->assertStatus(200); } @@ -112,7 +112,7 @@ public function test_super_admin_user_can_show_user(): void public function test_super_admin_user_can_edit_user(): void { for ($i = 1; $i <= 5; $i++) { - $response = $this->get('/admin/users/'.$i.'/edit'); + $response = $this->get('/admin/users/' . $i . '/edit'); $response->assertStatus(200); } @@ -151,7 +151,7 @@ public function test_super_admin_user_can_restore_trashed_user(): void { $model_id = 5; - $response = $this->delete('/admin/users/'.$model_id); + $response = $this->delete('/admin/users/' . $model_id); $response->assertStatus(302); @@ -177,15 +177,31 @@ 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'); + $response = $this->get('/admin/users/' . $i . '/change-password'); $response->assertStatus(200); } } + 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. * @@ -213,7 +229,7 @@ public function test_super_admin_user_can_create_role(): void public function test_super_admin_user_can_show_role(): void { for ($i = 1; $i <= 5; $i++) { - $response = $this->get('/admin/roles/'.$i); + $response = $this->get('/admin/roles/' . $i); $response->assertStatus(200); } @@ -222,7 +238,7 @@ public function test_super_admin_user_can_show_role(): void public function test_super_admin_user_can_edit_role(): void { for ($i = 1; $i <= 5; $i++) { - $response = $this->get('/admin/roles/'.$i.'/edit'); + $response = $this->get('/admin/roles/' . $i . '/edit'); $response->assertStatus(200); } @@ -328,7 +344,7 @@ public function test_super_admin_user_can_restore_trashed_post(): void { $model_id = 5; - $response = $this->delete('/admin/posts/'.$model_id); + $response = $this->delete('/admin/posts/' . $model_id); $response->assertStatus(302); @@ -420,7 +436,7 @@ public function test_super_admin_user_can_restore_trashed_category(): void { $model_id = 5; - $response = $this->delete('/admin/categories/'.$model_id); + $response = $this->delete('/admin/categories/' . $model_id); $response->assertStatus(302); @@ -512,7 +528,7 @@ public function test_super_admin_user_can_restore_trashed_tag(): void { $model_id = 5; - $response = $this->delete('/admin/tags/'.$model_id); + $response = $this->delete('/admin/tags/' . $model_id); $response->assertStatus(302); From 2ff5f407539c6d78cb4d1f5d4fc6d30ce969cb6a Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Thu, 16 May 2024 14:46:48 +0000 Subject: [PATCH 2/3] Apply fixes from StyleCI --- tests/Feature/BackendViewSuperAdminTest.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/Feature/BackendViewSuperAdminTest.php b/tests/Feature/BackendViewSuperAdminTest.php index 1154af82..2ff6ee63 100644 --- a/tests/Feature/BackendViewSuperAdminTest.php +++ b/tests/Feature/BackendViewSuperAdminTest.php @@ -103,7 +103,7 @@ public function test_super_admin_user_can_create_user(): void public function test_super_admin_user_can_show_user(): void { for ($i = 1; $i <= 5; $i++) { - $response = $this->get('/admin/users/' . $i); + $response = $this->get('/admin/users/'.$i); $response->assertStatus(200); } @@ -112,7 +112,7 @@ public function test_super_admin_user_can_show_user(): void public function test_super_admin_user_can_edit_user(): void { for ($i = 1; $i <= 5; $i++) { - $response = $this->get('/admin/users/' . $i . '/edit'); + $response = $this->get('/admin/users/'.$i.'/edit'); $response->assertStatus(200); } @@ -151,7 +151,7 @@ public function test_super_admin_user_can_restore_trashed_user(): void { $model_id = 5; - $response = $this->delete('/admin/users/' . $model_id); + $response = $this->delete('/admin/users/'.$model_id); $response->assertStatus(302); @@ -180,7 +180,7 @@ public function test_super_admin_user_can_restore_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'); + $response = $this->get('/admin/users/'.$i.'/change-password'); $response->assertStatus(200); } @@ -229,7 +229,7 @@ public function test_super_admin_user_can_create_role(): void public function test_super_admin_user_can_show_role(): void { for ($i = 1; $i <= 5; $i++) { - $response = $this->get('/admin/roles/' . $i); + $response = $this->get('/admin/roles/'.$i); $response->assertStatus(200); } @@ -238,7 +238,7 @@ public function test_super_admin_user_can_show_role(): void public function test_super_admin_user_can_edit_role(): void { for ($i = 1; $i <= 5; $i++) { - $response = $this->get('/admin/roles/' . $i . '/edit'); + $response = $this->get('/admin/roles/'.$i.'/edit'); $response->assertStatus(200); } @@ -344,7 +344,7 @@ public function test_super_admin_user_can_restore_trashed_post(): void { $model_id = 5; - $response = $this->delete('/admin/posts/' . $model_id); + $response = $this->delete('/admin/posts/'.$model_id); $response->assertStatus(302); @@ -436,7 +436,7 @@ public function test_super_admin_user_can_restore_trashed_category(): void { $model_id = 5; - $response = $this->delete('/admin/categories/' . $model_id); + $response = $this->delete('/admin/categories/'.$model_id); $response->assertStatus(302); @@ -528,7 +528,7 @@ public function test_super_admin_user_can_restore_trashed_tag(): void { $model_id = 5; - $response = $this->delete('/admin/tags/' . $model_id); + $response = $this->delete('/admin/tags/'.$model_id); $response->assertStatus(302); From 0f714cb585c78c90fe66d663cfd3e19ac3f21802 Mon Sep 17 00:00:00 2001 From: Nasir Khan Saikat Date: Sat, 18 May 2024 12:24:17 +0600 Subject: [PATCH 3/3] update test --- tests/Feature/BackendViewSuperAdminTest.php | 50 ++++++++++++++++++++- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/tests/Feature/BackendViewSuperAdminTest.php b/tests/Feature/BackendViewSuperAdminTest.php index 1154af82..5fae0cd2 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(); @@ -285,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); @@ -292,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); @@ -299,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); @@ -306,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); @@ -313,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); @@ -326,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); @@ -342,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); @@ -359,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); @@ -377,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); @@ -384,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); @@ -391,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); @@ -398,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); @@ -405,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); @@ -418,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); @@ -434,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); @@ -451,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); @@ -469,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); @@ -476,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); @@ -483,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); @@ -490,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); @@ -497,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); @@ -510,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); @@ -526,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); @@ -543,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);