Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/TenantTest.php
<?php | <?php | ||||
namespace Tests\Feature; | namespace Tests\Feature; | ||||
use App\Tenant; | use App\Tenant; | ||||
use App\TenantSetting; | |||||
use Tests\TestCase; | use Tests\TestCase; | ||||
class TenantTest extends TestCase | class TenantTest extends TestCase | ||||
{ | { | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function setUp(): void | public function setUp(): void | ||||
{ | { | ||||
parent::setUp(); | parent::setUp(); | ||||
TenantSetting::truncate(); | |||||
} | } | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function tearDown(): void | public function tearDown(): void | ||||
{ | { | ||||
TenantSetting::truncate(); | |||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
/** | /** | ||||
* Test Tenant::getConfig() method | |||||
*/ | |||||
public function testGetConfig(): void | |||||
{ | |||||
// No tenant id specified | |||||
$this->assertSame(\config('app.name'), Tenant::getConfig(null, 'app.name')); | |||||
$this->assertSame(\config('app.env'), Tenant::getConfig(null, 'app.env')); | |||||
$this->assertSame(null, Tenant::getConfig(null, 'app.unknown')); | |||||
$tenant = Tenant::whereNotIn('id', [1])->first(); | |||||
$tenant->setSetting('app.test', 'test'); | |||||
// Tenant specified | |||||
$this->assertSame($tenant->title, Tenant::getConfig($tenant->id, 'app.name')); | |||||
$this->assertSame('test', Tenant::getConfig($tenant->id, 'app.test')); | |||||
$this->assertSame(\config('app.env'), Tenant::getConfig($tenant->id, 'app.env')); | |||||
$this->assertSame(null, Tenant::getConfig($tenant->id, 'app.unknown')); | |||||
} | |||||
/** | |||||
* Test Tenant::wallet() method | * Test Tenant::wallet() method | ||||
*/ | */ | ||||
public function testWallet(): void | public function testWallet(): void | ||||
{ | { | ||||
$tenant = Tenant::find(1); | $tenant = Tenant::find(1); | ||||
$user = \App\User::where('email', 'reseller@' . \config('app.domain'))->first(); | $user = \App\User::where('email', 'reseller@' . \config('app.domain'))->first(); | ||||
$wallet = $tenant->wallet(); | $wallet = $tenant->wallet(); | ||||
$this->assertInstanceof(\App\Wallet::class, $wallet); | $this->assertInstanceof(\App\Wallet::class, $wallet); | ||||
$this->assertSame($user->wallets->first()->id, $wallet->id); | $this->assertSame($user->wallets->first()->id, $wallet->id); | ||||
} | } | ||||
} | } |