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

add tenant_path_route helper and tests

This commit is contained in:
Abrar Ahmad 2022-08-09 14:38:23 +05:00
parent 25f19c2c39
commit 6050f56c4c
2 changed files with 16 additions and 8 deletions

View file

@ -70,13 +70,12 @@ if (! function_exists('tenant_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)) {
$parameters[PathTenantResolver::$tenantParameterName] = optional(tenant())->getTenantKey();
}
dd($parameters);
return route($route, $parameters);
return route($route, $parameters, $absolute);
}
}

View file

@ -124,13 +124,22 @@ test('tenant parameter name can be customized', function () {
->get('/acme/foo/abc/xyz');
});
test('tenant path route helper function test', function () {
Tenant::create([
test('tenant path route helper adds the tenant parameter', function () {
$tenant = Tenant::create([
'id' => 'acme',
]);
pest()->get( tenant_path_route('foo', ['a' => 'a', 'b' => 'b']));
tenancy()->initialize($tenant);
expect(tenancy()->initialized)->toBeTrue();
expect(tenant('id'))->toBe('acme');
expect(tenant_path_route('foo', ['a' => 'bar', 'b' => 'boo']))->toBe('http://localhost/acme/foo/bar/boo');
});
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');
});