diff --git a/tests/TenantAssetTest.php b/tests/TenantAssetTest.php index 3bd501de..bedc4d00 100644 --- a/tests/TenantAssetTest.php +++ b/tests/TenantAssetTest.php @@ -31,6 +31,7 @@ beforeEach(function () { TenancyUrlGenerator::$passTenantParameterToRoutes = true; TenantAssetController::$headers = []; TenantAssetController::$publicDisk = null; + InitializeTenancyByRequestData::$onFail = null; /** @var CloneRoutesAsTenant $cloneAction */ $cloneAction = app(CloneRoutesAsTenant::class); @@ -130,6 +131,21 @@ test('tenant asset controller throws when the configured disk has no root', func pest()->get(tenant_asset('foo.txt'), ['X-Tenant' => $tenant->id]); }); +test('tenant assets are served from the central storage path in central context', function () { + config(['tenancy.identification.default_middleware' => InitializeTenancyByRequestData::class]); + + // Mimic the universal route setup (let the request through even though no tenant is identified) + InitializeTenancyByRequestData::$onFail = fn ($e, $request, $next) => $next($request); + + $filename = 'testfile' . Str::random(8); + Storage::disk('public')->put($filename, 'bar'); + + $response = pest()->get(tenant_asset($filename)); + + $response->assertSuccessful(); + expect($response->getFile()->getPathname())->toBe(storage_path("app/public/$filename")); +}); + test('asset helper returns a link to tenant asset controller when asset url is null', function () { config(['app.asset_url' => null]); config(['tenancy.filesystem.asset_helper_override' => true]);