Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Browser/LogonTest.php
<?php | <?php | ||||
namespace Tests\Browser; | namespace Tests\Browser; | ||||
use Tests\Browser; | use Tests\Browser; | ||||
use Tests\Browser\Components\Menu; | use Tests\Browser\Components\Menu; | ||||
use Tests\Browser\Components\Toast; | use Tests\Browser\Components\Toast; | ||||
use Tests\Browser\Pages\Dashboard; | use Tests\Browser\Pages\Dashboard; | ||||
use Tests\Browser\Pages\Home; | use Tests\Browser\Pages\Home; | ||||
use Tests\Browser\Pages\UserProfile; | |||||
use Tests\TestCaseDusk; | use Tests\TestCaseDusk; | ||||
use Illuminate\Foundation\Testing\DatabaseMigrations; | use Illuminate\Foundation\Testing\DatabaseMigrations; | ||||
class LogonTest extends TestCaseDusk | class LogonTest extends TestCaseDusk | ||||
{ | { | ||||
/** | /** | ||||
* Test menu on logon page | * Test menu on logon page | ||||
Show All 14 Lines | public function testLogonMenu(): void | ||||
$browser->assertMissing('#footer-menu .navbar-nav'); | $browser->assertMissing('#footer-menu .navbar-nav'); | ||||
} | } | ||||
}); | }); | ||||
} | } | ||||
/** | /** | ||||
* Test redirect to /login if user is unauthenticated | * Test redirect to /login if user is unauthenticated | ||||
*/ | */ | ||||
public function testLogonRedirect(): void | public function testRequiredAuth(): void | ||||
{ | { | ||||
$this->browse(function (Browser $browser) { | $this->browse(function (Browser $browser) { | ||||
$browser->visit('/dashboard'); | $browser->visit('/dashboard'); | ||||
// Checks if we're really on the login page | // Checks if we're really on the login page | ||||
$browser->waitForLocation('/login') | $browser->waitForLocation('/login') | ||||
->on(new Home()); | ->on(new Home()); | ||||
}); | }); | ||||
▲ Show 20 Lines • Show All 154 Lines • ▼ Show 20 Lines | public function test2FA(): void | ||||
// Test valid (TOTP) code | // Test valid (TOTP) code | ||||
$browser->type('@second-factor-input', $code) | $browser->type('@second-factor-input', $code) | ||||
->press('form button') | ->press('form button') | ||||
->waitUntilMissing('@second-factor-input.is-invalid') | ->waitUntilMissing('@second-factor-input.is-invalid') | ||||
->waitForLocation('/dashboard') | ->waitForLocation('/dashboard') | ||||
->on(new Dashboard()); | ->on(new Dashboard()); | ||||
}); | }); | ||||
} | } | ||||
/** | |||||
* Test redirect to the requested page after logon | |||||
* | |||||
* @depends test2FA | |||||
*/ | |||||
public function testAfterLogonRedirect(): void | |||||
{ | |||||
$this->browse(function (Browser $browser) { | |||||
// User is logged in | |||||
$browser->visit(new UserProfile()); | |||||
// Test redirect if the token is invalid | |||||
$browser->script("localStorage.setItem('token', '123')"); | |||||
$browser->refresh() | |||||
->on(new Home()) | |||||
->submitLogon('john@kolab.org', 'simple123', false) | |||||
->waitForLocation('/profile'); | |||||
}); | |||||
} | |||||
} | } |