暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PasswordResetTest.php 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. use App\Models\User;
  3. use Illuminate\Auth\Notifications\ResetPassword;
  4. use Illuminate\Support\Facades\Notification;
  5. test('reset password link screen can be rendered', function () {
  6. $response = $this->get('/forgot-password');
  7. $response->assertStatus(200);
  8. });
  9. test('reset password link can be requested', function () {
  10. Notification::fake();
  11. $user = User::factory()->create();
  12. $this->post('/forgot-password', ['email' => $user->email]);
  13. Notification::assertSentTo($user, ResetPassword::class);
  14. });
  15. test('reset password screen can be rendered', function () {
  16. Notification::fake();
  17. $user = User::factory()->create();
  18. $this->post('/forgot-password', ['email' => $user->email]);
  19. Notification::assertSentTo($user, ResetPassword::class, function ($notification) {
  20. $response = $this->get('/reset-password/'.$notification->token);
  21. $response->assertStatus(200);
  22. return true;
  23. });
  24. });
  25. test('password can be reset with valid token', function () {
  26. Notification::fake();
  27. $user = User::factory()->create();
  28. $this->post('/forgot-password', ['email' => $user->email]);
  29. Notification::assertSentTo($user, ResetPassword::class, function ($notification) use ($user) {
  30. $response = $this->post('/reset-password', [
  31. 'token' => $notification->token,
  32. 'email' => $user->email,
  33. 'password' => 'password',
  34. 'password_confirmation' => 'password',
  35. ]);
  36. $response
  37. ->assertSessionHasNoErrors()
  38. ->assertRedirect(route('login'));
  39. return true;
  40. });
  41. });