SignedInWithNewDeviceNotificationTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace Tests\Feature\Notifications;
  3. use App\Models\AuthLog;
  4. use App\Models\User;
  5. use App\Notifications\SignedInWithNewDeviceNotification;
  6. use Illuminate\Notifications\Messages\MailMessage;
  7. use PHPUnit\Framework\Attributes\CoversClass;
  8. use PHPUnit\Framework\Attributes\Test;
  9. use Tests\FeatureTestCase;
  10. /**
  11. * SignedInWithNewDeviceNotificationTest test class
  12. */
  13. #[CoversClass(SignedInWithNewDeviceNotification::class)]
  14. class SignedInWithNewDeviceNotificationTest 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\SignedInWithNewDeviceNotification
  26. */
  27. protected $signedInWithNewDevice;
  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->signedInWithNewDevice = new SignedInWithNewDeviceNotification($this->authLog);
  35. }
  36. #[Test]
  37. public function test_it_renders_to_email()
  38. {
  39. $mail = $this->signedInWithNewDevice->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->signedInWithNewDevice->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. }