Add option to enable email verification locally for testing

This commit is contained in:
Constantin Graf
2026-06-11 10:17:56 +02:00
committed by Constantin Graf
parent 111ce94150
commit 24c94af952
3 changed files with 37 additions and 2 deletions

View File

@@ -73,13 +73,14 @@ class EnsureEmailIsVerifiedMiddlewareTest extends MiddlewareTestAbstract
$response->assertOk();
}
public function test_users_with_unverified_email_can_access_route_in_local_environment(): void
public function test_users_with_unverified_email_can_access_route_in_local_environment_if_local_email_verification_is_disabled(): void
{
// Arrange
$user = User::factory()->unverified()->create();
$route = $this->createTestRoute();
$this->actingAs($user);
$this->app->detectEnvironment(fn () => 'local');
config(['app.local_email_verification' => false]);
// Act
$response = $this->get($route);
@@ -87,4 +88,36 @@ class EnsureEmailIsVerifiedMiddlewareTest extends MiddlewareTestAbstract
// Assert
$response->assertOk();
}
public function tests_users_with_unverified_email_are_redirected_in_non_local_environment_even_if_local_email_verification_is_disabled(): void
{
// Arrange
$user = User::factory()->unverified()->create();
$route = $this->createTestRoute();
$this->actingAs($user);
$this->assertSame('testing', config('app.env'));
config(['app.local_email_verification' => false]);
// Act
$response = $this->get($route);
// Assert
$response->assertRedirect(route('verification.notice'));
}
public function test_users_with_unverified_email_are_redirected_in_local_environment_if_local_email_verification_is_enabled(): void
{
// Arrange
$user = User::factory()->unverified()->create();
$route = $this->createTestRoute();
$this->actingAs($user);
$this->app->detectEnvironment(fn () => 'local');
config(['app.local_email_verification' => true]);
// Act
$response = $this->get($route);
// Assert
$response->assertRedirect(route('verification.notice'));
}
}