diff --git a/routes/auth.php b/routes/auth.php index 1351b3fb..168a9f4b 100644 --- a/routes/auth.php +++ b/routes/auth.php @@ -14,12 +14,14 @@ Route::get('register', [RegisteredUserController::class, 'create']) ->name('register'); - Route::post('register', [RegisteredUserController::class, 'store']); + Route::post('register', [RegisteredUserController::class, 'store']) + ->name('register.store'); Route::get('login', [AuthenticatedSessionController::class, 'create']) ->name('login'); - Route::post('login', [AuthenticatedSessionController::class, 'store']); + Route::post('login', [AuthenticatedSessionController::class, 'store']) + ->name('login.store'); Route::get('forgot-password', [PasswordResetLinkController::class, 'create']) ->name('password.request'); @@ -50,7 +52,8 @@ ->name('password.confirm'); Route::post('confirm-password', [ConfirmablePasswordController::class, 'store']) - ->middleware('throttle:6,1'); + ->middleware('throttle:6,1') + ->name('password.confirm.store'); Route::post('logout', [AuthenticatedSessionController::class, 'destroy']) ->name('logout'); diff --git a/tests/Feature/Auth/AuthenticationTest.php b/tests/Feature/Auth/AuthenticationTest.php index a53c560a..46578335 100644 --- a/tests/Feature/Auth/AuthenticationTest.php +++ b/tests/Feature/Auth/AuthenticationTest.php @@ -12,7 +12,7 @@ class AuthenticationTest extends TestCase public function test_login_screen_can_be_rendered() { - $response = $this->get('/login'); + $response = $this->get(route('login')); $response->assertStatus(200); } @@ -21,7 +21,7 @@ public function test_users_can_authenticate_using_the_login_screen() { $user = User::factory()->create(); - $response = $this->post('/login', [ + $response = $this->post(route('login.store'), [ 'email' => $user->email, 'password' => 'password', ]); @@ -34,7 +34,7 @@ public function test_users_can_not_authenticate_with_invalid_password() { $user = User::factory()->create(); - $this->post('/login', [ + $this->post(route('login.store'), [ 'email' => $user->email, 'password' => 'wrong-password', ]); @@ -46,10 +46,10 @@ public function test_users_can_logout() { $user = User::factory()->create(); - $response = $this->actingAs($user)->post('/logout'); + $response = $this->actingAs($user)->post(route('logout')); $this->assertGuest(); - $response->assertRedirect('/'); + $response->assertRedirect(route('home')); } public function test_users_are_rate_limited() @@ -57,7 +57,7 @@ public function test_users_are_rate_limited() $user = User::factory()->create(); for ($i = 0; $i < 5; $i++) { - $this->post('/login', [ + $this->post(route('login.store'), [ 'email' => $user->email, 'password' => 'wrong-password', ])->assertStatus(302)->assertSessionHasErrors([ @@ -65,7 +65,7 @@ public function test_users_are_rate_limited() ]); } - $response = $this->post('/login', [ + $response = $this->post(route('login.store'), [ 'email' => $user->email, 'password' => 'wrong-password', ]); diff --git a/tests/Feature/Auth/EmailVerificationTest.php b/tests/Feature/Auth/EmailVerificationTest.php index 0ce64e02..8eaba3cf 100644 --- a/tests/Feature/Auth/EmailVerificationTest.php +++ b/tests/Feature/Auth/EmailVerificationTest.php @@ -17,7 +17,7 @@ public function test_email_verification_screen_can_be_rendered() { $user = User::factory()->unverified()->create(); - $response = $this->actingAs($user)->get('/verify-email'); + $response = $this->actingAs($user)->get(route('verification.notice')); $response->assertStatus(200); } @@ -79,7 +79,7 @@ public function test_verified_user_is_redirected_to_dashboard_from_verification_ 'email_verified_at' => now(), ]); - $response = $this->actingAs($user)->get('/verify-email'); + $response = $this->actingAs($user)->get(route('verification.notice')); $response->assertRedirect(route('dashboard', absolute: false)); } diff --git a/tests/Feature/Auth/PasswordConfirmationTest.php b/tests/Feature/Auth/PasswordConfirmationTest.php index d2072ffd..9ff9f005 100644 --- a/tests/Feature/Auth/PasswordConfirmationTest.php +++ b/tests/Feature/Auth/PasswordConfirmationTest.php @@ -14,7 +14,7 @@ public function test_confirm_password_screen_can_be_rendered() { $user = User::factory()->create(); - $response = $this->actingAs($user)->get('/confirm-password'); + $response = $this->actingAs($user)->get(route('password.confirm')); $response->assertStatus(200); } @@ -23,7 +23,7 @@ public function test_password_can_be_confirmed() { $user = User::factory()->create(); - $response = $this->actingAs($user)->post('/confirm-password', [ + $response = $this->actingAs($user)->post(route('password.confirm.store'), [ 'password' => 'password', ]); @@ -35,7 +35,7 @@ public function test_password_is_not_confirmed_with_invalid_password() { $user = User::factory()->create(); - $response = $this->actingAs($user)->post('/confirm-password', [ + $response = $this->actingAs($user)->post(route('password.confirm.store'), [ 'password' => 'wrong-password', ]); diff --git a/tests/Feature/Auth/PasswordResetTest.php b/tests/Feature/Auth/PasswordResetTest.php index 71c6ef1e..254d2885 100644 --- a/tests/Feature/Auth/PasswordResetTest.php +++ b/tests/Feature/Auth/PasswordResetTest.php @@ -14,7 +14,7 @@ class PasswordResetTest extends TestCase public function test_reset_password_link_screen_can_be_rendered() { - $response = $this->get('/forgot-password'); + $response = $this->get(route('password.request')); $response->assertStatus(200); } @@ -25,7 +25,7 @@ public function test_reset_password_link_can_be_requested() $user = User::factory()->create(); - $this->post('/forgot-password', ['email' => $user->email]); + $this->post(route('password.email'), ['email' => $user->email]); Notification::assertSentTo($user, ResetPassword::class); } @@ -36,10 +36,10 @@ public function test_reset_password_screen_can_be_rendered() $user = User::factory()->create(); - $this->post('/forgot-password', ['email' => $user->email]); + $this->post(route('password.email'), ['email' => $user->email]); Notification::assertSentTo($user, ResetPassword::class, function ($notification) { - $response = $this->get('/reset-password/'.$notification->token); + $response = $this->get(route('password.request', $notification->token)); $response->assertStatus(200); @@ -53,10 +53,10 @@ public function test_password_can_be_reset_with_valid_token() $user = User::factory()->create(); - $this->post('/forgot-password', ['email' => $user->email]); + $this->post(route('password.email'), ['email' => $user->email]); Notification::assertSentTo($user, ResetPassword::class, function ($notification) use ($user) { - $response = $this->post('/reset-password', [ + $response = $this->post(route('password.store'), [ 'token' => $notification->token, 'email' => $user->email, 'password' => 'password', @@ -75,7 +75,7 @@ public function test_password_cannot_be_reset_with_invalid_token(): void { $user = User::factory()->create(); - $response = $this->post('/reset-password', [ + $response = $this->post(route('password.store'), [ 'token' => 'invalid-token', 'email' => $user->email, 'password' => 'newpassword123', diff --git a/tests/Feature/Auth/RegistrationTest.php b/tests/Feature/Auth/RegistrationTest.php index d0c3ea25..16cc907d 100644 --- a/tests/Feature/Auth/RegistrationTest.php +++ b/tests/Feature/Auth/RegistrationTest.php @@ -11,14 +11,14 @@ class RegistrationTest extends TestCase public function test_registration_screen_can_be_rendered() { - $response = $this->get('/register'); + $response = $this->get(route('register')); $response->assertStatus(200); } public function test_new_users_can_register() { - $response = $this->post('/register', [ + $response = $this->post(route('register.store'), [ 'name' => 'Test User', 'email' => 'test@example.com', 'password' => 'password', diff --git a/tests/Feature/Auth/VerificationNotificationTest.php b/tests/Feature/Auth/VerificationNotificationTest.php index ccf3c07f..34a81a81 100644 --- a/tests/Feature/Auth/VerificationNotificationTest.php +++ b/tests/Feature/Auth/VerificationNotificationTest.php @@ -21,8 +21,8 @@ public function test_sends_verification_notification(): void ]); $this->actingAs($user) - ->post('email/verification-notification') - ->assertRedirect('/'); + ->post(route('verification.send')) + ->assertRedirect(route('home')); Notification::assertSentTo($user, VerifyEmail::class); } @@ -36,7 +36,7 @@ public function test_does_not_send_verification_notification_if_email_is_verifie ]); $this->actingAs($user) - ->post('email/verification-notification') + ->post(route('verification.send')) ->assertRedirect(route('dashboard', absolute: false)); Notification::assertNothingSent(); diff --git a/tests/Feature/DashboardTest.php b/tests/Feature/DashboardTest.php index 5903f8f2..853643b5 100644 --- a/tests/Feature/DashboardTest.php +++ b/tests/Feature/DashboardTest.php @@ -12,8 +12,8 @@ class DashboardTest extends TestCase public function test_guests_are_redirected_to_the_login_page() { - $response = $this->get('/dashboard'); - $response->assertRedirect('/login'); + $response = $this->get(route('dashboard')); + $response->assertRedirect(route('login')); } public function test_authenticated_users_can_visit_the_dashboard() @@ -21,7 +21,7 @@ public function test_authenticated_users_can_visit_the_dashboard() $user = User::factory()->create(); $this->actingAs($user); - $response = $this->get('/dashboard'); + $response = $this->get(route('dashboard')); $response->assertStatus(200); } } diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php index c3dd53d0..57b337fc 100644 --- a/tests/Feature/ExampleTest.php +++ b/tests/Feature/ExampleTest.php @@ -11,7 +11,7 @@ class ExampleTest extends TestCase public function test_returns_a_successful_response() { - $response = $this->get('/'); + $response = $this->get(route('home')); $response->assertStatus(200); } diff --git a/tests/Feature/Settings/PasswordUpdateTest.php b/tests/Feature/Settings/PasswordUpdateTest.php index ae1ce618..c1665294 100644 --- a/tests/Feature/Settings/PasswordUpdateTest.php +++ b/tests/Feature/Settings/PasswordUpdateTest.php @@ -17,7 +17,7 @@ public function test_password_update_page_is_displayed() $response = $this ->actingAs($user) - ->get('/settings/password'); + ->get(route('password.edit')); $response->assertStatus(200); } @@ -28,8 +28,8 @@ public function test_password_can_be_updated() $response = $this ->actingAs($user) - ->from('/settings/password') - ->put('/settings/password', [ + ->from(route('password.edit')) + ->put(route('password.update'), [ 'current_password' => 'password', 'password' => 'new-password', 'password_confirmation' => 'new-password', @@ -37,7 +37,7 @@ public function test_password_can_be_updated() $response ->assertSessionHasNoErrors() - ->assertRedirect('/settings/password'); + ->assertRedirect(route('password.edit')); $this->assertTrue(Hash::check('new-password', $user->refresh()->password)); } @@ -48,8 +48,8 @@ public function test_correct_password_must_be_provided_to_update_password() $response = $this ->actingAs($user) - ->from('/settings/password') - ->put('/settings/password', [ + ->from(route('password.edit')) + ->put(route('password.update'), [ 'current_password' => 'wrong-password', 'password' => 'new-password', 'password_confirmation' => 'new-password', @@ -57,6 +57,6 @@ public function test_correct_password_must_be_provided_to_update_password() $response ->assertSessionHasErrors('current_password') - ->assertRedirect('/settings/password'); + ->assertRedirect(route('password.edit')); } } diff --git a/tests/Feature/Settings/ProfileUpdateTest.php b/tests/Feature/Settings/ProfileUpdateTest.php index 7d512144..e6c95cee 100644 --- a/tests/Feature/Settings/ProfileUpdateTest.php +++ b/tests/Feature/Settings/ProfileUpdateTest.php @@ -16,7 +16,7 @@ public function test_profile_page_is_displayed() $response = $this ->actingAs($user) - ->get('/settings/profile'); + ->get(route('profile.edit')); $response->assertOk(); } @@ -27,14 +27,14 @@ public function test_profile_information_can_be_updated() $response = $this ->actingAs($user) - ->patch('/settings/profile', [ + ->patch(route('profile.update'), [ 'name' => 'Test User', 'email' => 'test@example.com', ]); $response ->assertSessionHasNoErrors() - ->assertRedirect('/settings/profile'); + ->assertRedirect(route('profile.edit')); $user->refresh(); @@ -49,14 +49,14 @@ public function test_email_verification_status_is_unchanged_when_the_email_addre $response = $this ->actingAs($user) - ->patch('/settings/profile', [ + ->patch(route('profile.update'), [ 'name' => 'Test User', 'email' => $user->email, ]); $response ->assertSessionHasNoErrors() - ->assertRedirect('/settings/profile'); + ->assertRedirect(route('profile.edit')); $this->assertNotNull($user->refresh()->email_verified_at); } @@ -67,13 +67,13 @@ public function test_user_can_delete_their_account() $response = $this ->actingAs($user) - ->delete('/settings/profile', [ + ->delete(route('profile.destroy'), [ 'password' => 'password', ]); $response ->assertSessionHasNoErrors() - ->assertRedirect('/'); + ->assertRedirect(route('home')); $this->assertGuest(); $this->assertNull($user->fresh()); @@ -85,14 +85,14 @@ public function test_correct_password_must_be_provided_to_delete_account() $response = $this ->actingAs($user) - ->from('/settings/profile') - ->delete('/settings/profile', [ + ->from(route('profile.edit')) + ->delete(route('profile.destroy'), [ 'password' => 'wrong-password', ]); $response ->assertSessionHasErrors('password') - ->assertRedirect('/settings/profile'); + ->assertRedirect(route('profile.edit')); $this->assertNotNull($user->fresh()); }