1d403609dSGreg Roach<?php 2d403609dSGreg Roach 3d403609dSGreg Roach/** 4d403609dSGreg Roach * webtrees: online genealogy 5*89f7189bSGreg Roach * Copyright (C) 2021 webtrees development team 6d403609dSGreg Roach * This program is free software: you can redistribute it and/or modify 7d403609dSGreg Roach * it under the terms of the GNU General Public License as published by 8d403609dSGreg Roach * the Free Software Foundation, either version 3 of the License, or 9d403609dSGreg Roach * (at your option) any later version. 10d403609dSGreg Roach * This program is distributed in the hope that it will be useful, 11d403609dSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12d403609dSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13d403609dSGreg Roach * GNU General Public License for more details. 14d403609dSGreg Roach * You should have received a copy of the GNU General Public License 15*89f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 16d403609dSGreg Roach */ 17fcfa147eSGreg Roach 18d403609dSGreg Roachdeclare(strict_types=1); 19d403609dSGreg Roach 20d403609dSGreg Roachnamespace Fisharebest\Webtrees\Http\ResetHandlers; 21d403609dSGreg Roach 2271378461SGreg Roachuse Fig\Http\Message\StatusCodeInterface; 23d403609dSGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\PasswordResetPage; 24d403609dSGreg Roachuse Fisharebest\Webtrees\Services\UserService; 25d403609dSGreg Roachuse Fisharebest\Webtrees\TestCase; 26d403609dSGreg Roachuse Fisharebest\Webtrees\User; 27d403609dSGreg Roach 28d403609dSGreg Roach/** 29d403609dSGreg Roach * @covers \Fisharebest\Webtrees\Http\RequestHandlers\PasswordResetPage 30d403609dSGreg Roach */ 31d403609dSGreg Roachclass PasswordResetPageTest extends TestCase 32d403609dSGreg Roach{ 33d403609dSGreg Roach /** 34d403609dSGreg Roach * @return void 35d403609dSGreg Roach */ 36d403609dSGreg Roach public function testPasswordResetPageWithValidToken(): void 37d403609dSGreg Roach { 385e933c21SGreg Roach $user = self::createMock(User::class); 39d403609dSGreg Roach 405e933c21SGreg Roach $user_service = self::createMock(UserService::class); 41f917a287SGreg Roach $user_service 425e933c21SGreg Roach ->expects(self::once()) 43f917a287SGreg Roach ->method('findByToken') 44f917a287SGreg Roach ->with('1234') 45f917a287SGreg Roach ->willReturn($user); 46d403609dSGreg Roach 47f917a287SGreg Roach $request = self::createRequest() 48f917a287SGreg Roach ->withAttribute('token', '1234'); 49d403609dSGreg Roach $handler = new PasswordResetPage($user_service); 50d403609dSGreg Roach $response = $handler->handle($request); 51d403609dSGreg Roach 5271378461SGreg Roach self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode()); 53d403609dSGreg Roach } 54d403609dSGreg Roach 55d403609dSGreg Roach /** 56d403609dSGreg Roach * @return void 57d403609dSGreg Roach */ 58d403609dSGreg Roach public function testPasswordResetPageWithoutValidToken(): void 59d403609dSGreg Roach { 605e933c21SGreg Roach $user_service = self::createMock(UserService::class); 61f917a287SGreg Roach $user_service 625e933c21SGreg Roach ->expects(self::once()) 63f917a287SGreg Roach ->method('findByToken') 64f917a287SGreg Roach ->with('4321') 65f917a287SGreg Roach ->willReturn(null); 66d403609dSGreg Roach 67f917a287SGreg Roach $request = self::createRequest() 68f917a287SGreg Roach ->withAttribute('token', '4321'); 69d403609dSGreg Roach $handler = new PasswordResetPage($user_service); 70d403609dSGreg Roach $response = $handler->handle($request); 71d403609dSGreg Roach 7271378461SGreg Roach self::assertSame(StatusCodeInterface::STATUS_FOUND, $response->getStatusCode()); 73d403609dSGreg Roach } 74d403609dSGreg Roach} 75