WebauthnRecoveryNotificationTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace Tests\Feature\Notifications;
  3. use App\Models\User;
  4. use App\Notifications\WebauthnRecoveryNotification;
  5. use Illuminate\Notifications\Messages\MailMessage;
  6. use Illuminate\Support\Facades\Lang;
  7. use PHPUnit\Framework\Attributes\CoversClass;
  8. use PHPUnit\Framework\Attributes\Test;
  9. use Tests\FeatureTestCase;
  10. /**
  11. * WebauthnRecoveryNotificationTest test class
  12. */
  13. #[CoversClass(WebauthnRecoveryNotification::class)]
  14. class WebauthnRecoveryNotificationTest extends FeatureTestCase
  15. {
  16. /**
  17. * @var \App\Models\User
  18. */
  19. protected $user;
  20. /**
  21. * @var \App\Notifications\WebauthnRecoveryNotification
  22. */
  23. protected $webauthnRecoveryNotification;
  24. public function setUp() : void
  25. {
  26. parent::setUp();
  27. $this->user = User::factory()->create();
  28. $this->webauthnRecoveryNotification = new WebauthnRecoveryNotification('test_token');
  29. }
  30. #[Test]
  31. public function test_it_renders_to_email()
  32. {
  33. $mail = $this->webauthnRecoveryNotification->toMail($this->user);
  34. $this->assertInstanceOf(MailMessage::class, $mail);
  35. }
  36. #[Test]
  37. public function test_rendered_email_contains_expected_data()
  38. {
  39. $mail = $this->webauthnRecoveryNotification->toMail($this->user)->render();
  40. $this->assertStringContainsString(
  41. 'http://localhost/webauthn/recover?token=test_token&amp;email=' . urlencode($this->user->email),
  42. $mail
  43. );
  44. $this->assertStringContainsString(
  45. Lang::get('Recover Account'),
  46. $mail
  47. );
  48. $this->assertStringContainsString(
  49. Lang::get(
  50. 'You are receiving this email because we received an account recovery request for your account.'
  51. ),
  52. $mail
  53. );
  54. $this->assertStringContainsString(
  55. Lang::get(
  56. 'This recovery link will expire in :count minutes.',
  57. ['count' => config('auth.passwords.webauthn.expire')]
  58. ),
  59. $mail
  60. );
  61. $this->assertStringContainsString(
  62. Lang::get('If you did not request an account recovery, no further action is required.'),
  63. $mail
  64. );
  65. }
  66. }