mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 12:24:04 +00:00
* Add Laravel 12 support, drop Laravel 11 support * Fix RLS tree generation (specify schema name in generateTrees()) * ci fixes, use stable virtualcolumn version --------- Co-authored-by: lukinovec <lukinovec@gmail.com>
60 lines
1.7 KiB
PHP
60 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Illuminate\Support\Facades\Route;
|
|
use Stancl\Tenancy\Middleware\InitializeTenancyByDomainOrSubdomain;
|
|
use Stancl\Tenancy\Tests\Etc\Tenant;
|
|
use function Stancl\Tenancy\Tests\pest;
|
|
|
|
beforeEach(function () {
|
|
Route::group([
|
|
'middleware' => InitializeTenancyByDomainOrSubdomain::class,
|
|
], function () {
|
|
Route::get('/test', function () {
|
|
return tenant('id');
|
|
});
|
|
});
|
|
});
|
|
|
|
test('tenant can be identified by subdomain', function () {
|
|
config(['tenancy.identification.central_domains' => ['localhost']]);
|
|
|
|
$tenant = Tenant::create(['id' => 'acme']);
|
|
$tenant->domains()->create(['domain' => 'foo']);
|
|
|
|
expect(tenancy()->initialized)->toBeFalse();
|
|
|
|
pest()->get('http://foo.localhost/test')->assertSee('acme');
|
|
});
|
|
|
|
test('tenant can be identified by domain', function () {
|
|
config(['tenancy.identification.central_domains' => []]);
|
|
|
|
$tenant = Tenant::create(['id' => 'acme']);
|
|
$tenant->domains()->create(['domain' => 'foobar.localhost']);
|
|
|
|
expect(tenancy()->initialized)->toBeFalse();
|
|
|
|
pest()->get('http://foobar.localhost/test')->assertSee('acme');
|
|
});
|
|
|
|
test('domain records can be either in domain syntax or subdomain syntax', function () {
|
|
config(['tenancy.identification.central_domains' => ['localhost']]);
|
|
|
|
$foo = Tenant::create(['id' => 'foo']);
|
|
$foo->domains()->create(['domain' => 'foo']);
|
|
|
|
$bar = Tenant::create(['id' => 'bar']);
|
|
$bar->domains()->create(['domain' => 'bar.localhost']);
|
|
|
|
expect(tenancy()->initialized)->toBeFalse();
|
|
|
|
// Subdomain format
|
|
pest()->get('http://foo.localhost/test')->assertSee('foo');
|
|
|
|
tenancy()->end();
|
|
|
|
// Domain format
|
|
pest()->get('http://bar.localhost/test')->assertSee('bar');
|
|
});
|