AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

PasswordResetTest.php 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace Tests\Feature\Auth;
  3. use App\Models\User;
  4. use Illuminate\Auth\Notifications\ResetPassword;
  5. use Illuminate\Foundation\Testing\RefreshDatabase;
  6. use Illuminate\Support\Facades\Notification;
  7. use Laravel\Fortify\Features;
  8. use Tests\TestCase;
  9. class PasswordResetTest extends TestCase
  10. {
  11. use RefreshDatabase;
  12. protected function setUp(): void
  13. {
  14. parent::setUp();
  15. $this->skipUnlessFortifyHas(Features::resetPasswords());
  16. }
  17. public function test_reset_password_link_screen_can_be_rendered()
  18. {
  19. $response = $this->get(route('password.request'));
  20. $response->assertOk();
  21. }
  22. public function test_reset_password_link_can_be_requested()
  23. {
  24. Notification::fake();
  25. $user = User::factory()->create();
  26. $this->post(route('password.email'), ['email' => $user->email]);
  27. Notification::assertSentTo($user, ResetPassword::class);
  28. }
  29. public function test_reset_password_screen_can_be_rendered()
  30. {
  31. Notification::fake();
  32. $user = User::factory()->create();
  33. $this->post(route('password.email'), ['email' => $user->email]);
  34. Notification::assertSentTo($user, ResetPassword::class, function ($notification) {
  35. $response = $this->get(route('password.reset', $notification->token));
  36. $response->assertOk();
  37. return true;
  38. });
  39. }
  40. public function test_password_can_be_reset_with_valid_token()
  41. {
  42. Notification::fake();
  43. $user = User::factory()->create();
  44. $this->post(route('password.email'), ['email' => $user->email]);
  45. Notification::assertSentTo($user, ResetPassword::class, function ($notification) use ($user) {
  46. $response = $this->post(route('password.update'), [
  47. 'token' => $notification->token,
  48. 'email' => $user->email,
  49. 'password' => 'password',
  50. 'password_confirmation' => 'password',
  51. ]);
  52. $response
  53. ->assertSessionHasNoErrors()
  54. ->assertRedirect(route('login'));
  55. return true;
  56. });
  57. }
  58. public function test_password_cannot_be_reset_with_invalid_token(): void
  59. {
  60. $user = User::factory()->create();
  61. $response = $this->post(route('password.update'), [
  62. 'token' => 'invalid-token',
  63. 'email' => $user->email,
  64. 'password' => 'newpassword123',
  65. 'password_confirmation' => 'newpassword123',
  66. ]);
  67. $response->assertSessionHasErrors('email');
  68. }
  69. }