Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Browser/DomainTest.php
<?php | <?php | ||||
namespace Tests\Browser; | namespace Tests\Browser; | ||||
use App\Domain; | use App\Domain; | ||||
use App\User; | use App\User; | ||||
use Tests\Browser; | use Tests\Browser; | ||||
use Tests\Browser\Components\ListInput; | |||||
use Tests\Browser\Components\Toast; | use Tests\Browser\Components\Toast; | ||||
use Tests\Browser\Pages\Dashboard; | use Tests\Browser\Pages\Dashboard; | ||||
use Tests\Browser\Pages\DomainInfo; | use Tests\Browser\Pages\DomainInfo; | ||||
use Tests\Browser\Pages\DomainList; | use Tests\Browser\Pages\DomainList; | ||||
use Tests\Browser\Pages\Home; | use Tests\Browser\Pages\Home; | ||||
use Tests\TestCaseDusk; | use Tests\TestCaseDusk; | ||||
use Illuminate\Foundation\Testing\DatabaseMigrations; | use Illuminate\Foundation\Testing\DatabaseMigrations; | ||||
Show All 38 Lines | public function testDomainInfo(): void | ||||
$this->browse(function ($browser) { | $this->browse(function ($browser) { | ||||
// Unconfirmed domain | // Unconfirmed domain | ||||
$domain = Domain::where('namespace', 'kolab.org')->first(); | $domain = Domain::where('namespace', 'kolab.org')->first(); | ||||
if ($domain->isConfirmed()) { | if ($domain->isConfirmed()) { | ||||
$domain->status ^= Domain::STATUS_CONFIRMED; | $domain->status ^= Domain::STATUS_CONFIRMED; | ||||
$domain->save(); | $domain->save(); | ||||
} | } | ||||
$domain->setSetting('spf_whitelist', \json_encode(['.test.com'])); | |||||
$browser->visit('/domain/' . $domain->id) | $browser->visit('/domain/' . $domain->id) | ||||
->on(new DomainInfo()) | ->on(new DomainInfo()) | ||||
->whenAvailable('@verify', function ($browser) use ($domain) { | ->whenAvailable('@verify', function ($browser) use ($domain) { | ||||
$browser->assertSeeIn('pre', $domain->namespace) | $browser->assertSeeIn('pre', $domain->namespace) | ||||
->assertSeeIn('pre', $domain->hash()) | ->assertSeeIn('pre', $domain->hash()) | ||||
->click('button') | ->click('button') | ||||
->assertToast(Toast::TYPE_SUCCESS, 'Domain verified successfully.'); | ->assertToast(Toast::TYPE_SUCCESS, 'Domain verified successfully.'); | ||||
// TODO: Test scenario when a domain confirmation failed | // TODO: Test scenario when a domain confirmation failed | ||||
}) | }) | ||||
->whenAvailable('@config', function ($browser) use ($domain) { | ->whenAvailable('@config', function ($browser) use ($domain) { | ||||
$browser->assertSeeIn('pre', $domain->namespace); | $browser->assertSeeIn('pre', $domain->namespace); | ||||
}) | }) | ||||
->assertMissing('@verify'); | ->assertMissing('@verify'); | ||||
// Check that confirmed domain page contains only the config box | // Check that confirmed domain page contains only the config box | ||||
$browser->visit('/domain/' . $domain->id) | $browser->visit('/domain/' . $domain->id) | ||||
->on(new DomainInfo()) | ->on(new DomainInfo()) | ||||
->assertMissing('@verify') | ->assertMissing('@verify') | ||||
->assertPresent('@config'); | ->assertPresent('@config'); | ||||
}); | }); | ||||
} | } | ||||
/** | /** | ||||
* Test domain settings | |||||
*/ | |||||
public function testDomainSettings(): void | |||||
{ | |||||
$this->browse(function ($browser) { | |||||
$domain = Domain::where('namespace', 'kolab.org')->first(); | |||||
$domain->setSetting('spf_whitelist', \json_encode(['.test.com'])); | |||||
$browser->visit('/domain/' . $domain->id) | |||||
->on(new DomainInfo()) | |||||
->assertElementsCount('@nav a', 2) | |||||
->assertSeeIn('@nav #tab-general', 'Domain configuration') | |||||
->assertSeeIn('@nav #tab-settings', 'Settings') | |||||
->click('@nav #tab-settings') | |||||
->with('#settings form', function (Browser $browser) { | |||||
// Test whitelist widget | |||||
$widget = new ListInput('#spf_whitelist'); | |||||
$browser->assertSeeIn('div.row:nth-child(1) label', 'SPF Whitelist') | |||||
->assertVisible('div.row:nth-child(1) .list-input') | |||||
->with($widget, function (Browser $browser) { | |||||
$browser->assertListInputValue(['.test.com']) | |||||
->assertValue('@input', '') | |||||
->addListEntry('invalid domain'); | |||||
}) | |||||
->click('button[type=submit]') | |||||
->assertToast(Toast::TYPE_ERROR, 'Form validation error') | |||||
->with($widget, function (Browser $browser) { | |||||
$err = 'The entry format is invalid. Expected a domain name starting with a dot.'; | |||||
$browser->assertFormError(2, $err, false) | |||||
->removeListEntry(2) | |||||
->removeListEntry(1) | |||||
->addListEntry('.new.domain.tld'); | |||||
}) | |||||
->click('button[type=submit]') | |||||
->assertToast(Toast::TYPE_SUCCESS, 'Domain settings updated successfully.'); | |||||
}); | |||||
}); | |||||
} | |||||
/** | |||||
* Test domains list page (unauthenticated) | * Test domains list page (unauthenticated) | ||||
*/ | */ | ||||
public function testDomainListUnauth(): void | public function testDomainListUnauth(): void | ||||
{ | { | ||||
// Test that the page requires authentication | // Test that the page requires authentication | ||||
$this->browse(function ($browser) { | $this->browse(function ($browser) { | ||||
$browser->visit('/logout') | $browser->visit('/logout') | ||||
->visit('/domains') | ->visit('/domains') | ||||
▲ Show 20 Lines • Show All 65 Lines • Show Last 20 Lines |