mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-13 00:14:04 +00:00
Merge remote-tracking branch 'origin/3.x'
This commit is contained in:
commit
7c29764d81
10 changed files with 165 additions and 4 deletions
|
|
@ -295,11 +295,13 @@ test('migrate fresh command works', function () {
|
|||
test('run command with array of tenants works', function () {
|
||||
$tenantId1 = Tenant::create()->getTenantKey();
|
||||
$tenantId2 = Tenant::create()->getTenantKey();
|
||||
$tenantId3 = Tenant::create()->getTenantKey();
|
||||
Artisan::call('tenants:migrate-fresh');
|
||||
|
||||
pest()->artisan("tenants:run --tenants=$tenantId1 --tenants=$tenantId2 'foo foo --b=bar --c=xyz'")
|
||||
->expectsOutputToContain('Tenant: ' . $tenantId1)
|
||||
->expectsOutputToContain('Tenant: ' . $tenantId2)
|
||||
->doesntExpectOutput('Tenant: ' . $tenantId3)
|
||||
->assertExitCode(0);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -145,11 +145,78 @@ test('test asset controller returns a 404 when no path is provided', function ()
|
|||
|
||||
tenancy()->initialize($tenant);
|
||||
|
||||
$this->withoutExceptionHandling();
|
||||
pest()->expectExceptionMessage('Empty path'); // outside tests this is a 404
|
||||
|
||||
pest()->get(tenant_asset(null), [
|
||||
'X-Tenant' => $tenant->id,
|
||||
])->assertNotFound();
|
||||
});
|
||||
|
||||
test('tenant asset controller returns a 404 when the storage root doesnt exist', function () {
|
||||
config(['tenancy.identification.default_middleware' => InitializeTenancyByRequestData::class]);
|
||||
|
||||
$tenant = Tenant::create();
|
||||
|
||||
tenancy()->initialize($tenant);
|
||||
|
||||
$storageRoot = storage_path("app/public");
|
||||
|
||||
if (is_dir($storageRoot)) {
|
||||
rmdir(storage_path("app/public"));
|
||||
}
|
||||
|
||||
$this->withoutExceptionHandling();
|
||||
pest()->expectExceptionMessage("Storage root doesn't exist"); // outside tests this is a 404
|
||||
|
||||
pest()->get(tenant_asset('foo.txt'), [
|
||||
'X-Tenant' => $tenant->id,
|
||||
]);
|
||||
});
|
||||
|
||||
test('tenant asset controller returns a 404 when accessing a nonexistent file', function () {
|
||||
config(['tenancy.identification.default_middleware' => InitializeTenancyByRequestData::class]);
|
||||
|
||||
$tenant = Tenant::create();
|
||||
|
||||
tenancy()->initialize($tenant);
|
||||
|
||||
$storageRoot = storage_path("app/public");
|
||||
|
||||
if (! is_dir($storageRoot)) {
|
||||
mkdir(storage_path("app/public"), recursive: true);
|
||||
}
|
||||
|
||||
$this->withoutExceptionHandling();
|
||||
pest()->expectExceptionMessage("Accessing a nonexistent file"); // outside tests this is a 404
|
||||
|
||||
pest()->get(tenant_asset('foo.txt'), [
|
||||
'X-Tenant' => $tenant->id,
|
||||
]);
|
||||
});
|
||||
|
||||
test('test asset controller returns a 404 when accessing a file outside the storage root', function () {
|
||||
config(['tenancy.identification.default_middleware' => InitializeTenancyByRequestData::class]);
|
||||
|
||||
$tenant = Tenant::create();
|
||||
|
||||
tenancy()->initialize($tenant);
|
||||
|
||||
$storageRoot = storage_path("app/public");
|
||||
|
||||
if (! is_dir($storageRoot)) {
|
||||
mkdir(storage_path("app/public"), recursive: true);
|
||||
file_put_contents(storage_path('app/foo.txt'), 'bar');
|
||||
}
|
||||
|
||||
$this->withoutExceptionHandling();
|
||||
pest()->expectExceptionMessage('Accessing a file outside the storage root'); // outside tests this is a 404
|
||||
|
||||
pest()->get(tenant_asset('../foo.txt'), [
|
||||
'X-Tenant' => $tenant->id,
|
||||
]);
|
||||
});
|
||||
|
||||
function getEnvironmentSetUp($app)
|
||||
{
|
||||
$app->booted(function () {
|
||||
|
|
|
|||
|
|
@ -417,4 +417,46 @@ class Controller extends BaseController
|
|||
{
|
||||
return tenant() ? 'Tenancy is initialized.' : 'Tenancy is not initialized.';
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function universal_route_works_when_middleware_is_inserted_via_controller_middleware()
|
||||
{
|
||||
Route::middlewareGroup('universal', []);
|
||||
config(['tenancy.features' => [UniversalRoutes::class]]);
|
||||
|
||||
Route::get('/foo', [UniversalRouteController::class, 'show']);
|
||||
|
||||
$this->get('http://localhost/foo')
|
||||
->assertSuccessful()
|
||||
->assertSee('Tenancy is not initialized.');
|
||||
|
||||
$tenant = Tenant::create([
|
||||
'id' => 'acme',
|
||||
]);
|
||||
$tenant->domains()->create([
|
||||
'domain' => 'acme.localhost',
|
||||
]);
|
||||
|
||||
$this->get('http://acme.localhost/foo')
|
||||
->assertSuccessful()
|
||||
->assertSee('Tenancy is initialized.');
|
||||
}
|
||||
}
|
||||
|
||||
class UniversalRouteController
|
||||
{
|
||||
public function getMiddleware()
|
||||
{
|
||||
return array_map(fn($middleware) => [
|
||||
'middleware' => $middleware,
|
||||
'options' => [],
|
||||
], ['universal', InitializeTenancyByDomain::class]);
|
||||
}
|
||||
|
||||
public function show()
|
||||
{
|
||||
return tenancy()->initialized
|
||||
? 'Tenancy is initialized.'
|
||||
: 'Tenancy is not initialized.';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue