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\Components\Error; | use Tests\Browser\Components\Error; | ||||
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\DuskTestCase; | use Tests\DuskTestCase; | ||||
use Laravel\Dusk\Browser; | |||||
use Illuminate\Foundation\Testing\DatabaseMigrations; | use Illuminate\Foundation\Testing\DatabaseMigrations; | ||||
class DomainTest extends DuskTestCase | class DomainTest extends DuskTestCase | ||||
{ | { | ||||
/** | /** | ||||
* Test domain info page (unauthenticated) | * Test domain info page (unauthenticated) | ||||
*/ | */ | ||||
public function testDomainInfoUnauth(): void | public function testDomainInfoUnauth(): void | ||||
{ | { | ||||
// Test that the page requires authentication | // Test that the page requires authentication | ||||
$this->browse(function (Browser $browser) { | $this->browse(function ($browser) { | ||||
$browser->visit('/domain/123')->on(new Home()); | $browser->visit('/domain/123')->on(new Home()); | ||||
}); | }); | ||||
} | } | ||||
/** | /** | ||||
* Test domain info page (non-existing domain id) | * Test domain info page (non-existing domain id) | ||||
*/ | */ | ||||
public function testDomainInfo404(): void | public function testDomainInfo404(): void | ||||
{ | { | ||||
$this->browse(function (Browser $browser) { | $this->browse(function ($browser) { | ||||
// FIXME: I couldn't make loginAs() method working | // FIXME: I couldn't make loginAs() method working | ||||
// Note: Here we're also testing that unauthenticated request | // Note: Here we're also testing that unauthenticated request | ||||
// is passed to logon form and then "redirected" to the requested page | // is passed to logon form and then "redirected" to the requested page | ||||
$browser->visit('/domain/123') | $browser->visit('/domain/123') | ||||
->on(new Home()) | ->on(new Home()) | ||||
->submitLogon('john@kolab.org', 'simple123') | ->submitLogon('john@kolab.org', 'simple123') | ||||
// TODO: the check below could look simpler, but we can't | // TODO: the check below could look simpler, but we can't | ||||
// just remove the callback argument. We'll create | // just remove the callback argument. We'll create | ||||
// Browser wrapper in future, then we could create expectError() method | // Browser wrapper in future, then we could create expectError() method | ||||
->with(new Error('404'), function (Browser $browser) { | ->with(new Error('404'), function ($browser) { | ||||
}); | }); | ||||
}); | }); | ||||
} | } | ||||
/** | /** | ||||
* Test domain info page (existing domain) | * Test domain info page (existing domain) | ||||
* | * | ||||
* @depends testDomainInfo404 | * @depends testDomainInfo404 | ||||
*/ | */ | ||||
public function testDomainInfo(): void | public function testDomainInfo(): void | ||||
{ | { | ||||
$this->browse(function (Browser $browser) { | $this->browse(function ($browser) { | ||||
// Unconfirmed domain | // Unconfirmed domain | ||||
$domain = Domain::where('namespace', 'kolab.org')->first(); | $domain = Domain::where('namespace', 'kolab.org')->first(); | ||||
$domain->status ^= Domain::STATUS_CONFIRMED; | $domain->status ^= Domain::STATUS_CONFIRMED; | ||||
$domain->save(); | $domain->save(); | ||||
$browser->visit('/domain/' . $domain->id) | $browser->visit('/domain/' . $domain->id) | ||||
->on(new DomainInfo()) | ->on(new DomainInfo()) | ||||
->whenAvailable('@verify', function (Browser $browser) use ($domain) { | ->whenAvailable('@verify', function ($browser) use ($domain) { | ||||
// Make sure the domain is confirmed now | // Make sure the domain is confirmed now | ||||
// TODO: Test verification process failure | // TODO: Test verification process failure | ||||
$domain->status |= Domain::STATUS_CONFIRMED; | $domain->status |= Domain::STATUS_CONFIRMED; | ||||
$domain->save(); | $domain->save(); | ||||
$browser->assertSeeIn('pre', $domain->namespace) | $browser->assertSeeIn('pre', $domain->namespace) | ||||
->assertSeeIn('pre', $domain->hash()) | ->assertSeeIn('pre', $domain->hash()) | ||||
->click('button'); | ->click('button'); | ||||
}) | }) | ||||
->whenAvailable('@config', function (Browser $browser) use ($domain) { | ->whenAvailable('@config', function ($browser) use ($domain) { | ||||
$browser->assertSeeIn('pre', $domain->namespace); | $browser->assertSeeIn('pre', $domain->namespace); | ||||
}) | }) | ||||
->assertMissing('@verify') | ->assertMissing('@verify') | ||||
->with(new Toast(Toast::TYPE_SUCCESS), function (Browser $browser) { | ->with(new Toast(Toast::TYPE_SUCCESS), function ($browser) { | ||||
$browser->assertToastTitle('') | $browser->assertToastTitle('') | ||||
->assertToastMessage('Domain verified successfully') | ->assertToastMessage('Domain verified successfully') | ||||
->closeToast(); | ->closeToast(); | ||||
}); | }); | ||||
// 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 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 $browser) { | $this->browse(function ($browser) { | ||||
$browser->visit('/logout') | $browser->visit('/logout') | ||||
->visit('/domains') | ->visit('/domains') | ||||
->on(new Home()); | ->on(new Home()); | ||||
}); | }); | ||||
} | } | ||||
/** | /** | ||||
* Test domains list page | * Test domains list page | ||||
* | * | ||||
* @depends testDomainListUnauth | * @depends testDomainListUnauth | ||||
*/ | */ | ||||
public function testDomainList(): void | public function testDomainList(): void | ||||
{ | { | ||||
$this->browse(function (Browser $browser) { | $this->browse(function ($browser) { | ||||
// Login the user | // Login the user | ||||
$browser->visit('/login') | $browser->visit('/login') | ||||
->on(new Home()) | ->on(new Home()) | ||||
->submitLogon('john@kolab.org', 'simple123', true) | ->submitLogon('john@kolab.org', 'simple123', true) | ||||
// On dashboard click the "Domains" link | // On dashboard click the "Domains" link | ||||
->on(new Dashboard()) | ->on(new Dashboard()) | ||||
->assertSeeIn('@links a.link-domains', 'Domains') | ->assertSeeIn('@links a.link-domains', 'Domains') | ||||
->click('@links a.link-domains') | ->click('@links a.link-domains') | ||||
// On Domains List page click the domain entry | // On Domains List page click the domain entry | ||||
->on(new DomainList()) | ->on(new DomainList()) | ||||
->assertSeeIn('@table tbody tr:first-child td:first-child', 'kolab.org') | ->assertSeeIn('@table tbody tr:first-child td:first-child', 'kolab.org') | ||||
->click('@table tbody tr:first-child td:first-child a') | ->click('@table tbody tr:first-child td:first-child a') | ||||
// On Domain Info page verify that's the clicked domain | // On Domain Info page verify that's the clicked domain | ||||
->on(new DomainInfo()) | ->on(new DomainInfo()) | ||||
->whenAvailable('@config', function (Browser $browser) { | ->whenAvailable('@config', function ($browser) { | ||||
$browser->assertSeeIn('pre', 'kolab.org'); | $browser->assertSeeIn('pre', 'kolab.org'); | ||||
}); | }); | ||||
}); | }); | ||||
} | } | ||||
} | } |