mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 15:34:04 +00:00
separate TestCase for redirect tests
This commit is contained in:
parent
be6b2f8248
commit
55560563b5
4 changed files with 56 additions and 10 deletions
|
|
@ -283,7 +283,7 @@ return [
|
||||||
// Stancl\Tenancy\Features\TelescopeTags::class,
|
// Stancl\Tenancy\Features\TelescopeTags::class,
|
||||||
// Stancl\Tenancy\Features\UniversalRoutes::class,
|
// Stancl\Tenancy\Features\UniversalRoutes::class,
|
||||||
// Stancl\Tenancy\Features\TenantConfig::class, // https://tenancyforlaravel.com/docs/v3/features/tenant-config
|
// Stancl\Tenancy\Features\TenantConfig::class, // https://tenancyforlaravel.com/docs/v3/features/tenant-config
|
||||||
Stancl\Tenancy\Features\CrossDomainRedirect::class, // https://tenancyforlaravel.com/docs/v3/features/cross-domain-redirect
|
// Stancl\Tenancy\Features\CrossDomainRedirect::class, // https://tenancyforlaravel.com/docs/v3/features/cross-domain-redirect
|
||||||
],
|
],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,16 @@
|
||||||
|
|
||||||
use Stancl\Tenancy\Tests\TestCase;
|
use Stancl\Tenancy\Tests\TestCase;
|
||||||
|
|
||||||
uses(TestCase::class)->in(__DIR__);
|
uses(TestCase::class)->in(...filesAndFolder());
|
||||||
|
|
||||||
function pest(): TestCase
|
function pest(): \Orchestra\Testbench\TestCase
|
||||||
{
|
{
|
||||||
return Pest\TestSuite::getInstance()->test;
|
return Pest\TestSuite::getInstance()->test;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function filesAndFolder(): array
|
||||||
|
{
|
||||||
|
$dirs = scandir(__DIR__);
|
||||||
|
|
||||||
|
return array_filter($dirs, fn($dir) => ! in_array($dir, ['.', '..', 'WithoutTenancy'], true));
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,16 @@ declare(strict_types=1);
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
use Stancl\Tenancy\Features\CrossDomainRedirect;
|
use Stancl\Tenancy\Features\CrossDomainRedirect;
|
||||||
|
use Stancl\Tenancy\TenancyServiceProvider;
|
||||||
use Stancl\Tenancy\Tests\Etc\Tenant;
|
use Stancl\Tenancy\Tests\Etc\Tenant;
|
||||||
|
use Stancl\Tenancy\Tests\WithoutTenancy\TestCase;
|
||||||
|
|
||||||
|
uses(TestCase::class);
|
||||||
|
|
||||||
test('tenant redirect macro replaces only the hostname', function () {
|
test('tenant redirect macro replaces only the hostname', function () {
|
||||||
// `CrossDomainRedirect` feature already enabled in config
|
config()->set('tenancy.features', [CrossDomainRedirect::class]);
|
||||||
|
|
||||||
|
$this->app->register(new TenancyServiceProvider($this->app));
|
||||||
|
|
||||||
Route::get('/foobar', function () {
|
Route::get('/foobar', function () {
|
||||||
return 'Foo';
|
return 'Foo';
|
||||||
|
|
@ -17,7 +23,7 @@ test('tenant redirect macro replaces only the hostname', function () {
|
||||||
return redirect()->route('home')->domain('abcd');
|
return redirect()->route('home')->domain('abcd');
|
||||||
});
|
});
|
||||||
|
|
||||||
$tenant = Tenant::create();
|
$tenant = Tenant::create(['id' => 'foo']); // todo automatic id generation is not working
|
||||||
tenancy()->initialize($tenant);
|
tenancy()->initialize($tenant);
|
||||||
|
|
||||||
pest()->get('/redirect')
|
pest()->get('/redirect')
|
||||||
|
|
@ -34,8 +40,12 @@ test('tenant route helper generates correct url', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check that `domain()` can be called on a redirect before tenancy is used (regression test for #949)
|
// 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 () {
|
test('redirect from central to tenant works', function (bool $enabled, bool $shouldThrow) {
|
||||||
// `CrossDomainRedirect` feature already enabled in config
|
if ($enabled) {
|
||||||
|
config()->set('tenancy.features', [CrossDomainRedirect::class]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->app->register(new TenancyServiceProvider($this->app));
|
||||||
|
|
||||||
Route::get('/foobar', function () {
|
Route::get('/foobar', function () {
|
||||||
return 'Foo';
|
return 'Foo';
|
||||||
|
|
@ -45,6 +55,22 @@ test('redirect from central to tenant works', function () {
|
||||||
return redirect()->route('home')->domain('abcd');
|
return redirect()->route('home')->domain('abcd');
|
||||||
});
|
});
|
||||||
|
|
||||||
pest()->get('/redirect')
|
try {
|
||||||
->assertRedirect('http://abcd/foobar');
|
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],
|
||||||
|
]);
|
||||||
13
tests/WithoutTenancy/TestCase.php
Normal file
13
tests/WithoutTenancy/TestCase.php
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Stancl\Tenancy\Tests\WithoutTenancy;
|
||||||
|
|
||||||
|
abstract class TestCase extends \Stancl\Tenancy\Tests\TestCase
|
||||||
|
{
|
||||||
|
protected function getPackageProviders($app)
|
||||||
|
{
|
||||||
|
return []; // We will provide TenancyServiceProvider in tests
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue