mirror of
https://github.com/archtechx/tenancy.git
synced 2026-09-20 14:14:03 +00:00
minor test cleanup
This commit is contained in:
parent
d783879f98
commit
9673464128
2 changed files with 33 additions and 43 deletions
|
|
@ -277,7 +277,7 @@ test('the framework/cache directory is created when storage_path is scoped', fun
|
||||||
}
|
}
|
||||||
})->with([true, false]);
|
})->with([true, false]);
|
||||||
|
|
||||||
test('scoped disks are scoped per tenant', function (bool $nested) {
|
test('scoped disks are scoped per tenant', function () {
|
||||||
config([
|
config([
|
||||||
'tenancy.bootstrappers' => [
|
'tenancy.bootstrappers' => [
|
||||||
FilesystemTenancyBootstrapper::class,
|
FilesystemTenancyBootstrapper::class,
|
||||||
|
|
@ -294,8 +294,8 @@ test('scoped disks are scoped per tenant', function (bool $nested) {
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$disk = $nested ? 'nested_disk' : 'scoped_disk';
|
foreach (['scoped_disk' => '', 'nested_disk' => '/nested_disk_prefix'] as $disk => $nested_prefix) {
|
||||||
$path = 'app/public/scoped_disk_prefix/' . ($nested ? 'nested_disk_prefix/' : '') . 'foo.txt';
|
$path = "app/public/scoped_disk_prefix{$nested_prefix}/foo.txt";
|
||||||
|
|
||||||
$tenant = Tenant::create();
|
$tenant = Tenant::create();
|
||||||
$centralFile = storage_path($path);
|
$centralFile = storage_path($path);
|
||||||
|
|
@ -316,10 +316,8 @@ test('scoped disks are scoped per tenant', function (bool $nested) {
|
||||||
expect(Storage::disk($disk)->get('foo.txt'))->toBe('central');
|
expect(Storage::disk($disk)->get('foo.txt'))->toBe('central');
|
||||||
expect(file_get_contents($centralFile))->toBe('central');
|
expect(file_get_contents($centralFile))->toBe('central');
|
||||||
expect(file_get_contents($tenantFile))->toBe('tenant');
|
expect(file_get_contents($tenantFile))->toBe('tenant');
|
||||||
})->with([
|
}
|
||||||
'scoped disk' => false,
|
});
|
||||||
'nested scoped disk' => true,
|
|
||||||
]);
|
|
||||||
|
|
||||||
test('scoped disks based on a non-local disk are scoped per tenant', function () {
|
test('scoped disks based on a non-local disk are scoped per tenant', function () {
|
||||||
config([
|
config([
|
||||||
|
|
@ -363,25 +361,7 @@ test('adding a scoped disk to tenancy.filesystem.disks throws an exception if it
|
||||||
'disk' => 'foo',
|
'disk' => 'foo',
|
||||||
'prefix' => 'bar',
|
'prefix' => 'bar',
|
||||||
],
|
],
|
||||||
]);
|
// There's no way for a scoped disk with an array parent to have the parent listed in tenancy.filesystem.disks
|
||||||
|
|
||||||
$initializeTenancy = fn () => tenancy()->initialize(Tenant::create());
|
|
||||||
|
|
||||||
config(['tenancy.filesystem.disks' => ['foo']]);
|
|
||||||
expect($initializeTenancy)->toThrow(Exception::class, "Disk [foo] uses the 'scoped' driver, so it has no root to make tenant-aware.");
|
|
||||||
|
|
||||||
config(['tenancy.filesystem.disks' => ['bar']]);
|
|
||||||
expect($initializeTenancy)->toThrow(Exception::class, "Disk [bar] uses the 'scoped' driver, so it has no root to make tenant-aware.");
|
|
||||||
|
|
||||||
config(['tenancy.filesystem.disks' => ['public', 'foo', 'bar']]);
|
|
||||||
expect($initializeTenancy)->not()->toThrow(Throwable::class);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('adding a scoped disk with an inline base disk to tenancy.filesystem.disks throws an exception', function () {
|
|
||||||
config([
|
|
||||||
'tenancy.bootstrappers' => [
|
|
||||||
FilesystemTenancyBootstrapper::class,
|
|
||||||
],
|
|
||||||
'filesystems.disks.inline_base' => [
|
'filesystems.disks.inline_base' => [
|
||||||
'driver' => 'scoped',
|
'driver' => 'scoped',
|
||||||
'disk' => [
|
'disk' => [
|
||||||
|
|
@ -394,10 +374,19 @@ test('adding a scoped disk with an inline base disk to tenancy.filesystem.disks
|
||||||
|
|
||||||
$initializeTenancy = fn () => tenancy()->initialize(Tenant::create());
|
$initializeTenancy = fn () => tenancy()->initialize(Tenant::create());
|
||||||
|
|
||||||
// The base disk is inline, so it has no name.
|
config(['tenancy.filesystem.disks' => ['foo']]);
|
||||||
// There's no way to make the scoped disk tenant-aware.
|
expect($initializeTenancy)->toThrow(Exception::class, "Disk [foo] uses the 'scoped' driver, so it has no root to make tenant-aware.");
|
||||||
|
|
||||||
|
config(['tenancy.filesystem.disks' => ['bar']]);
|
||||||
|
expect($initializeTenancy)->toThrow(Exception::class, "Disk [bar] uses the 'scoped' driver, so it has no root to make tenant-aware.");
|
||||||
|
|
||||||
config(['tenancy.filesystem.disks' => ['inline_base']]);
|
config(['tenancy.filesystem.disks' => ['inline_base']]);
|
||||||
expect($initializeTenancy)->toThrow(Exception::class, "Disk [inline_base] uses the 'scoped' driver, so it has no root to make tenant-aware.");
|
expect($initializeTenancy)->toThrow(Exception::class, "Disk [inline_base] uses the 'scoped' driver, so it has no root to make tenant-aware.");
|
||||||
|
|
||||||
|
config(['tenancy.filesystem.disks' => ['public', 'foo', 'bar']]);
|
||||||
|
expect($initializeTenancy)->not()->toThrow(Throwable::class);
|
||||||
|
|
||||||
|
// No way to make the 'inline_base' disk work
|
||||||
});
|
});
|
||||||
|
|
||||||
test('file cache stores get their paths scoped on bootstrap and restored back on revert', function () {
|
test('file cache stores get their paths scoped on bootstrap and restored back on revert', function () {
|
||||||
|
|
|
||||||
|
|
@ -398,9 +398,10 @@ test('tenant asset controller only serves files inside the asset root', function
|
||||||
|
|
||||||
pest()->get(tenant_asset('photo.jpg'), ['X-Tenant' => $tenant->id])->assertSuccessful();
|
pest()->get(tenant_asset('photo.jpg'), ['X-Tenant' => $tenant->id])->assertSuccessful();
|
||||||
|
|
||||||
// Files outside the asset root, e.g. ones that shouldn't be served.
|
// Files outside the asset root
|
||||||
// The directory with the second file starts with the name of the asset root.
|
|
||||||
file_put_contents(storage_path('app/photo.jpg'), 'private file');
|
file_put_contents(storage_path('app/photo.jpg'), 'private file');
|
||||||
|
|
||||||
|
// This path starts with the asset root but is a sibling dir, not a child. Regression assertion
|
||||||
mkdir($siblingDirectory = storage_path('app/public-originals'), recursive: true);
|
mkdir($siblingDirectory = storage_path('app/public-originals'), recursive: true);
|
||||||
file_put_contents($siblingDirectory . '/photo.jpg', 'private file');
|
file_put_contents($siblingDirectory . '/photo.jpg', 'private file');
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue