Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/Admin/DomainsTest.php
- This file was added.
<?php | |||||
namespace Tests\Feature\Controller\Admin; | |||||
use Tests\TestCase; | |||||
class DomainsTest extends TestCase | |||||
{ | |||||
/** | |||||
* {@inheritDoc} | |||||
*/ | |||||
public function setUp(): void | |||||
{ | |||||
parent::setUp(); | |||||
self::useAdminUrl(); | |||||
} | |||||
/** | |||||
* {@inheritDoc} | |||||
*/ | |||||
public function tearDown(): void | |||||
{ | |||||
parent::tearDown(); | |||||
} | |||||
/** | |||||
* Test domains searching (/api/v4/domains) | |||||
*/ | |||||
public function testIndex(): void | |||||
{ | |||||
$john = $this->getTestUser('john@kolab.org'); | |||||
$admin = $this->getTestUser('jeroen@jeroen.jeroen'); | |||||
// Non-admin user | |||||
$response = $this->actingAs($john)->get("api/v4/domains"); | |||||
$response->assertStatus(403); | |||||
// Search with no search criteria | |||||
$response = $this->actingAs($admin)->get("api/v4/domains"); | |||||
$response->assertStatus(200); | |||||
$json = $response->json(); | |||||
$this->assertSame(0, $json['count']); | |||||
$this->assertSame([], $json['list']); | |||||
// Search with no matches expected | |||||
$response = $this->actingAs($admin)->get("api/v4/domains?search=abcd12.org"); | |||||
$response->assertStatus(200); | |||||
$json = $response->json(); | |||||
$this->assertSame(0, $json['count']); | |||||
$this->assertSame([], $json['list']); | |||||
// Search by a domain name | |||||
$response = $this->actingAs($admin)->get("api/v4/domains?search=kolab.org"); | |||||
$response->assertStatus(200); | |||||
$json = $response->json(); | |||||
$this->assertSame(1, $json['count']); | |||||
$this->assertCount(1, $json['list']); | |||||
$this->assertSame('kolab.org', $json['list'][0]['namespace']); | |||||
// Search by owner | |||||
$response = $this->actingAs($admin)->get("api/v4/domains?owner={$john->id}"); | |||||
$response->assertStatus(200); | |||||
$json = $response->json(); | |||||
$this->assertSame(1, $json['count']); | |||||
$this->assertCount(1, $json['list']); | |||||
$this->assertSame('kolab.org', $json['list'][0]['namespace']); | |||||
// Search by owner (Ned is a controller on John's wallets, | |||||
// here we expect only domains assigned to Ned's wallet(s)) | |||||
$ned = $this->getTestUser('ned@kolab.org'); | |||||
$response = $this->actingAs($admin)->get("api/v4/domains?owner={$ned->id}"); | |||||
$response->assertStatus(200); | |||||
$json = $response->json(); | |||||
$this->assertSame(0, $json['count']); | |||||
$this->assertCount(0, $json['list']); | |||||
} | |||||
} |