]> git.localhorst.tv Git - alttp.git/blob - tests/Feature/Auth/EmailVerificationTest.php
add discord auth
[alttp.git] / tests / Feature / Auth / EmailVerificationTest.php
1 <?php
2
3 namespace Tests\Feature\Auth;
4
5 use App\Models\User;
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;
11 use Tests\TestCase;
12
13 class EmailVerificationTest extends TestCase
14 {
15     use RefreshDatabase;
16
17     public function test_email_verification_screen_can_be_rendered()
18     {
19         $user = User::factory()->create([
20             'email_verified_at' => null,
21         ]);
22
23         $response = $this->actingAs($user)->get('/verify-email');
24
25         $response->assertStatus(200);
26     }
27
28     public function test_email_can_be_verified()
29     {
30         $user = User::factory()->create([
31             'email_verified_at' => null,
32         ]);
33
34         Event::fake();
35
36         $verificationUrl = URL::temporarySignedRoute(
37             'verification.verify',
38             now()->addMinutes(60),
39             ['id' => $user->id, 'hash' => sha1($user->email)]
40         );
41
42         $response = $this->actingAs($user)->get($verificationUrl);
43
44         Event::assertDispatched(Verified::class);
45         $this->assertTrue($user->fresh()->hasVerifiedEmail());
46         $response->assertRedirect(RouteServiceProvider::HOME.'?verified=1');
47     }
48
49     public function test_email_is_not_verified_with_invalid_hash()
50     {
51         $user = User::factory()->create([
52             'email_verified_at' => null,
53         ]);
54
55         $verificationUrl = URL::temporarySignedRoute(
56             'verification.verify',
57             now()->addMinutes(60),
58             ['id' => $user->id, 'hash' => sha1('wrong-email')]
59         );
60
61         $this->actingAs($user)->get($verificationUrl);
62
63         $this->assertFalse($user->fresh()->hasVerifiedEmail());
64     }
65 }