1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-14 14:54:04 +00:00

Test fetching files using the public URL

This commit is contained in:
lukinovec 2022-08-10 16:03:00 +02:00
parent 006a6800cc
commit fa783641f4

View file

@ -2,7 +2,10 @@
declare(strict_types=1); declare(strict_types=1);
use Illuminate\Filesystem\FilesystemAdapter; namespace Stancl\Tenancy\Tests;
use ReflectionObject;
use ReflectionProperty;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Stancl\JobPipeline\JobPipeline; use Stancl\JobPipeline\JobPipeline;
@ -12,10 +15,11 @@ use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Redis; use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Stancl\Tenancy\Events\TenancyEnded; use Stancl\Tenancy\Events\TenancyEnded;
use Stancl\Tenancy\Events\TenancyInitialized; use Stancl\Tenancy\Jobs\CreateDatabase;
use Stancl\Tenancy\Events\TenantCreated; use Stancl\Tenancy\Events\TenantCreated;
use Stancl\Tenancy\Events\TenantDeleted; use Stancl\Tenancy\Events\TenantDeleted;
use Stancl\Tenancy\Jobs\CreateDatabase; use Illuminate\Filesystem\FilesystemAdapter;
use Stancl\Tenancy\Events\TenancyInitialized;
use Stancl\Tenancy\Jobs\CreateStorageSymlinks; use Stancl\Tenancy\Jobs\CreateStorageSymlinks;
use Stancl\Tenancy\Jobs\RemoveStorageSymlinks; use Stancl\Tenancy\Jobs\RemoveStorageSymlinks;
use Stancl\Tenancy\Listeners\BootstrapTenancy; use Stancl\Tenancy\Listeners\BootstrapTenancy;
@ -187,7 +191,7 @@ test('filesystem data is separated', function () {
expect($new_storage_path)->toEqual($expected_storage_path); expect($new_storage_path)->toEqual($expected_storage_path);
}); });
test('filesystem local storage has own public url', function() { test('filesystem local storage has own public url and files can get fetched using the url', function() {
config([ config([
'tenancy.bootstrappers' => [ 'tenancy.bootstrappers' => [
FilesystemTenancyBootstrapper::class, FilesystemTenancyBootstrapper::class,
@ -198,18 +202,33 @@ test('filesystem local storage has own public url', function() {
$tenant1 = Tenant::create(); $tenant1 = Tenant::create();
$tenant2 = Tenant::create(); $tenant2 = Tenant::create();
$tenant1StorageUrl = 'http://localhost/public-'.$tenant1->getKey().'/';
$tenant2StorageUrl = 'http://localhost/public-'.$tenant2->getKey().'/';
$tenant1FileName = 'tenant1.txt';
$tenant2FileName = 'tenant2.txt';
tenancy()->initialize($tenant1); tenancy()->initialize($tenant1);
Storage::disk('public')->put($tenant1FileName, tenant()->getKey());
$this->assertEquals( $this->assertEquals(
'http://localhost/public-'.$tenant1->getTenantKey().'/', $tenant1StorageUrl,
Storage::disk('public')->url('') Storage::disk('public')->url('')
); );
tenancy()->initialize($tenant2); tenancy()->initialize($tenant2);
Storage::disk('public')->put($tenant2FileName, tenant()->getKey());
$this->assertEquals( $this->assertEquals(
'http://localhost/public-'.$tenant2->getTenantKey().'/', $tenant2StorageUrl,
Storage::disk('public')->url('') Storage::disk('public')->url('')
); );
$this->assertEquals(
$tenant2StorageUrl . $tenant2FileName,
Storage::disk('public')->url($tenant2FileName)
);
$this->get(Storage::disk('public')->url($tenant2FileName))->assertSee($tenant2->getTenantKey());
}); });
test('create and delete storage symlinks jobs works', function() { test('create and delete storage symlinks jobs works', function() {