mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-08 00:02:15 +01:00
Add option to enable email verification locally for testing
This commit is contained in:
committed by
Constantin Graf
parent
111ce94150
commit
24c94af952
@@ -17,7 +17,7 @@ class EnsureEmailIsVerified
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, ?string $redirectToRoute = null): Response
|
||||
{
|
||||
if (! app()->isLocal()) {
|
||||
if (! app()->isLocal() || config('app.local_email_verification')) {
|
||||
if ($request->user() === null ||
|
||||
(! $request->user()->hasVerifiedEmail())) {
|
||||
return $request->expectsJson()
|
||||
|
||||
@@ -81,6 +81,8 @@ return [
|
||||
|
||||
'enable_registration' => (bool) env('APP_ENABLE_REGISTRATION', false),
|
||||
|
||||
'local_email_verification' => (bool) env('APP_LOCAL_EMAIL_VERIFICATION', false),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Timezone
|
||||
|
||||
@@ -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'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user