mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 14:14:04 +00:00
path identification wip
This commit is contained in:
parent
7ad93adde5
commit
5e6d82be57
8 changed files with 215 additions and 3 deletions
111
tests/v3/PathIdentificationTest.php
Normal file
111
tests/v3/PathIdentificationTest.php
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy\Tests\v3;
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Stancl\Tenancy\Database\Models\Tenant;
|
||||
use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedByPathException;
|
||||
use Stancl\Tenancy\Middleware\InitializeTenancyByPath;
|
||||
use Stancl\Tenancy\Tests\TestCase;
|
||||
|
||||
class PathIdentificationTest extends TestCase
|
||||
{
|
||||
public function getEnvironmentSetup($app)
|
||||
{
|
||||
parent::getEnvironmentSetUp($app);
|
||||
|
||||
config(['tenancy.global_middleware' => []]);
|
||||
}
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Route::group([
|
||||
'prefix' => '/{tenant}',
|
||||
'middleware' => InitializeTenancyByPath::class,
|
||||
], function () {
|
||||
Route::get('/foo/{a}/{b}', function ($a, $b) {
|
||||
return "$a + $b";
|
||||
});
|
||||
|
||||
Route::get('/bar', [TestController::class, 'index']);
|
||||
});
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function tenant_can_be_identified_by_path()
|
||||
{
|
||||
Tenant::create([
|
||||
'id' => 'acme',
|
||||
]);
|
||||
|
||||
$this->assertFalse(tenancy()->initialized);
|
||||
|
||||
$this
|
||||
->get('/acme/foo/abc/xyz');
|
||||
|
||||
$this->assertTrue(tenancy()->initialized);
|
||||
$this->assertSame('acme', tenant('id'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function route_actions_dont_get_the_tenant_id()
|
||||
{
|
||||
Tenant::create([
|
||||
'id' => 'acme',
|
||||
]);
|
||||
|
||||
$this->assertFalse(tenancy()->initialized);
|
||||
|
||||
$this
|
||||
->get('/acme/foo/abc/xyz')
|
||||
->assertSee('abc + xyz');
|
||||
|
||||
$this->assertTrue(tenancy()->initialized);
|
||||
$this->assertSame('acme', tenant('id'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function exception_is_thrown_when_tenant_cannot_be_identified_by_path()
|
||||
{
|
||||
// todo the exception assertion doesn't work
|
||||
$this->expectException(TenantCouldNotBeIdentifiedByPathException::class);
|
||||
|
||||
$this->assertFalse(tenancy()->initialized);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function tenancy_is_initialized_prior_to_controller_constructors()
|
||||
{
|
||||
// todo same test for domain resolver
|
||||
|
||||
Tenant::create([
|
||||
'id' => 'acme',
|
||||
]);
|
||||
|
||||
$this->assertFalse(tenancy()->initialized);
|
||||
|
||||
$this
|
||||
->get('/acme/bar')
|
||||
->assertSee('foo');
|
||||
|
||||
// todo make this pass
|
||||
$this->assertTrue(app('tenancy_was_initialized_in_constructor'));
|
||||
$this->assertTrue(tenancy()->initialized);
|
||||
$this->assertSame('acme', tenant('id'));
|
||||
}
|
||||
}
|
||||
|
||||
class TestController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
app()->instance('tenancy_was_initialized_in_constructor', tenancy()->initialized);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return 'foo';
|
||||
}
|
||||
}
|
||||
0
tests/v3/SubdomainIdentificationTest.php
Normal file
0
tests/v3/SubdomainIdentificationTest.php
Normal file
Loading…
Add table
Add a link
Reference in a new issue