diff --git a/tests/Features/RedirectTest.php b/tests/Features/RedirectTest.php index 3929094d..4c836fab 100644 --- a/tests/Features/RedirectTest.php +++ b/tests/Features/RedirectTest.php @@ -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], +]); diff --git a/tests/WithoutTenancy/Features/RedirectTest.php b/tests/WithoutTenancy/Features/RedirectTest.php deleted file mode 100644 index d0737e62..00000000 --- a/tests/WithoutTenancy/Features/RedirectTest.php +++ /dev/null @@ -1,46 +0,0 @@ -set('tenancy.features', [CrossDomainRedirect::class]); - } - - $this->app->register(new TenancyServiceProvider($this->app)); - - 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], -]); diff --git a/tests/WithoutTenancy/TestCase.php b/tests/WithoutTenancy/TestCase.php deleted file mode 100644 index 3b630115..00000000 --- a/tests/WithoutTenancy/TestCase.php +++ /dev/null @@ -1,13 +0,0 @@ -