46 lines
1.2 KiB
PHP
46 lines
1.2 KiB
PHP
<?php
|
|
|
|
use App\Models\User;
|
|
use App\Notifications\VerifyEmailNotification;
|
|
use Illuminate\Support\Facades\Notification;
|
|
|
|
test('sends verification notification', function () {
|
|
Notification::fake();
|
|
|
|
$user = User::factory()->create([
|
|
'email_verified_at' => null,
|
|
]);
|
|
|
|
$this->actingAs($user)
|
|
->post(route('verification.send'))
|
|
->assertRedirect(route('home'));
|
|
|
|
Notification::assertSentTo($user, VerifyEmailNotification::class);
|
|
});
|
|
|
|
test('verification email links to the public signed route', function () {
|
|
$user = User::factory()->create([
|
|
'email_verified_at' => null,
|
|
]);
|
|
|
|
$mail = (new VerifyEmailNotification)->toMail($user);
|
|
|
|
expect($mail->viewData['verificationUrl'])
|
|
->toContain('/verify-email/'.$user->id.'/'.sha1($user->email))
|
|
->toContain('signature=');
|
|
});
|
|
|
|
test('does not send verification notification if email is verified', function () {
|
|
Notification::fake();
|
|
|
|
$user = User::factory()->create([
|
|
'email_verified_at' => now(),
|
|
]);
|
|
|
|
$this->actingAs($user)
|
|
->post(route('verification.send'))
|
|
->assertRedirect(route('dashboard', absolute: false));
|
|
|
|
Notification::assertNothingSent();
|
|
});
|