Mercurial > packages > auth
comparison stubs/default/tests/Feature/Auth/EmailVerificationTest.php @ 0:90e38de8f2ba
Initial Commit
| author | luka |
|---|---|
| date | Wed, 13 Aug 2025 22:17:20 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:90e38de8f2ba |
|---|---|
| 1 <?php | |
| 2 | |
| 3 namespace Tests\Feature\Auth; | |
| 4 | |
| 5 use App\Models\User; | |
| 6 use Illuminate\Auth\Events\Verified; | |
| 7 use Illuminate\Foundation\Testing\RefreshDatabase; | |
| 8 use Illuminate\Support\Facades\Event; | |
| 9 use Illuminate\Support\Facades\URL; | |
| 10 use Tests\TestCase; | |
| 11 | |
| 12 class EmailVerificationTest extends TestCase | |
| 13 { | |
| 14 use RefreshDatabase; | |
| 15 | |
| 16 public function test_email_verification_screen_can_be_rendered(): void | |
| 17 { | |
| 18 $user = User::factory()->unverified()->create(); | |
| 19 | |
| 20 $response = $this->actingAs($user)->get('/verify-email'); | |
| 21 | |
| 22 $response->assertStatus(200); | |
| 23 } | |
| 24 | |
| 25 public function test_email_can_be_verified(): void | |
| 26 { | |
| 27 $user = User::factory()->unverified()->create(); | |
| 28 | |
| 29 Event::fake(); | |
| 30 | |
| 31 $verificationUrl = URL::temporarySignedRoute( | |
| 32 'verification.verify', | |
| 33 now()->addMinutes(60), | |
| 34 ['id' => $user->id, 'hash' => sha1($user->email)] | |
| 35 ); | |
| 36 | |
| 37 $response = $this->actingAs($user)->get($verificationUrl); | |
| 38 | |
| 39 Event::assertDispatched(Verified::class); | |
| 40 $this->assertTrue($user->fresh()->hasVerifiedEmail()); | |
| 41 $response->assertRedirect(route('dashboard', absolute: false).'?verified=1'); | |
| 42 } | |
| 43 | |
| 44 public function test_email_is_not_verified_with_invalid_hash(): void | |
| 45 { | |
| 46 $user = User::factory()->unverified()->create(); | |
| 47 | |
| 48 $verificationUrl = URL::temporarySignedRoute( | |
| 49 'verification.verify', | |
| 50 now()->addMinutes(60), | |
| 51 ['id' => $user->id, 'hash' => sha1('wrong-email')] | |
| 52 ); | |
| 53 | |
| 54 $this->actingAs($user)->get($verificationUrl); | |
| 55 | |
| 56 $this->assertFalse($user->fresh()->hasVerifiedEmail()); | |
| 57 } | |
| 58 } |
