From f61675473adde0725601b7be18ad872867103ff5 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Wed, 31 Aug 2022 08:37:08 +0200 Subject: [PATCH] Add tests for the symlink actions --- tests/ActionTest.php | 68 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 tests/ActionTest.php diff --git a/tests/ActionTest.php b/tests/ActionTest.php new file mode 100644 index 00000000..a1bd6a5c --- /dev/null +++ b/tests/ActionTest.php @@ -0,0 +1,68 @@ + [ + FilesystemTenancyBootstrapper::class, + ], + 'tenancy.filesystem.suffix_base' => 'tenant-', + 'tenancy.filesystem.root_override.public' => '%storage_path%/app/public/', + 'tenancy.filesystem.url_override.public' => 'public-%tenant_id%' + ]); + + /** @var \Stancl\Tenancy\Database\Models\Tenant $tenant */ + $tenant = Tenant::create(); + $tenantKey = $tenant->getTenantKey(); + + tenancy()->initialize($tenant); + + Storage::disk('public')->put('test.txt', 'test'); + + $this->assertDirectoryDoesNotExist(public_path("public-$tenantKey")); + + CreateStorageSymlinksAction::handle($tenant); + + $this->assertDirectoryExists(storage_path("app/public")); + $this->assertDirectoryExists(public_path("public-$tenantKey")); + $this->assertEquals(storage_path("app/public/"), readlink(public_path("public-$tenantKey"))); +}); + +test('remove storage symlinks action works', function() { + config([ + 'tenancy.bootstrappers' => [ + FilesystemTenancyBootstrapper::class, + ], + 'tenancy.filesystem.suffix_base' => 'tenant-', + 'tenancy.filesystem.root_override.public' => '%storage_path%/app/public/', + 'tenancy.filesystem.url_override.public' => 'public-%tenant_id%' + ]); + + /** @var \Stancl\Tenancy\Database\Models\Tenant $tenant */ + $tenant = Tenant::create(); + $tenantKey = $tenant->getTenantKey(); + + tenancy()->initialize($tenant); + + CreateStorageSymlinksAction::handle($tenant); + + RemoveStorageSymlinksAction::handle($tenant); + + $this->assertDirectoryDoesNotExist(public_path("public-$tenantKey")); +});