mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 10:54:04 +00:00
Features are now *always* bootstrapped, even if Tenancy is not resolved from the container. Previous implementations include https://github.com/tenancy-for-laravel/v4/pull/19 https://github.com/archtechx/tenancy/pull/1021 Bug originally reported here https://github.com/archtechx/tenancy/issues/949 This implementation is much simpler, we do not distinguish between features that should be "always bootstrapped" and features that should only be bootstrapped after Tenancy is resolved. All features should work without issues if they're bootstrapped when TSP::boot() is called. We also add a Tenancy::bootstrapFeatures() method that can be used to bootstrap any features dynamically added at runtime that weren't bootstrapped in TSP::boot(). The function keeps track of which features were already bootstrapped so it doesn't bootstrap them again. The only potentialy risky thing in this implementation is that we're now resolving Tenancy in TSP::boot() (previously Tenancy was not being resolved) but that shouldn't be causing any issues.
39 lines
1.1 KiB
PHP
39 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Illuminate\Support\Facades\Route;
|
|
use Stancl\Tenancy\Features\CrossDomainRedirect;
|
|
use Stancl\Tenancy\Tests\Etc\Tenant;
|
|
use function Stancl\Tenancy\Tests\pest;
|
|
|
|
test('tenant redirect macro replaces only the hostname', function () {
|
|
config([
|
|
'tenancy.features' => [CrossDomainRedirect::class],
|
|
]);
|
|
|
|
tenancy()->bootstrapFeatures();
|
|
|
|
Route::get('/foobar', function () {
|
|
return 'Foo';
|
|
})->name('home');
|
|
|
|
Route::get('/redirect', function () {
|
|
return redirect()->route('home')->domain('abcd');
|
|
});
|
|
|
|
$tenant = Tenant::create();
|
|
tenancy()->initialize($tenant);
|
|
|
|
pest()->get('/redirect')
|
|
->assertRedirect('http://abcd/foobar');
|
|
});
|
|
|
|
test('tenant route helper generates correct url', function () {
|
|
Route::get('/abcdef/{a?}/{b?}', function () {
|
|
return 'Foo';
|
|
})->name('foo');
|
|
|
|
expect(tenant_route('foo.localhost', 'foo', ['a' => 'as', 'b' => 'df']))->toBe('http://foo.localhost/abcdef/as/df');
|
|
expect(tenant_route('foo.localhost', 'foo', []))->toBe('http://foo.localhost/abcdef');
|
|
});
|