Files
KanbanGit/tests/Feature/Auth/VerificationNotificationTest.php
T
Twyco a43aff0477
CI/CD / test_and_check_app (push) Failing after 1m34s
CI/CD / Publish immutable image (push) Skipped
CI/CD / test_and_check_app (pull_request) Canceled after 0s
CI/CD / Publish immutable image (pull_request) Canceled after 0s
feat(KAN-21): rebuild login verification and two-factor flows
2026-09-10 11:02:15 +02:00

73 lines
2.0 KiB
PHP

<?php
namespace Tests\Feature\Auth;
use App\Models\User;
use Illuminate\Auth\Notifications\VerifyEmail;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
use Laravel\Fortify\Features;
use Tests\TestCase;
class VerificationNotificationTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
$this->skipUnlessFortifyFeature(Features::emailVerification());
}
public function test_sends_verification_notification(): void
{
Notification::fake();
$user = User::factory()->unverified()->create();
$this->actingAs($user)
->post(route('verification.send'))
->assertRedirect(route('home'))
->assertSessionHas('status', 'verification-link-sent');
Notification::assertSentTo($user, VerifyEmail::class);
}
public function test_does_not_send_verification_notification_if_email_is_verified(): void
{
Notification::fake();
$user = User::factory()->create();
$this->actingAs($user)
->post(route('verification.send'))
->assertRedirect(route('dashboard', absolute: false));
Notification::assertNothingSent();
}
public function test_guests_cannot_request_a_verification_email(): void
{
Notification::fake();
$this->post(route('verification.send'))->assertRedirect(route('login'));
Notification::assertNothingSent();
}
public function test_resending_verification_emails_is_throttled(): void
{
Notification::fake();
$user = User::factory()->unverified()->create();
$this->actingAs($user);
for ($attempt = 0; $attempt < 6; $attempt++) {
$this->post(route('verification.send'))->assertRedirect();
}
$this->post(route('verification.send'))->assertTooManyRequests();
Notification::assertSentToTimes($user, VerifyEmail::class, 6);
}
}