diff --git a/assets/config.php b/assets/config.php index 4c3f0cb2..3778e107 100644 --- a/assets/config.php +++ b/assets/config.php @@ -283,7 +283,7 @@ return [ // Stancl\Tenancy\Features\TelescopeTags::class, // Stancl\Tenancy\Features\UniversalRoutes::class, // 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 ], /** diff --git a/tests/Pest.php b/tests/Pest.php index d7ca8c22..3181e41a 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -2,9 +2,16 @@ 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; } + +function filesAndFolder(): array +{ + $dirs = scandir(__DIR__); + + return array_filter($dirs, fn($dir) => ! in_array($dir, ['.', '..', 'WithoutTenancy'], true)); +} diff --git a/tests/Features/RedirectTest.php b/tests/WithoutTenancy/Features/RedirectTest.php similarity index 51% rename from tests/Features/RedirectTest.php rename to tests/WithoutTenancy/Features/RedirectTest.php index 847b0cdf..61b13035 100644 --- a/tests/Features/RedirectTest.php +++ b/tests/WithoutTenancy/Features/RedirectTest.php @@ -4,10 +4,16 @@ declare(strict_types=1); use Illuminate\Support\Facades\Route; use Stancl\Tenancy\Features\CrossDomainRedirect; +use Stancl\Tenancy\TenancyServiceProvider; use Stancl\Tenancy\Tests\Etc\Tenant; +use Stancl\Tenancy\Tests\WithoutTenancy\TestCase; + +uses(TestCase::class); 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 () { return 'Foo'; @@ -17,7 +23,7 @@ test('tenant redirect macro replaces only the hostname', function () { return redirect()->route('home')->domain('abcd'); }); - $tenant = Tenant::create(); + $tenant = Tenant::create(['id' => 'foo']); // todo automatic id generation is not working tenancy()->initialize($tenant); 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) -test('redirect from central to tenant works', function () { - // `CrossDomainRedirect` feature already enabled in config +test('redirect from central to tenant works', function (bool $enabled, bool $shouldThrow) { + if ($enabled) { + config()->set('tenancy.features', [CrossDomainRedirect::class]); + } + + $this->app->register(new TenancyServiceProvider($this->app)); Route::get('/foobar', function () { return 'Foo'; @@ -45,6 +55,22 @@ test('redirect from central to tenant works', function () { return redirect()->route('home')->domain('abcd'); }); - pest()->get('/redirect') - ->assertRedirect('http://abcd/foobar'); -}); + 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], +]); diff --git a/tests/WithoutTenancy/TestCase.php b/tests/WithoutTenancy/TestCase.php new file mode 100644 index 00000000..3b630115 --- /dev/null +++ b/tests/WithoutTenancy/TestCase.php @@ -0,0 +1,13 @@ +