mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-04 23:14:05 +00:00
Add Fortify bootstrapper custom query param passing test
This commit is contained in:
parent
d218431b95
commit
0a3ba9018c
2 changed files with 35 additions and 2 deletions
|
|
@ -86,7 +86,6 @@ class FortifyRouteBootstrapper implements TenancyBootstrapper
|
||||||
protected function useTenantRoutesInFortify(Tenant $tenant): void
|
protected function useTenantRoutesInFortify(Tenant $tenant): void
|
||||||
{
|
{
|
||||||
if (static::$passQueryParameter) {
|
if (static::$passQueryParameter) {
|
||||||
// todo@tests
|
|
||||||
$tenantParameterName = RequestDataTenantResolver::queryParameterName();
|
$tenantParameterName = RequestDataTenantResolver::queryParameterName();
|
||||||
$tenantParameterValue = RequestDataTenantResolver::payloadValue($tenant);
|
$tenantParameterValue = RequestDataTenantResolver::payloadValue($tenant);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Stancl\Tenancy\Enums\Context;
|
|
||||||
use Stancl\Tenancy\Tests\Etc\Tenant;
|
use Stancl\Tenancy\Tests\Etc\Tenant;
|
||||||
use Illuminate\Support\Facades\Event;
|
use Illuminate\Support\Facades\Event;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
@ -9,6 +8,7 @@ use Stancl\Tenancy\Events\TenancyInitialized;
|
||||||
use Stancl\Tenancy\Listeners\BootstrapTenancy;
|
use Stancl\Tenancy\Listeners\BootstrapTenancy;
|
||||||
use Stancl\Tenancy\Listeners\RevertToCentralContext;
|
use Stancl\Tenancy\Listeners\RevertToCentralContext;
|
||||||
use Stancl\Tenancy\Bootstrappers\Integrations\FortifyRouteBootstrapper;
|
use Stancl\Tenancy\Bootstrappers\Integrations\FortifyRouteBootstrapper;
|
||||||
|
use Stancl\Tenancy\Resolvers\RequestDataTenantResolver;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
Event::listen(TenancyInitialized::class, BootstrapTenancy::class);
|
Event::listen(TenancyInitialized::class, BootstrapTenancy::class);
|
||||||
|
|
@ -61,3 +61,37 @@ test('fortify route tenancy bootstrapper updates fortify config correctly', func
|
||||||
expect(config('fortify.home'))->toBe($originalFortifyHome);
|
expect(config('fortify.home'))->toBe($originalFortifyHome);
|
||||||
expect(config('fortify.redirects'))->toBe($originalFortifyRedirects);
|
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);
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue