mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 05:14:05 +00:00
* UrlGenerator: set defaults based on config; request data: move config to config file+resolver * Claude code adjustments * improve request data tests, simplify complex test in UrlGeneratorBootstrapperTest * url generator test: test changing tenant parameter name * request data identification: add tenant_model_column configuration * defaultParameterNames -> passQueryParameter * move comment * minor refactor in PathIdentificationTest, expand CLAUDE.md to include early identification section * Fix COLOR_FLAG * improve test name Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * TenancyUrlGenerator: add a check for queryParameterName being null Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix code style (php-cs-fixer) --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
63 lines
2.5 KiB
PHP
63 lines
2.5 KiB
PHP
<?php
|
|
|
|
use Stancl\Tenancy\Enums\Context;
|
|
use Stancl\Tenancy\Tests\Etc\Tenant;
|
|
use Illuminate\Support\Facades\Event;
|
|
use Illuminate\Support\Facades\Route;
|
|
use Stancl\Tenancy\Events\TenancyEnded;
|
|
use Stancl\Tenancy\Events\TenancyInitialized;
|
|
use Stancl\Tenancy\Listeners\BootstrapTenancy;
|
|
use Stancl\Tenancy\Listeners\RevertToCentralContext;
|
|
use Stancl\Tenancy\Bootstrappers\Integrations\FortifyRouteBootstrapper;
|
|
|
|
beforeEach(function () {
|
|
Event::listen(TenancyInitialized::class, BootstrapTenancy::class);
|
|
Event::listen(TenancyEnded::class, RevertToCentralContext::class);
|
|
FortifyRouteBootstrapper::$passTenantParameter = true;
|
|
});
|
|
|
|
afterEach(function () {
|
|
FortifyRouteBootstrapper::$passTenantParameter = true;
|
|
FortifyRouteBootstrapper::$fortifyRedirectMap = [];
|
|
FortifyRouteBootstrapper::$fortifyHome = 'tenant.dashboard';
|
|
FortifyRouteBootstrapper::$passQueryParameter = false;
|
|
});
|
|
|
|
test('fortify route tenancy bootstrapper updates fortify config correctly', function() {
|
|
config(['tenancy.bootstrappers' => [FortifyRouteBootstrapper::class]]);
|
|
|
|
$originalFortifyHome = config('fortify.home');
|
|
$originalFortifyRedirects = config('fortify.redirects');
|
|
|
|
Route::get('/home', function () {
|
|
return true;
|
|
})->name($homeRouteName = 'home');
|
|
|
|
Route::get('/welcome', function () {
|
|
return true;
|
|
})->name($welcomeRouteName = 'welcome');
|
|
|
|
FortifyRouteBootstrapper::$fortifyHome = $homeRouteName;
|
|
FortifyRouteBootstrapper::$fortifyRedirectMap['login'] = $welcomeRouteName;
|
|
|
|
expect(config('fortify.home'))->toBe($originalFortifyHome);
|
|
expect(config('fortify.redirects'))->toBe($originalFortifyRedirects);
|
|
|
|
FortifyRouteBootstrapper::$passTenantParameter = true;
|
|
tenancy()->initialize($tenant = Tenant::create());
|
|
expect(config('fortify.home'))->toBe('http://localhost/home?tenant=' . $tenant->getTenantKey());
|
|
expect(config('fortify.redirects'))->toEqual(['login' => 'http://localhost/welcome?tenant=' . $tenant->getTenantKey()]);
|
|
|
|
tenancy()->end();
|
|
expect(config('fortify.home'))->toBe($originalFortifyHome);
|
|
expect(config('fortify.redirects'))->toBe($originalFortifyRedirects);
|
|
|
|
FortifyRouteBootstrapper::$passTenantParameter = false;
|
|
tenancy()->initialize($tenant);
|
|
expect(config('fortify.home'))->toBe('http://localhost/home');
|
|
expect(config('fortify.redirects'))->toEqual(['login' => 'http://localhost/welcome']);
|
|
|
|
tenancy()->end();
|
|
expect(config('fortify.home'))->toBe($originalFortifyHome);
|
|
expect(config('fortify.redirects'))->toBe($originalFortifyRedirects);
|
|
});
|