From 068cee83ee201b531b8aed9e2c3963421ff63940 Mon Sep 17 00:00:00 2001 From: Abrar Ahmad Date: Wed, 30 Nov 2022 13:42:45 +0500 Subject: [PATCH] move only one test to without tenancy folder --- assets/config.php | 2 +- tests/Features/RedirectTest.php | 36 +++++++++++++++++++ .../WithoutTenancy/Features/RedirectTest.php | 30 ---------------- 3 files changed, 37 insertions(+), 31 deletions(-) create mode 100644 tests/Features/RedirectTest.php diff --git a/assets/config.php b/assets/config.php index 3778e107..4c3f0cb2 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/Features/RedirectTest.php b/tests/Features/RedirectTest.php new file mode 100644 index 00000000..3c90321c --- /dev/null +++ b/tests/Features/RedirectTest.php @@ -0,0 +1,36 @@ +app->register(new TenancyServiceProvider($this->app)); + + Route::get('/foobar', function () { + return 'Foo'; + })->name('home'); + + Route::get('/redirect', function () { + return redirect()->route('home')->domain('abcd'); + }); + + $tenant = Tenant::create(['id' => 'foo']); + tenancy()->initialize($tenant); + + pest()->get('/redirect') + ->assertRedirect('http://abcd/foobar'); +}); + +test('tenant route helper generates correct url', function () { + Route::get('/abcdef/{a?}/{b?}', function () { + return 'Foo'; + })->name('foo'); + + 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'); +}); diff --git a/tests/WithoutTenancy/Features/RedirectTest.php b/tests/WithoutTenancy/Features/RedirectTest.php index 61b13035..d0737e62 100644 --- a/tests/WithoutTenancy/Features/RedirectTest.php +++ b/tests/WithoutTenancy/Features/RedirectTest.php @@ -5,40 +5,10 @@ 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 () { - config()->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'); - }); - - $tenant = Tenant::create(['id' => 'foo']); // todo automatic id generation is not working - tenancy()->initialize($tenant); - - pest()->get('/redirect') - ->assertRedirect('http://abcd/foobar'); -}); - -test('tenant route helper generates correct url', function () { - Route::get('/abcdef/{a?}/{b?}', function () { - return 'Foo'; - })->name('foo'); - - 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) {