mirror of
https://github.com/archtechx/tenancy.git
synced 2026-09-20 12:34:03 +00:00
Merge 'not a local disk'/'not tenant-aware'/'unnamed parent' throwing tests into a single test
This commit is contained in:
parent
1abeb852de
commit
fe85fe45bd
1 changed files with 16 additions and 38 deletions
|
|
@ -120,7 +120,7 @@ test('the disk used for serving tenant assets is configurable', function () {
|
||||||
expect($response->getFile()->getPathname())->toBe($path);
|
expect($response->getFile()->getPathname())->toBe($path);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('tenant asset controller throws when the configured disk is not local', function (string $publicDisk) {
|
test('tenant asset controller throws when the configured disk is not local or not tenant-aware', function () {
|
||||||
config([
|
config([
|
||||||
'tenancy.identification.default_middleware' => InitializeTenancyByRequestData::class,
|
'tenancy.identification.default_middleware' => InitializeTenancyByRequestData::class,
|
||||||
// Add a disk that uses the s3 driver (= non-local disk).
|
// Add a disk that uses the s3 driver (= non-local disk).
|
||||||
|
|
@ -137,27 +137,7 @@ test('tenant asset controller throws when the configured disk is not local', fun
|
||||||
'disk' => 'remote',
|
'disk' => 'remote',
|
||||||
'prefix' => 'assets',
|
'prefix' => 'assets',
|
||||||
],
|
],
|
||||||
]);
|
// 'media' isn't tenant-aware (i.e. not included in tenancy.filesystem.disks)
|
||||||
|
|
||||||
TenantAssetController::$publicDisk = $publicDisk;
|
|
||||||
|
|
||||||
$tenant = Tenant::create();
|
|
||||||
tenancy()->initialize($tenant);
|
|
||||||
|
|
||||||
$this->withoutExceptionHandling();
|
|
||||||
pest()->expectExceptionMessage("Disk [$publicDisk] is not a local disk.");
|
|
||||||
|
|
||||||
pest()->get(tenant_asset('foo.txt'), ['X-Tenant' => $tenant->id]);
|
|
||||||
})->with([
|
|
||||||
'disk' => 'remote',
|
|
||||||
'scoped disk' => 'scoped_remote',
|
|
||||||
]);
|
|
||||||
|
|
||||||
test('tenant asset controller throws when the disk used for serving assets is not tenant-aware', function (string $publicDisk, string $expectedMessage) {
|
|
||||||
$centralStoragePath = storage_path();
|
|
||||||
|
|
||||||
config([
|
|
||||||
'tenancy.identification.default_middleware' => InitializeTenancyByRequestData::class,
|
|
||||||
'filesystems.disks.media' => [
|
'filesystems.disks.media' => [
|
||||||
'driver' => 'local',
|
'driver' => 'local',
|
||||||
'root' => storage_path('app/media'),
|
'root' => storage_path('app/media'),
|
||||||
|
|
@ -177,30 +157,28 @@ test('tenant asset controller throws when the disk used for serving assets is no
|
||||||
],
|
],
|
||||||
'prefix' => 'assets',
|
'prefix' => 'assets',
|
||||||
],
|
],
|
||||||
// 'media' isn't tenant-aware (i.e. not included in tenancy.filesystem.disks)
|
|
||||||
'tenancy.filesystem.root_override.media' => '%storage_path%/app/media/',
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
TenantAssetController::$publicDisk = $publicDisk;
|
|
||||||
|
|
||||||
$tenant = Tenant::create();
|
$tenant = Tenant::create();
|
||||||
tenancy()->initialize($tenant);
|
tenancy()->initialize($tenant);
|
||||||
|
|
||||||
Storage::disk($publicDisk)->put($filename = 'testfile' . Str::random(8), 'bar');
|
|
||||||
|
|
||||||
// The disk's root stays central
|
|
||||||
expect(Storage::disk($publicDisk)->path($filename))->toStartWith("$centralStoragePath/app/media/");
|
|
||||||
|
|
||||||
$this->withoutExceptionHandling();
|
$this->withoutExceptionHandling();
|
||||||
|
|
||||||
pest()->expectExceptionMessage($expectedMessage);
|
$expectedExceptions = [
|
||||||
|
'remote' => 'Disk [remote] is not a local disk.',
|
||||||
|
'scoped_remote' => 'Disk [scoped_remote] is not a local disk.',
|
||||||
|
'media' => 'Disk [media] is not tenant-aware.',
|
||||||
|
'scoped_media' => 'Disk [media] is not tenant-aware.',
|
||||||
|
'inline_scoped_media' => 'Disk [inline_scoped_media] has an unnamed parent disk.',
|
||||||
|
];
|
||||||
|
|
||||||
pest()->get(tenant_asset($filename), ['X-Tenant' => $tenant->id]);
|
foreach ($expectedExceptions as $publicDisk => $exceptionMessage) {
|
||||||
})->with([
|
TenantAssetController::$publicDisk = $publicDisk;
|
||||||
'disk' => ['media', 'Disk [media] is not tenant-aware.'],
|
|
||||||
'scoped disk' => ['scoped_media', 'Disk [media] is not tenant-aware.'],
|
expect(fn () => pest()->get(tenant_asset('foo.txt'), ['X-Tenant' => $tenant->id]))
|
||||||
'scoped disk with an inline parent disk' => ['inline_scoped_media', 'Disk [inline_scoped_media] has an unnamed parent disk.'],
|
->toThrow(Exception::class, $exceptionMessage);
|
||||||
]);
|
}
|
||||||
|
});
|
||||||
|
|
||||||
test('tenant assets are served from the resolved root of a scoped disk', function () {
|
test('tenant assets are served from the resolved root of a scoped disk', function () {
|
||||||
config([
|
config([
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue