No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

EmailVerificationTest.php 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. use App\Models\User;
  3. use App\Providers\RouteServiceProvider;
  4. use Illuminate\Auth\Events\Verified;
  5. use Illuminate\Support\Facades\Event;
  6. use Illuminate\Support\Facades\URL;
  7. test('email verification screen can be rendered', function () {
  8. $user = User::factory()->create([
  9. 'email_verified_at' => null,
  10. ]);
  11. $response = $this->actingAs($user)->get('/verify-email');
  12. $response->assertStatus(200);
  13. });
  14. test('email can be verified', function () {
  15. $user = User::factory()->create([
  16. 'email_verified_at' => null,
  17. ]);
  18. Event::fake();
  19. $verificationUrl = URL::temporarySignedRoute(
  20. 'verification.verify',
  21. now()->addMinutes(60),
  22. ['id' => $user->id, 'hash' => sha1($user->email)]
  23. );
  24. $response = $this->actingAs($user)->get($verificationUrl);
  25. Event::assertDispatched(Verified::class);
  26. expect($user->fresh()->hasVerifiedEmail())->toBeTrue();
  27. $response->assertRedirect(RouteServiceProvider::HOME.'?verified=1');
  28. });
  29. test('email is not verified with invalid hash', function () {
  30. $user = User::factory()->create([
  31. 'email_verified_at' => null,
  32. ]);
  33. $verificationUrl = URL::temporarySignedRoute(
  34. 'verification.verify',
  35. now()->addMinutes(60),
  36. ['id' => $user->id, 'hash' => sha1('wrong-email')]
  37. );
  38. $this->actingAs($user)->get($verificationUrl);
  39. expect($user->fresh()->hasVerifiedEmail())->toBeFalse();
  40. });