3 namespace Tests\Feature\Auth;
6 use App\Providers\RouteServiceProvider;
7 use Illuminate\Auth\Events\Verified;
8 use Illuminate\Foundation\Testing\RefreshDatabase;
9 use Illuminate\Support\Facades\Event;
10 use Illuminate\Support\Facades\URL;
13 class EmailVerificationTest extends TestCase
17 public function test_email_verification_screen_can_be_rendered()
19 $user = User::factory()->create([
20 'email_verified_at' => null,
23 $response = $this->actingAs($user)->get('/verify-email');
25 $response->assertStatus(200);
28 public function test_email_can_be_verified()
30 $user = User::factory()->create([
31 'email_verified_at' => null,
36 $verificationUrl = URL::temporarySignedRoute(
37 'verification.verify',
38 now()->addMinutes(60),
39 ['id' => $user->id, 'hash' => sha1($user->email)]
42 $response = $this->actingAs($user)->get($verificationUrl);
44 Event::assertDispatched(Verified::class);
45 $this->assertTrue($user->fresh()->hasVerifiedEmail());
46 $response->assertRedirect(RouteServiceProvider::HOME.'?verified=1');
49 public function test_email_is_not_verified_with_invalid_hash()
51 $user = User::factory()->create([
52 'email_verified_at' => null,
55 $verificationUrl = URL::temporarySignedRoute(
56 'verification.verify',
57 now()->addMinutes(60),
58 ['id' => $user->id, 'hash' => sha1('wrong-email')]
61 $this->actingAs($user)->get($verificationUrl);
63 $this->assertFalse($user->fresh()->hasVerifiedEmail());