mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 10:54:04 +00:00
Cloning: remove route context middleware flags during cloning
Previously, if a universal route was cloned without a cloneRoutesWithMiddleware(['universal']) call, i.e. it had both 'clone' and 'universal' flags, with only the former triggering cloning, the 'universal' flag would be included in the middleware of the cloned route. Now, we make sure to remove all context flags -- central, tenant, universal -- in the first step of processing middleware, before adding just 'tenant'.
This commit is contained in:
parent
947894fa1d
commit
69bf768424
2 changed files with 24 additions and 3 deletions
|
|
@ -401,3 +401,24 @@ test('tenant parameter addition can be controlled by setting addTenantParameter'
|
|||
$this->withoutExceptionHandling()->get('http://central.localhost/foo')->assertSee('central');
|
||||
}
|
||||
})->with([true, false]);
|
||||
|
||||
test('existing context flags are removed during cloning', function () {
|
||||
RouteFacade::get('/foo', fn () => true)->name('foo')->middleware(['clone', 'central']);
|
||||
RouteFacade::get('/bar', fn () => true)->name('bar')->middleware(['clone', 'universal']);
|
||||
|
||||
$cloneAction = app(CloneRoutesAsTenant::class);
|
||||
|
||||
// Clone foo route
|
||||
$cloneAction->handle();
|
||||
expect(collect(RouteFacade::getRoutes()->get())->map->getName())
|
||||
->toContain('tenant.foo');
|
||||
expect(tenancy()->getRouteMiddleware(RouteFacade::getRoutes()->getByName('tenant.foo')))
|
||||
->not()->toContain('central');
|
||||
|
||||
// Clone bar route
|
||||
$cloneAction->handle();
|
||||
expect(collect(RouteFacade::getRoutes()->get())->map->getName())
|
||||
->toContain('tenant.foo', 'tenant.bar');
|
||||
expect(tenancy()->getRouteMiddleware(RouteFacade::getRoutes()->getByName('tenant.foo')))
|
||||
->not()->toContain('universal');
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue