. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Http\RequestHandlers; use Fig\Http\Message\RequestMethodInterface; use Fig\Http\Message\StatusCodeInterface; use Fisharebest\Webtrees\Http\Exceptions\HttpNotFoundException; use Fisharebest\Webtrees\Services\TreeService; use Fisharebest\Webtrees\TestCase; use Fisharebest\Webtrees\Tree; use Illuminate\Support\Collection; /** * @covers \Fisharebest\Webtrees\Http\RequestHandlers\RedirectCalendarPhp */ class RedirectCalendarPhpTest extends TestCase { /** * @return void */ public function testRedirect(): void { $tree = $this->createStub(Tree::class); $tree ->method('name') ->willReturn('tree1'); $tree_service = $this->createStub(TreeService::class); $tree_service ->expects(self::once()) ->method('all') ->willReturn(new Collection(['tree1' => $tree])); $handler = new RedirectCalendarPhp($tree_service); $request = self::createRequest( RequestMethodInterface::METHOD_GET, ['ged' => 'tree1'], [], [], ['base_url' => 'https://www.example.com'] ); $response = $handler->handle($request); self::assertSame(StatusCodeInterface::STATUS_MOVED_PERMANENTLY, $response->getStatusCode()); self::assertSame( 'https://www.example.com/index.php?route=%2Ftree1%2Fcalendar%2Fday&cal=&day=&month=&year=&filterev=&filterof=&filtersx=', $response->getHeaderLine('Location') ); } /** * @return void */ public function testNoSuchTree(): void { $tree_service = $this->createStub(TreeService::class); $tree_service ->expects(self::once()) ->method('all') ->willReturn(new Collection([])); $handler = new RedirectCalendarPhp($tree_service); $request = self::createRequest(RequestMethodInterface::METHOD_GET, ['ged' => 'tree1']); $this->expectException(HttpNotFoundException::class); $handler->handle($request); } }