mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-06 00:34:05 +00:00
add tenant_path_route helper and tests
This commit is contained in:
parent
25f19c2c39
commit
6050f56c4c
2 changed files with 16 additions and 8 deletions
|
|
@ -70,13 +70,12 @@ if (! function_exists('tenant_route')) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! function_exists('tenant_path_route')) {
|
if (! function_exists('tenant_path_route')) {
|
||||||
function tenant_path_route($route, $parameters = [])
|
function tenant_path_route(string $route, array $parameters = [], bool $absolute = true): string
|
||||||
{
|
{
|
||||||
if (! array_key_exists(PathTenantResolver::$tenantParameterName, $parameters)) {
|
if (! array_key_exists(PathTenantResolver::$tenantParameterName, $parameters)) {
|
||||||
$parameters[PathTenantResolver::$tenantParameterName] = optional(tenant())->getTenantKey();
|
$parameters[PathTenantResolver::$tenantParameterName] = optional(tenant())->getTenantKey();
|
||||||
}
|
}
|
||||||
dd($parameters);
|
|
||||||
|
|
||||||
return route($route, $parameters);
|
return route($route, $parameters, $absolute);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -124,13 +124,22 @@ test('tenant parameter name can be customized', function () {
|
||||||
->get('/acme/foo/abc/xyz');
|
->get('/acme/foo/abc/xyz');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('tenant path route helper function test', function () {
|
test('tenant path route helper adds the tenant parameter', function () {
|
||||||
Tenant::create([
|
$tenant = Tenant::create([
|
||||||
'id' => 'acme',
|
'id' => 'acme',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
pest()->get( tenant_path_route('foo', ['a' => 'a', 'b' => 'b']));
|
tenancy()->initialize($tenant);
|
||||||
|
|
||||||
expect(tenancy()->initialized)->toBeTrue();
|
expect(tenant_path_route('foo', ['a' => 'bar', 'b' => 'boo']))->toBe('http://localhost/acme/foo/bar/boo');
|
||||||
expect(tenant('id'))->toBe('acme');
|
});
|
||||||
|
|
||||||
|
test('tenant path route helper does not override the parameter if passed by developer', function () {
|
||||||
|
$tenant = Tenant::create([
|
||||||
|
'id' => 'acme',
|
||||||
|
]);
|
||||||
|
|
||||||
|
tenancy()->initialize($tenant);
|
||||||
|
|
||||||
|
expect(tenant_path_route('foo', ['tenant' => $tenant->getTenantKey(), 'a' => 'bar', 'b' => 'boo']))->toBe('http://localhost/acme/foo/bar/boo');
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue