1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 14:34:04 +00:00

Delete WithoutTenancy directory, move tests

This commit is contained in:
lukinovec 2023-02-20 15:41:06 +01:00
parent 92a464520f
commit 241cf1fd21
3 changed files with 43 additions and 61 deletions

View file

@ -2,11 +2,15 @@
declare(strict_types=1);
use Illuminate\Support\Facades\Route;
use Stancl\Tenancy\Tests\Etc\Tenant;
use Illuminate\Support\Facades\Route;
use Stancl\Tenancy\TenancyServiceProvider;
use Stancl\Tenancy\Features\CrossDomainRedirect;
test('tenant redirect macro replaces only the hostname', function () {
// `CrossDomainRedirect` feature already enabled in config
config()->set('tenancy.features', [CrossDomainRedirect::class]);
TenancyServiceProvider::bootstrapFeatures();
Route::get('/foobar', function () {
return 'Foo';
@ -31,3 +35,40 @@ test('tenant route helper generates correct url', function () {
expect(tenant_route('foo.localhost', 'foo', ['a' => 'as', 'b' => 'df']))->toBe('http://foo.localhost/abcdef/as/df');
expect(tenant_route('foo.localhost', 'foo', []))->toBe('http://foo.localhost/abcdef');
});
// Check that `domain()` can be called on a redirect before tenancy is used (regression test for #949)
test('redirect from central to tenant works', function (bool $enabled, bool $shouldThrow) {
if ($enabled) {
config()->set('tenancy.features', [CrossDomainRedirect::class]);
TenancyServiceProvider::bootstrapFeatures();
}
Route::get('/foobar', function () {
return 'Foo';
})->name('home');
Route::get('/redirect', function () {
return redirect()->route('home')->domain('abcd');
});
try {
pest()->get('/redirect')
->assertRedirect('http://abcd/foobar');
if ($shouldThrow) {
pest()->fail('Exception not thrown');
}
} catch (Throwable $e) {
if ($shouldThrow) {
pest()->assertTrue(true); // empty assertion to make the test pass
} else {
pest()->fail('Exception thrown: ' . $e->getMessage());
}
}
})->with([
['enabled' => false, 'shouldThrow' => true],
['enabled' => true, 'shouldThrow' => false],
]);