12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- namespace Tests\Feature\Notifications;
- use App\Models\AuthLog;
- use App\Models\User;
- use App\Notifications\SignedInWithNewDeviceNotification;
- use Illuminate\Notifications\Messages\MailMessage;
- use PHPUnit\Framework\Attributes\CoversClass;
- use PHPUnit\Framework\Attributes\Test;
- use Tests\FeatureTestCase;
- /**
- * SignedInWithNewDeviceNotificationTest test class
- */
- #[CoversClass(SignedInWithNewDeviceNotification::class)]
- class SignedInWithNewDeviceNotificationTest extends FeatureTestCase
- {
- /**
- * @var \App\Models\User
- */
- protected $user;
- /**
- * @var \App\Models\AuthLog
- */
- protected $authLog;
- /**
- * @var \App\Notifications\SignedInWithNewDeviceNotification
- */
- protected $signedInWithNewDevice;
- public function setUp() : void
- {
- parent::setUp();
- $this->user = User::factory()->create();
- AuthLog::factory()->for($this->user, 'authenticatable')->failedLogin()->create();
- $this->authLog = AuthLog::first();
- $this->signedInWithNewDevice = new SignedInWithNewDeviceNotification($this->authLog);
- }
- #[Test]
- public function test_it_renders_to_email()
- {
- $mail = $this->signedInWithNewDevice->toMail($this->user);
- $this->assertInstanceOf(MailMessage::class, $mail);
- }
- #[Test]
- public function test_rendered_email_contains_expected_data()
- {
- $mail = $this->signedInWithNewDevice->toMail($this->user)->render();
- $this->assertStringContainsString(
- $this->authLog->login_at->toCookieString(),
- $mail
- );
- $this->assertStringContainsString(
- $this->authLog->ip_address,
- $mail
- );
- $this->assertStringContainsString(
- $this->user->name,
- $mail
- );
- $this->assertStringContainsString(
- __('admin.browser_on_platform', ['browser' => 'Firefox', 'platform' => 'Windows']),
- $mail
- );
- }
- }
|