From 0a3ba9018cc6a6b843c2756fc52a9e5c582d7ec3 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Mon, 2 Jun 2025 15:40:51 +0200 Subject: [PATCH] Add Fortify bootstrapper custom query param passing test --- .../Integrations/FortifyRouteBootstrapper.php | 1 - .../FortifyRouteBootstrapperTest.php | 36 ++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/Bootstrappers/Integrations/FortifyRouteBootstrapper.php b/src/Bootstrappers/Integrations/FortifyRouteBootstrapper.php index fb371d6a..12b49f78 100644 --- a/src/Bootstrappers/Integrations/FortifyRouteBootstrapper.php +++ b/src/Bootstrappers/Integrations/FortifyRouteBootstrapper.php @@ -86,7 +86,6 @@ class FortifyRouteBootstrapper implements TenancyBootstrapper protected function useTenantRoutesInFortify(Tenant $tenant): void { if (static::$passQueryParameter) { - // todo@tests $tenantParameterName = RequestDataTenantResolver::queryParameterName(); $tenantParameterValue = RequestDataTenantResolver::payloadValue($tenant); } else { diff --git a/tests/Bootstrappers/FortifyRouteBootstrapperTest.php b/tests/Bootstrappers/FortifyRouteBootstrapperTest.php index 63f0f2a0..1fc6c42e 100644 --- a/tests/Bootstrappers/FortifyRouteBootstrapperTest.php +++ b/tests/Bootstrappers/FortifyRouteBootstrapperTest.php @@ -1,6 +1,5 @@ toBe($originalFortifyHome); expect(config('fortify.redirects'))->toBe($originalFortifyRedirects); }); + +test('fortify route bootstrapper works with custom query parameter', function() { + config([ + 'tenancy.bootstrappers' => [FortifyRouteBootstrapper::class], + 'tenancy.identification.resolvers.' . RequestDataTenantResolver::class . '.query_parameter' => 'team', + ]); + + $originalFortifyHome = config('fortify.home'); + $originalFortifyRedirects = config('fortify.redirects'); + + Route::get('/dashboard', function () { + return true; + })->name($homeRouteName = 'tenant.dashboard'); + + Route::get('/login', function () { + return true; + })->name($loginRouteName = 'tenant.login'); + + FortifyRouteBootstrapper::$fortifyHome = $homeRouteName; + FortifyRouteBootstrapper::$fortifyRedirectMap['login'] = $loginRouteName; + FortifyRouteBootstrapper::$passQueryParameter = true; + + $tenant = Tenant::create(); + + tenancy()->initialize($tenant); + + expect(config('fortify.home'))->toBe('http://localhost/dashboard?team=' . $tenant->id); + expect(config('fortify.redirects'))->toEqual(['login' => 'http://localhost/login?team=' . $tenant->id]); + + tenancy()->end(); + + expect(config('fortify.home'))->toBe($originalFortifyHome); + expect(config('fortify.redirects'))->toBe($originalFortifyRedirects); +});