Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/DomainsTest.php
<?php | <?php | ||||
namespace Tests\Feature\Controller; | namespace Tests\Feature\Controller; | ||||
use App\Domain; | use App\Domain; | ||||
use App\Entitlement; | use App\Entitlement; | ||||
use App\Sku; | use App\Sku; | ||||
use App\Tenant; | |||||
use App\User; | use App\User; | ||||
use App\Wallet; | use App\Wallet; | ||||
use Illuminate\Support\Facades\Queue; | use Illuminate\Support\Facades\Queue; | ||||
use Illuminate\Support\Str; | use Illuminate\Support\Str; | ||||
use Tests\TestCase; | use Tests\TestCase; | ||||
class DomainsTest extends TestCase | class DomainsTest extends TestCase | ||||
{ | { | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function setUp(): void | public function setUp(): void | ||||
{ | { | ||||
parent::setUp(); | parent::setUp(); | ||||
$this->deleteTestUser('test1@' . \config('app.domain')); | $this->deleteTestUser('test1@' . \config('app.domain')); | ||||
$this->deleteTestUser('test2@' . \config('app.domain')); | $this->deleteTestUser('test2@' . \config('app.domain')); | ||||
$this->deleteTestUser('test1@domainscontroller.com'); | $this->deleteTestUser('test1@domainscontroller.com'); | ||||
$this->deleteTestDomain('domainscontroller.com'); | $this->deleteTestDomain('domainscontroller.com'); | ||||
Sku::where('title', 'test')->delete(); | |||||
} | } | ||||
public function tearDown(): void | public function tearDown(): void | ||||
{ | { | ||||
$this->deleteTestUser('test1@' . \config('app.domain')); | $this->deleteTestUser('test1@' . \config('app.domain')); | ||||
$this->deleteTestUser('test2@' . \config('app.domain')); | $this->deleteTestUser('test2@' . \config('app.domain')); | ||||
$this->deleteTestUser('test1@domainscontroller.com'); | $this->deleteTestUser('test1@domainscontroller.com'); | ||||
$this->deleteTestDomain('domainscontroller.com'); | $this->deleteTestDomain('domainscontroller.com'); | ||||
Sku::where('title', 'test')->delete(); | |||||
$domain = $this->getTestDomain('kolab.org'); | $domain = $this->getTestDomain('kolab.org'); | ||||
$domain->settings()->whereIn('key', ['spf_whitelist'])->delete(); | $domain->settings()->whereIn('key', ['spf_whitelist'])->delete(); | ||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 324 Lines • ▼ Show 20 Lines | public function testShow(): void | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
// Jack has no entitlement/control over kolab.org | // Jack has no entitlement/control over kolab.org | ||||
$response = $this->actingAs($jack)->get("api/v4/domains/{$domain->id}"); | $response = $this->actingAs($jack)->get("api/v4/domains/{$domain->id}"); | ||||
$response->assertStatus(403); | $response->assertStatus(403); | ||||
} | } | ||||
/** | /** | ||||
* Test fetching SKUs list for a domain (GET /domains/<id>/skus) | |||||
*/ | |||||
public function testSkus(): void | |||||
{ | |||||
$user = $this->getTestUser('john@kolab.org'); | |||||
$domain = $this->getTestDomain('kolab.org'); | |||||
// Unauth access not allowed | |||||
$response = $this->get("api/v4/domains/{$domain->id}/skus"); | |||||
$response->assertStatus(401); | |||||
// Create an sku for another tenant, to make sure it is not included in the result | |||||
$nsku = Sku::create([ | |||||
'title' => 'test', | |||||
'name' => 'Test', | |||||
'description' => '', | |||||
'active' => true, | |||||
'cost' => 100, | |||||
'handler_class' => 'App\Handlers\Domain', | |||||
]); | |||||
$tenant = Tenant::whereNotIn('id', [\config('app.tenant_id')])->first(); | |||||
$nsku->tenant_id = $tenant->id; | |||||
$nsku->save(); | |||||
$response = $this->actingAs($user)->get("api/v4/domains/{$domain->id}/skus"); | |||||
$response->assertStatus(200); | |||||
$json = $response->json(); | |||||
$this->assertCount(1, $json); | |||||
$this->assertSkuElement('domain-hosting', $json[0], [ | |||||
'prio' => 0, | |||||
'type' => 'domain', | |||||
'handler' => 'DomainHosting', | |||||
'enabled' => true, | |||||
'readonly' => true, | |||||
]); | |||||
} | |||||
/** | |||||
* Test fetching domain status (GET /api/v4/domains/<domain-id>/status) | * Test fetching domain status (GET /api/v4/domains/<domain-id>/status) | ||||
* and forcing setup process update (?refresh=1) | * and forcing setup process update (?refresh=1) | ||||
* | * | ||||
* @group dns | * @group dns | ||||
*/ | */ | ||||
public function testStatus(): void | public function testStatus(): void | ||||
{ | { | ||||
$john = $this->getTestUser('john@kolab.org'); | $john = $this->getTestUser('john@kolab.org'); | ||||
▲ Show 20 Lines • Show All 182 Lines • Show Last 20 Lines |