@ -53,6 +53,7 @@ class LostControllerTest extends TestCase {
private $defaults;
/** @var IConfig | MockObject */
private $config;
private string $lostPasswordLink = '';
/** @var IMailer | MockObject */
private $mailer;
/** @var IManager|MockObject */
@ -93,11 +94,13 @@ class LostControllerTest extends TestCase {
$this->config = $this->createMock(IConfig::class);
$this->config->expects($this->any())
->method('getSystemValue')
->willReturnMap([
['secret', null, 'SECRET'],
['secret', '', 'SECRET'],
['lost_password_link', '', ''],
]);
->willReturnCallback(function (string $key, $default = '') {
return match ($key) {
'secret' => 'SECRET',
'lost_password_link' => $this->lostPasswordLink,
default => $default,
};
});
$this->l10n = $this->createMock(IL10N::class);
$this->l10n
->expects($this->any())
@ -162,6 +165,29 @@ class LostControllerTest extends TestCase {
$this->assertEquals($expectedResponse, $response);
}
public function testResetFormTokenErrorWithDisabledLink(): void {
$this->lostPasswordLink = 'disabled';
$this->userManager->method('get')
->with('ValidTokenUser')
->willReturn($this->existingUser);
$this->verificationToken->expects($this->once())
->method('check')
->with('12345:MySecretToken', $this->existingUser, 'lostpassword', 'test@example.com')
->willThrowException(new InvalidTokenException(InvalidTokenException::TOKEN_NOT_FOUND));
$response = $this->lostController->resetform('12345:MySecretToken', 'ValidTokenUser');
$expectedResponse = new TemplateResponse('core',
'error',
[
'errors' => [
['error' => 'Password reset is disabled'],
]
],
'guest');
$expectedResponse->throttle();
$this->assertEquals($expectedResponse, $response);
}
public function testResetFormValidToken(): void {
$this->userManager->method('get')
->with('ValidTokenUser')