mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 17:44:04 +00:00
[2.3.0] tenant_route() helper (#229)
* Add tenant_route helper * Add tests * Remove redundant setUp() * Fix test namespaces * Apply fixes from StyleCI
This commit is contained in:
parent
4e477b472f
commit
fd00be646e
4 changed files with 36 additions and 10 deletions
49
tests/RedirectTest.php
Normal file
49
tests/RedirectTest.php
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stancl\Tenancy\Tests;
|
||||
|
||||
use Route;
|
||||
use Stancl\Tenancy\Tenant;
|
||||
|
||||
class RedirectTest extends TestCase
|
||||
{
|
||||
public $autoCreateTenant = false;
|
||||
public $autoInitTenancy = false;
|
||||
|
||||
/** @test */
|
||||
public function tenant_redirect_macro_replaces_only_the_hostname()
|
||||
{
|
||||
config([
|
||||
'tenancy.features' => ['Stancl\Tenancy\Features\TenantRedirect'],
|
||||
]);
|
||||
|
||||
Route::get('/foobar', function () {
|
||||
return 'Foo';
|
||||
})->name('home');
|
||||
|
||||
Route::get('/redirect', function () {
|
||||
return redirect()->route('home')->tenant('abcd');
|
||||
});
|
||||
|
||||
Tenant::create('foo.localhost');
|
||||
tenancy()->init('foo.localhost');
|
||||
|
||||
$this->get('/redirect')
|
||||
->assertRedirect('http://abcd/foobar');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function tenant_route_helper_generates_correct_url()
|
||||
{
|
||||
Route::get('/abcdef/{a?}/{b?}', function () {
|
||||
return 'Foo';
|
||||
})->name('foo');
|
||||
|
||||
$this->assertSame('http://foo.localhost/abcdef/as/df', tenant_route('foo', ['a' => 'as', 'b' => 'df'], 'foo.localhost'));
|
||||
$this->assertSame('http://foo.localhost/abcdef', tenant_route('foo', [], 'foo.localhost'));
|
||||
|
||||
$this->assertSame('http://' . request()->getHost() . '/abcdef/x/y', tenant_route('foo', ['a' => 'x', 'b' => 'y']));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue