1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 08:24:05 +00:00

Add test for handling 'clone' in MW groups

This commit is contained in:
lukinovec 2025-06-03 11:37:55 +02:00
parent 875d6409cb
commit 4c32599c57

View file

@ -214,3 +214,28 @@ test('clone action trims trailing slashes from prefixes given to nested route gr
->not()->toContain("prefix//") ->not()->toContain("prefix//")
->toBe("http://localhost/prefix/{$tenant->getTenantKey()}/home"); ->toBe("http://localhost/prefix/{$tenant->getTenantKey()}/home");
}); });
test('clone middleware within middleware groups is properly handled during cloning', function () {
// Define a middleware group that contains the 'clone' flag along with the 'auth' MW
RouteFacade::middlewareGroup('mw-group-with-clone', ['auth', 'clone']);
RouteFacade::get('/foo', fn () => true)
->middleware('mw-group-with-clone')
->name('foo');
app(CloneRoutesAsTenant::class)->handle();
// Route 'foo' should be cloned as 'tenant.foo'
$clonedRoute = RouteFacade::getRoutes()->getByName('tenant.foo');
expect($clonedRoute)->not()->toBeNull();
$clonedRouteMiddleware = tenancy()->getRouteMiddleware($clonedRoute);
// The cloned route should still have other middleware from the group,
// but it should NOT have the original middleware group name.
// Instead, the middleware should be extracted from the group and applied directly.
expect($clonedRouteMiddleware)
->toContain('auth')
->not()->toContain('test-group', 'clone');
});