mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 22:14:03 +00:00
[2.3.0] More identification middleware (#323)
* Added request data identification middleware (#207) * Added request data identification middleware * Fixed styling * Changed to Illuminate request instead of helper * Enabled header and querystring customisation Co-authored-by: Jesper Jacobsen <joj@webshipper.com> * Apply fixes from StyleCI * Use constructor parameter instead of config * Add tests * Apply fixes from StyleCI Co-authored-by: JapSeyz <JapSeyz@JapSeyz.com> Co-authored-by: Jesper Jacobsen <joj@webshipper.com>
This commit is contained in:
parent
13422fb090
commit
f6115d590a
2 changed files with 132 additions and 0 deletions
62
tests/RequestDataIdentificationTest.php
Normal file
62
tests/RequestDataIdentificationTest.php
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stancl\Tenancy\Tests;
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Stancl\Tenancy\Middleware\InitializeTenancyByRequestData;
|
||||
use Stancl\Tenancy\Tenant;
|
||||
|
||||
class RequestDataIdentificationTest extends TestCase
|
||||
{
|
||||
public $autoCreateTenant = false;
|
||||
public $autoInitTenancy = false;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
config([
|
||||
'tenancy.exempt_domains' => [
|
||||
'localhost',
|
||||
],
|
||||
]);
|
||||
|
||||
Route::middleware(InitializeTenancyByRequestData::class)->get('/test', function () {
|
||||
return 'Tenant id: ' . tenant('id');
|
||||
});
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function header_identification_works()
|
||||
{
|
||||
$this->app->bind(InitializeTenancyByRequestData::class, function () {
|
||||
return new InitializeTenancyByRequestData('X-Tenant');
|
||||
});
|
||||
$tenant = Tenant::new()->save();
|
||||
$tenant2 = Tenant::new()->save();
|
||||
|
||||
$this
|
||||
->withoutExceptionHandling()
|
||||
->get('test', [
|
||||
'X-Tenant' => $tenant->id,
|
||||
])
|
||||
->assertSee($tenant->id);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function query_parameter_identification_works()
|
||||
{
|
||||
$this->app->bind(InitializeTenancyByRequestData::class, function () {
|
||||
return new InitializeTenancyByRequestData(null, 'tenant');
|
||||
});
|
||||
$tenant = Tenant::new()->save();
|
||||
$tenant2 = Tenant::new()->save();
|
||||
|
||||
$this
|
||||
->withoutExceptionHandling()
|
||||
->get('test?tenant=' . $tenant->id)
|
||||
->assertSee($tenant->id);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue