Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Browser/PasswordResetTest.php
<?php | <?php | ||||
namespace Tests\Browser; | namespace Tests\Browser; | ||||
use App\User; | use App\User; | ||||
use App\VerificationCode; | use App\VerificationCode; | ||||
use Tests\Browser; | use Tests\Browser; | ||||
use Tests\Browser\Components\Menu; | |||||
use Tests\Browser\Pages\Dashboard; | use Tests\Browser\Pages\Dashboard; | ||||
use Tests\Browser\Pages\Home; | use Tests\Browser\Pages\Home; | ||||
use Tests\Browser\Pages\PasswordReset; | use Tests\Browser\Pages\PasswordReset; | ||||
use Tests\TestCaseDusk; | use Tests\TestCaseDusk; | ||||
use Illuminate\Foundation\Testing\DatabaseMigrations; | use Illuminate\Foundation\Testing\DatabaseMigrations; | ||||
class PasswordResetTest extends TestCaseDusk | class PasswordResetTest extends TestCaseDusk | ||||
{ | { | ||||
Show All 18 Lines | class PasswordResetTest extends TestCaseDusk | ||||
} | } | ||||
/** | /** | ||||
* Test the link from logon to password-reset page | * Test the link from logon to password-reset page | ||||
*/ | */ | ||||
public function testLinkOnLogon(): void | public function testLinkOnLogon(): void | ||||
{ | { | ||||
$this->browse(function (Browser $browser) { | $this->browse(function (Browser $browser) { | ||||
$browser->visit(new Home()); | $browser->visit(new Home()) | ||||
->assertSeeLink('Forgot password?') | |||||
$browser->assertSeeLink('Forgot password?'); | ->clickLink('Forgot password?') | ||||
$browser->clickLink('Forgot password?'); | ->on(new PasswordReset()) | ||||
->assertVisible('@step1'); | |||||
$browser->on(new PasswordReset()); | |||||
$browser->assertVisible('@step1'); | |||||
}); | }); | ||||
} | } | ||||
/** | /** | ||||
* Test 1st step of password-reset | * Test 1st step of password-reset | ||||
*/ | */ | ||||
public function testStep1(): void | public function testStep1(): void | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 223 Lines • ▼ Show 20 Lines | public function testStep3(): void | ||||
// At this point we should be auto-logged-in to dashboard | // At this point we should be auto-logged-in to dashboard | ||||
$browser->on(new Dashboard()); | $browser->on(new Dashboard()); | ||||
// FIXME: Is it enough to be sure user is logged in? | // FIXME: Is it enough to be sure user is logged in? | ||||
}); | }); | ||||
} | } | ||||
/** | /** | ||||
* Test password-reset via a link | |||||
*/ | |||||
public function testResetViaLink(): void | |||||
{ | |||||
$user = $this->getTestUser('passwordresettestdusk@' . \config('app.domain')); | |||||
$user->setSetting('external_email', 'external@domain.tld'); | |||||
$code = new VerificationCode(['mode' => 'password-reset']); | |||||
$user->verificationcodes()->save($code); | |||||
$this->browse(function (Browser $browser) use ($code) { | |||||
// Test a valid link | |||||
$browser->visit("/password-reset/{$code->short_code}-{$code->code}") | |||||
->on(new PasswordReset()) | |||||
->waitFor('@step3') | |||||
->assertMissing('@step1') | |||||
->assertMissing('@step2') | |||||
->with('@step3', function ($step) { | |||||
$step->type('#reset_password', 'A2345678') | |||||
->type('#reset_password_confirmation', 'A2345678') | |||||
->click('[type=submit]'); | |||||
}) | |||||
->waitUntilMissing('@step3') | |||||
// At this point we should be auto-logged-in to dashboard | |||||
->on(new Dashboard()) | |||||
->within(new Menu(), function ($browser) { | |||||
$browser->clickMenuItem('logout'); | |||||
}); | |||||
$this->assertNull(VerificationCode::find($code->code)); | |||||
// Test an invalid link | |||||
$browser->visit("/password-reset/{$code->short_code}-{$code->code}") | |||||
->assertErrorPage(404, 'The password reset code is expired or invalid.'); | |||||
}); | |||||
} | |||||
/** | |||||
* Test password reset process for a user with 2FA enabled. | * Test password reset process for a user with 2FA enabled. | ||||
*/ | */ | ||||
public function testResetWith2FA(): void | public function testResetWith2FA(): void | ||||
{ | { | ||||
$this->markTestIncomplete(); | $this->markTestIncomplete(); | ||||
} | } | ||||
} | } |