mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-04 19:34:04 +00:00
Merge master, add more assertions, use array_merge() syntax
This commit is contained in:
commit
12b3b50230
45 changed files with 856 additions and 201 deletions
|
|
@ -201,6 +201,27 @@ test('tenant storage can get deleted after the tenant when DeletingTenant listen
|
|||
expect(File::isDirectory($tenantStoragePath))->toBeFalse();
|
||||
});
|
||||
|
||||
test('the framework/cache directory is created when storage_path is scoped', function (bool $suffixStoragePath) {
|
||||
config([
|
||||
'tenancy.bootstrappers' => [
|
||||
FilesystemTenancyBootstrapper::class,
|
||||
],
|
||||
'tenancy.filesystem.suffix_storage_path' => $suffixStoragePath
|
||||
]);
|
||||
|
||||
$centralStoragePath = storage_path();
|
||||
|
||||
tenancy()->initialize($tenant = Tenant::create());
|
||||
|
||||
if ($suffixStoragePath) {
|
||||
expect(storage_path('framework/cache'))->toBe($centralStoragePath . "/tenant{$tenant->id}/framework/cache");
|
||||
expect(is_dir($centralStoragePath . "/tenant{$tenant->id}/framework/cache"))->toBeTrue();
|
||||
} else {
|
||||
expect(storage_path('framework/cache'))->toBe($centralStoragePath . '/framework/cache');
|
||||
expect(is_dir($centralStoragePath . "/tenant{$tenant->id}/framework/cache"))->toBeFalse();
|
||||
}
|
||||
})->with([true, false]);
|
||||
|
||||
test('scoped disks are scoped per tenant', function () {
|
||||
config([
|
||||
'tenancy.bootstrappers' => [
|
||||
|
|
@ -215,16 +236,24 @@ test('scoped disks are scoped per tenant', function () {
|
|||
|
||||
$tenant = Tenant::create();
|
||||
|
||||
$storagePath = storage_path() . "/tenant{$tenant->id}";
|
||||
|
||||
// Resolve scoped_disk before initializing tenancy
|
||||
Storage::disk('scoped_disk');
|
||||
Storage::disk('scoped_disk')->put('foo.txt', 'central');
|
||||
expect(Storage::disk('scoped_disk')->get('foo.txt'))->toBe('central');
|
||||
expect(file_get_contents(storage_path() . "/app/public/scoped_disk_prefix/foo.txt"))->toBe('central');
|
||||
|
||||
tenancy()->initialize($tenant);
|
||||
|
||||
Storage::disk('scoped_disk')->put('foo.txt', 'foo text');
|
||||
expect(Storage::disk('scoped_disk')->get('foo.txt'))->toBe(null);
|
||||
Storage::disk('scoped_disk')->put('foo.txt', 'tenant');
|
||||
expect(file_get_contents(storage_path() . "/app/public/scoped_disk_prefix/foo.txt"))->toBe('tenant');
|
||||
expect(Storage::disk('scoped_disk')->get('foo.txt'))->toBe('tenant');
|
||||
|
||||
tenancy()->end();
|
||||
|
||||
expect(File::exists($storagePath . '/app/public/scoped_disk_prefix/foo.txt'))->toBeTrue();
|
||||
expect(Storage::disk('scoped_disk')->get('foo.txt'))->toBe('central');
|
||||
Storage::disk('scoped_disk')->put('foo.txt', 'central2');
|
||||
expect(Storage::disk('scoped_disk')->get('foo.txt'))->toBe('central2');
|
||||
|
||||
expect(file_get_contents(storage_path() . "/app/public/scoped_disk_prefix/foo.txt"))->toBe('central2');
|
||||
expect(file_get_contents(storage_path() . "/tenant{$tenant->id}/app/public/scoped_disk_prefix/foo.txt"))->toBe('tenant');
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ use Stancl\Tenancy\Bootstrappers\UrlGeneratorBootstrapper;
|
|||
use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedByRequestDataException;
|
||||
use Stancl\Tenancy\Middleware\InitializeTenancyByRequestData;
|
||||
use Stancl\Tenancy\Resolvers\RequestDataTenantResolver;
|
||||
|
||||
use function Stancl\Tenancy\Tests\pest;
|
||||
|
||||
beforeEach(function () {
|
||||
|
|
@ -80,6 +79,44 @@ test('tenancy url generator can prefix route names passed to the route helper',
|
|||
expect(route('home'))->toBe('http://localhost/central/home');
|
||||
});
|
||||
|
||||
test('tenancy url generator inherits scheme from original url generator', function() {
|
||||
config(['tenancy.bootstrappers' => [UrlGeneratorBootstrapper::class]]);
|
||||
|
||||
Route::get('/home', fn () => '')->name('home');
|
||||
|
||||
// No scheme forced, default is HTTP
|
||||
expect(app('url')->formatScheme())->toBe('http://');
|
||||
|
||||
$tenant = Tenant::create();
|
||||
|
||||
// Force the original URL generator to use HTTPS
|
||||
app('url')->forceScheme('https');
|
||||
|
||||
// Original generator uses HTTPS
|
||||
expect(app('url')->formatScheme())->toBe('https://');
|
||||
|
||||
// Check that TenancyUrlGenerator inherits the HTTPS scheme
|
||||
tenancy()->initialize($tenant);
|
||||
expect(app('url')->formatScheme())->toBe('https://'); // Should inherit HTTPS
|
||||
expect(route('home'))->toBe('https://localhost/home');
|
||||
|
||||
tenancy()->end();
|
||||
|
||||
// After ending tenancy, the original generator should still have the original scheme (HTTPS)
|
||||
expect(route('home'))->toBe('https://localhost/home');
|
||||
|
||||
// Use HTTP scheme
|
||||
app('url')->forceScheme('http');
|
||||
expect(app('url')->formatScheme())->toBe('http://');
|
||||
|
||||
tenancy()->initialize($tenant);
|
||||
expect(app('url')->formatScheme())->toBe('http://'); // Should inherit scheme (HTTP)
|
||||
expect(route('home'))->toBe('http://localhost/home');
|
||||
|
||||
tenancy()->end();
|
||||
expect(route('home'))->toBe('http://localhost/home');
|
||||
});
|
||||
|
||||
test('path identification route helper behavior', function (bool $addTenantParameterToDefaults, bool $passTenantParameterToRoutes) {
|
||||
config(['tenancy.bootstrappers' => [UrlGeneratorBootstrapper::class]]);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue