mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 17:44:04 +00:00
* Run cache tests on all supported drivers * update ci healthcheck for memcached * remove memcached healthcheck * fix typos in test comments, expand internal.md [ci skip] * add empty line [ci skip] * switch to using $store->setPrefix() * add dynamodb * refactor try-finally to try-catch * remove unnecessary clearResolvedInstances() call * add dual Cache:: and cache() assertions * add apc * Flush APCu cache in test setup * Revert "add dual Cache:: and cache() assertions" This reverts commit a0bab162fbe2dd0d25e7056ceca4fb7ce54efc77. * phpstan fix * Add logic for scoping 'file' disks to FilesystemTenancyBootstrapper * minor changes, add todos * refactor how the session.connection is used in the DB session bootstrapper * add session forgery prevention logic to the db session bootstrapper * only use the fs bootstrapper for file disk in 'cache data is separated' dataset * minor session scoping test changes * Add session scoping logic to FilesystemTenancyBootstrapper, correctly update disk roots even with storage_path_tenancy disabled * Fix code style (php-cs-fixer) * update docblock * make not-null check more explicit * separate bootstrapper tests, fix swapped test names for two tests * refactor cache bootstrapper tests * resolve global cache todo * expand tests: session separation tests, more filesystem separation assertions; change prefix_base-type config keys to templates/formats * add apc session scoping test, various session separation bugfixes * phpstan + minor logic fixes * prefix_format -> prefix * fix database session separation test * revert composer.json changes, update laravel dependencies to expected next release * only run session scoping logic in cache bootstrapper for redis, memcached, dynamodb, apc; update gitattributes * tenancy.central_domains -> tenancy.identification.central_domains * db session separation test: add datasets --------- Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
76 lines
3.1 KiB
PHP
76 lines
3.1 KiB
PHP
<?php
|
|
|
|
use Illuminate\Support\Facades\Event;
|
|
use Illuminate\Support\Facades\Route;
|
|
use Stancl\Tenancy\Bootstrappers\Integrations\FortifyRouteBootstrapper;
|
|
use Stancl\Tenancy\Enums\Context;
|
|
use Stancl\Tenancy\Events\TenancyEnded;
|
|
use Stancl\Tenancy\Events\TenancyInitialized;
|
|
use Stancl\Tenancy\Listeners\BootstrapTenancy;
|
|
use Stancl\Tenancy\Listeners\RevertToCentralContext;
|
|
|
|
beforeEach(function () {
|
|
Event::listen(TenancyInitialized::class, BootstrapTenancy::class);
|
|
Event::listen(TenancyEnded::class, RevertToCentralContext::class);
|
|
});
|
|
|
|
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('/{tenant}/home', function () {
|
|
return true;
|
|
})->name($pathIdHomeRouteName = 'tenant.home');
|
|
|
|
Route::get('/welcome', function () {
|
|
return true;
|
|
})->name($welcomeRouteName = 'welcome');
|
|
|
|
Route::get('/{tenant}/welcome', function () {
|
|
return true;
|
|
})->name($pathIdWelcomeRouteName = 'path.welcome');
|
|
|
|
FortifyRouteBootstrapper::$fortifyHome = $homeRouteName;
|
|
|
|
// Make login redirect to the central welcome route
|
|
FortifyRouteBootstrapper::$fortifyRedirectMap['login'] = [
|
|
'route_name' => $welcomeRouteName,
|
|
'context' => Context::CENTRAL,
|
|
];
|
|
|
|
tenancy()->initialize($tenant = Tenant::create());
|
|
// The bootstraper makes fortify.home always receive the tenant parameter
|
|
expect(config('fortify.home'))->toBe('http://localhost/home?tenant=' . $tenant->getTenantKey());
|
|
|
|
// The login redirect route has the central context specified, so it doesn't receive the tenant parameter
|
|
expect(config('fortify.redirects'))->toEqual(['login' => 'http://localhost/welcome']);
|
|
|
|
tenancy()->end();
|
|
expect(config('fortify.home'))->toBe($originalFortifyHome);
|
|
expect(config('fortify.redirects'))->toBe($originalFortifyRedirects);
|
|
|
|
// Making a route's context will pass the tenant parameter to the route
|
|
FortifyRouteBootstrapper::$fortifyRedirectMap['login']['context'] = Context::TENANT;
|
|
|
|
tenancy()->initialize($tenant);
|
|
|
|
expect(config('fortify.redirects'))->toEqual(['login' => 'http://localhost/welcome?tenant=' . $tenant->getTenantKey()]);
|
|
|
|
// Make the home and login route accept the tenant as a route parameter
|
|
// To confirm that tenant route parameter gets filled automatically too (path identification works as well as query string)
|
|
FortifyRouteBootstrapper::$fortifyHome = $pathIdHomeRouteName;
|
|
FortifyRouteBootstrapper::$fortifyRedirectMap['login']['route_name'] = $pathIdWelcomeRouteName;
|
|
|
|
tenancy()->end();
|
|
|
|
tenancy()->initialize($tenant);
|
|
|
|
expect(config('fortify.home'))->toBe("http://localhost/{$tenant->getTenantKey()}/home");
|
|
expect(config('fortify.redirects'))->toEqual(['login' => "http://localhost/{$tenant->getTenantKey()}/welcome"]);
|
|
});
|