diff --git a/src/helpers.php b/src/helpers.php index bc4ac1d1..91a491b7 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -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); } } diff --git a/tests/PathIdentificationTest.php b/tests/PathIdentificationTest.php index 0d0c8096..eadaa1e0 100644 --- a/tests/PathIdentificationTest.php +++ b/tests/PathIdentificationTest.php @@ -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'); });