FailedLoginNotificationTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace Tests\Feature\Notifications;
  3. use App\Models\AuthLog;
  4. use App\Models\User;
  5. use App\Notifications\FailedLoginNotification;
  6. use Illuminate\Notifications\Messages\MailMessage;
  7. use PHPUnit\Framework\Attributes\CoversClass;
  8. use PHPUnit\Framework\Attributes\Test;
  9. use Tests\FeatureTestCase;
  10. /**
  11. * FailedLoginTest test class
  12. */
  13. #[CoversClass(FailedLoginNotification::class)]
  14. class FailedLoginNotificationTest extends FeatureTestCase
  15. {
  16. /**
  17. * @var \App\Models\User
  18. */
  19. protected $user;
  20. /**
  21. * @var \App\Models\AuthLog
  22. */
  23. protected $authLog;
  24. /**
  25. * @var \App\Notifications\FailedLoginNotification
  26. */
  27. protected $failedLogin;
  28. public function setUp() : void
  29. {
  30. parent::setUp();
  31. $this->user = User::factory()->create();
  32. AuthLog::factory()->for($this->user, 'authenticatable')->failedLogin()->create();
  33. $this->authLog = AuthLog::first();
  34. $this->failedLogin = new FailedLoginNotification($this->authLog);
  35. }
  36. #[Test]
  37. public function test_it_renders_to_email()
  38. {
  39. $mail = $this->failedLogin->toMail($this->user);
  40. $this->assertInstanceOf(MailMessage::class, $mail);
  41. }
  42. #[Test]
  43. public function test_rendered_email_contains_expected_data()
  44. {
  45. $mail = $this->failedLogin->toMail($this->user)->render();
  46. $this->assertStringContainsString(
  47. $this->authLog->login_at->toCookieString(),
  48. $mail
  49. );
  50. $this->assertStringContainsString(
  51. $this->authLog->ip_address,
  52. $mail
  53. );
  54. $this->assertStringContainsString(
  55. $this->user->name,
  56. $mail
  57. );
  58. $this->assertStringContainsString(
  59. __('admin.browser_on_platform', ['browser' => 'Firefox', 'platform' => 'Windows']),
  60. $mail
  61. );
  62. }
  63. }