mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 17:24:03 +00:00
Fix forced root
This commit is contained in:
parent
a34bcfbe3e
commit
b9054864aa
3 changed files with 35 additions and 5 deletions
|
|
@ -9,7 +9,6 @@ use Illuminate\Support\Facades\Storage;
|
||||||
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
||||||
use Stancl\Tenancy\Tenant;
|
use Stancl\Tenancy\Tenant;
|
||||||
|
|
||||||
// todo test the helpers
|
|
||||||
class FilesystemTenancyBootstrapper implements TenancyBootstrapper
|
class FilesystemTenancyBootstrapper implements TenancyBootstrapper
|
||||||
{
|
{
|
||||||
protected $originalPaths = [];
|
protected $originalPaths = [];
|
||||||
|
|
@ -24,7 +23,6 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
|
||||||
'disks' => [],
|
'disks' => [],
|
||||||
'path' => $this->app->storagePath(),
|
'path' => $this->app->storagePath(),
|
||||||
'asset_url' => $this->app['config']['app.asset_url'],
|
'asset_url' => $this->app['config']['app.asset_url'],
|
||||||
'forced_root' => $this->app['url']->getForcedRoot(),
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,7 +38,7 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
|
||||||
$this->app['config']['app.asset_url'] = ($this->originalPaths['asset_url'] ?? $this->app['config']['app.url']) . "/$suffix";
|
$this->app['config']['app.asset_url'] = ($this->originalPaths['asset_url'] ?? $this->app['config']['app.url']) . "/$suffix";
|
||||||
$this->app['url']->setAssetRoot($this->app['config']['app.asset_url']);
|
$this->app['url']->setAssetRoot($this->app['config']['app.asset_url']);
|
||||||
} else {
|
} else {
|
||||||
$this->app['url']->forceRootUrl($this->app['url']->route('stancl.tenancy.asset', ['path' => '']));
|
$this->app['url']->setAssetRoot($this->app['url']->route('stancl.tenancy.asset', ['path' => '']));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Storage facade
|
// Storage facade
|
||||||
|
|
@ -65,7 +63,6 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
|
||||||
// asset()
|
// asset()
|
||||||
$this->app['config']['app.asset_url'] = $this->originalPaths['asset_url'];
|
$this->app['config']['app.asset_url'] = $this->originalPaths['asset_url'];
|
||||||
$this->app['url']->setAssetRoot($this->app['config']['app.asset_url']);
|
$this->app['url']->setAssetRoot($this->app['config']['app.asset_url']);
|
||||||
$this->app['url']->forceRootUrl($this->originalPaths['forced_root']);
|
|
||||||
|
|
||||||
// Storage facade
|
// Storage facade
|
||||||
foreach ($this->app['config']['tenancy.filesystem.disks'] as $disk) {
|
foreach ($this->app['config']['tenancy.filesystem.disks'] as $disk) {
|
||||||
|
|
|
||||||
|
|
@ -132,10 +132,11 @@ class CommandsTest extends TestCase
|
||||||
file_put_contents(app_path('Http/Kernel.php'), file_get_contents(__DIR__ . '/Etc/defaultHttpKernel.stub'));
|
file_put_contents(app_path('Http/Kernel.php'), file_get_contents(__DIR__ . '/Etc/defaultHttpKernel.stub'));
|
||||||
|
|
||||||
$this->artisan('tenancy:install')
|
$this->artisan('tenancy:install')
|
||||||
->expectsQuestion('Do you want to publish the default database migration?', 'yes');
|
->expectsQuestion('Do you want to publish the default database migrations?', 'yes');
|
||||||
$this->assertFileExists(base_path('routes/tenant.php'));
|
$this->assertFileExists(base_path('routes/tenant.php'));
|
||||||
$this->assertFileExists(base_path('config/tenancy.php'));
|
$this->assertFileExists(base_path('config/tenancy.php'));
|
||||||
$this->assertFileExists(database_path('migrations/2019_08_08_000000_create_tenants_table.php'));
|
$this->assertFileExists(database_path('migrations/2019_08_08_000000_create_tenants_table.php'));
|
||||||
|
$this->assertFileExists(database_path('migrations/2019_09_15_000000_create_domains_table.php'));
|
||||||
$this->assertDirectoryExists(database_path('migrations/tenant'));
|
$this->assertDirectoryExists(database_path('migrations/tenant'));
|
||||||
$this->assertSame(file_get_contents(__DIR__ . '/Etc/modifiedHttpKernel.stub'), file_get_contents(app_path('Http/Kernel.php')));
|
$this->assertSame(file_get_contents(__DIR__ . '/Etc/modifiedHttpKernel.stub'), file_get_contents(app_path('Http/Kernel.php')));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,19 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Stancl\Tenancy\Tests;
|
namespace Stancl\Tenancy\Tests;
|
||||||
|
|
||||||
|
use Stancl\Tenancy\Tenant;
|
||||||
|
|
||||||
class TenantAssetTest extends TestCase
|
class TenantAssetTest extends TestCase
|
||||||
{
|
{
|
||||||
|
public $autoCreateTenant = false;
|
||||||
|
public $autoInitTenancy = false;
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
public function asset_can_be_accessed_using_the_url_returned_by_the_tenant_asset_helper()
|
public function asset_can_be_accessed_using_the_url_returned_by_the_tenant_asset_helper()
|
||||||
{
|
{
|
||||||
|
Tenant::create('foo.localhost');
|
||||||
|
tenancy()->init('foo.localhost');
|
||||||
|
|
||||||
$filename = 'testfile' . $this->randomString(10);
|
$filename = 'testfile' . $this->randomString(10);
|
||||||
\Storage::disk('public')->put($filename, 'bar');
|
\Storage::disk('public')->put($filename, 'bar');
|
||||||
$path = storage_path("app/public/$filename");
|
$path = storage_path("app/public/$filename");
|
||||||
|
|
@ -24,4 +32,28 @@ class TenantAssetTest extends TestCase
|
||||||
|
|
||||||
$this->assertSame('bar', $content);
|
$this->assertSame('bar', $content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function asset_helper_returns_a_link_to_TenantAssetController_when_asset_url_is_null()
|
||||||
|
{
|
||||||
|
config(['app.asset_url' => null]);
|
||||||
|
|
||||||
|
Tenant::create('foo.localhost');
|
||||||
|
tenancy()->init('foo.localhost');
|
||||||
|
|
||||||
|
$this->assertSame(route('stancl.tenancy.asset', ['path' => 'foo']), asset('foo'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function asset_helper_returns_a_link_to_an_external_url_when_asset_url_is_not_null()
|
||||||
|
{
|
||||||
|
config(['app.asset_url' => 'https://an-s3-bucket']);
|
||||||
|
|
||||||
|
$tenant = Tenant::create(['foo.localhost']);
|
||||||
|
tenancy()->init('foo.localhost');
|
||||||
|
|
||||||
|
$this->assertSame("https://an-s3-bucket/tenant{$tenant->id}/foo", asset('foo'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// todo test global asset
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue