Skip to content

Commit

Permalink
Merge pull request #599 from nasirkhan/tests
Browse files Browse the repository at this point in the history
Test update
  • Loading branch information
nasirkhan authored May 18, 2024
2 parents 497f8b2 + af776d5 commit c1b05a7
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 8 deletions.
10 changes: 5 additions & 5 deletions app/Http/Controllers/Backend/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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}");
}

/**
Expand Down
68 changes: 65 additions & 3 deletions tests/Feature/BackendViewSuperAdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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');
Expand All @@ -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.
*
Expand Down Expand Up @@ -269,34 +283,44 @@ 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);
}

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);
}

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);
}

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);
}

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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -361,34 +391,44 @@ 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);
}

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);
}

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);
}

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);
}

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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -453,34 +499,44 @@ 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);
}

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);
}

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);
}

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);
}

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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit c1b05a7

Please sign in to comment.