1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-06 00:04:03 +00:00

Convert test cases

This commit is contained in:
Shift 2022-06-28 20:56:04 +00:00
parent 405b91085e
commit a8dcd0dfc9
No known key found for this signature in database
GPG key ID: 5A96F038425C5A1C
27 changed files with 3059 additions and 3658 deletions

View file

@ -2,65 +2,55 @@
declare(strict_types=1);
namespace Stancl\Tenancy\Tests;
use Illuminate\Support\Facades\Route;
use Stancl\Tenancy\Features\UniversalRoutes;
use Stancl\Tenancy\Middleware\InitializeTenancyByDomain;
use Stancl\Tenancy\Tests\Etc\Tenant;
class UniversalRouteTest extends TestCase
{
public function tearDown(): void
{
InitializeTenancyByDomain::$onFail = null;
uses(Stancl\Tenancy\Tests\TestCase::class);
parent::tearDown();
}
afterEach(function () {
InitializeTenancyByDomain::$onFail = null;
});
/** @test */
public function a_route_can_work_in_both_central_and_tenant_context()
{
Route::middlewareGroup('universal', []);
config(['tenancy.features' => [UniversalRoutes::class]]);
test('a route can work in both central and tenant context', function () {
Route::middlewareGroup('universal', []);
config(['tenancy.features' => [UniversalRoutes::class]]);
Route::get('/foo', function () {
return tenancy()->initialized
? 'Tenancy is initialized.'
: 'Tenancy is not initialized.';
})->middleware(['universal', InitializeTenancyByDomain::class]);
Route::get('/foo', function () {
return tenancy()->initialized
? 'Tenancy is initialized.'
: 'Tenancy is not initialized.';
})->middleware(['universal', InitializeTenancyByDomain::class]);
$this->get('http://localhost/foo')
->assertSuccessful()
->assertSee('Tenancy is not initialized.');
$this->get('http://localhost/foo')
->assertSuccessful()
->assertSee('Tenancy is not initialized.');
$tenant = Tenant::create([
'id' => 'acme',
]);
$tenant->domains()->create([
'domain' => 'acme.localhost',
]);
$tenant = Tenant::create([
'id' => 'acme',
]);
$tenant->domains()->create([
'domain' => 'acme.localhost',
]);
$this->get('http://acme.localhost/foo')
->assertSuccessful()
->assertSee('Tenancy is initialized.');
}
$this->get('http://acme.localhost/foo')
->assertSuccessful()
->assertSee('Tenancy is initialized.');
});
/** @test */
public function making_one_route_universal_doesnt_make_all_routes_universal()
{
Route::get('/bar', function () {
return tenant('id');
})->middleware(InitializeTenancyByDomain::class);
test('making one route universal doesnt make all routes universal', function () {
Route::get('/bar', function () {
return tenant('id');
})->middleware(InitializeTenancyByDomain::class);
$this->a_route_can_work_in_both_central_and_tenant_context();
tenancy()->end();
$this->a_route_can_work_in_both_central_and_tenant_context();
tenancy()->end();
$this->get('http://localhost/bar')
->assertStatus(500);
$this->get('http://localhost/bar')
->assertStatus(500);
$this->get('http://acme.localhost/bar')
->assertSuccessful()
->assertSee('acme');
}
}
$this->get('http://acme.localhost/bar')
->assertSuccessful()
->assertSee('acme');
});