createOne([ 'email_verified_at' => null, ]); $response = $this->actingAs($user)->get(route('verification.notice')); $response->assertStatus(200); } /** * Email can be verified. * * @return void */ public function testEmailCanBeVerified(): void { if (! Features::enabled(Features::emailVerification())) { static::markTestSkipped('Email verification not enabled.'); } Event::fake(); $user = User::factory()->createOne([ 'email_verified_at' => null, ]); $verificationUrl = URL::temporarySignedRoute( 'verification.verify', now()->addMinutes(60), ['id' => $user->id, 'hash' => sha1($user->email)] ); $response = $this->actingAs($user)->get($verificationUrl); Event::assertDispatched(Verified::class); static::assertTrue($user->fresh()->hasVerifiedEmail()); $response->assertRedirect(RouteServiceProvider::HOME.'?verified=1'); } /** * Email cannot be verified with invalid hash. * * @return void */ public function testEmailCanNotBeVerifiedWithInvalidHash(): void { if (! Features::enabled(Features::emailVerification())) { static::markTestSkipped('Email verification not enabled.'); } $user = User::factory()->createOne([ 'email_verified_at' => null, ]); $verificationUrl = URL::temporarySignedRoute( 'verification.verify', now()->addMinutes(60), ['id' => $user->id, 'hash' => sha1('wrong-email')] ); $this->actingAs($user)->get($verificationUrl); static::assertFalse($user->fresh()->hasVerifiedEmail()); } }