13340ecd2SGreg Roach<?php 23340ecd2SGreg Roach 33340ecd2SGreg Roach/** 43340ecd2SGreg Roach * webtrees: online genealogy 5d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 63340ecd2SGreg Roach * This program is free software: you can redistribute it and/or modify 73340ecd2SGreg Roach * it under the terms of the GNU General Public License as published by 83340ecd2SGreg Roach * the Free Software Foundation, either version 3 of the License, or 93340ecd2SGreg Roach * (at your option) any later version. 103340ecd2SGreg Roach * This program is distributed in the hope that it will be useful, 113340ecd2SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 123340ecd2SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 133340ecd2SGreg Roach * GNU General Public License for more details. 143340ecd2SGreg Roach * You should have received a copy of the GNU General Public License 153340ecd2SGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 163340ecd2SGreg Roach */ 173340ecd2SGreg Roach 183340ecd2SGreg Roachdeclare(strict_types=1); 193340ecd2SGreg Roach 203340ecd2SGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 213340ecd2SGreg Roach 223340ecd2SGreg Roachuse Fig\Http\Message\RequestMethodInterface; 233340ecd2SGreg Roachuse Fig\Http\Message\StatusCodeInterface; 2415c4f62cSGreg Roachuse Fisharebest\Webtrees\Http\Exceptions\HttpGoneException; 253340ecd2SGreg Roachuse Fisharebest\Webtrees\Services\TreeService; 263340ecd2SGreg Roachuse Fisharebest\Webtrees\TestCase; 273340ecd2SGreg Roachuse Fisharebest\Webtrees\Tree; 283340ecd2SGreg Roachuse Illuminate\Support\Collection; 29202c018bSGreg Roachuse PHPUnit\Framework\Attributes\CoversClass; 303340ecd2SGreg Roach 31202c018bSGreg Roach#[CoversClass(RedirectCalendarPhp::class)] 323340ecd2SGreg Roachclass RedirectCalendarPhpTest extends TestCase 333340ecd2SGreg Roach{ 34a26ec5edSGreg Roach protected static bool $uses_database = true; 35a26ec5edSGreg Roach 363340ecd2SGreg Roach public function testRedirect(): void 373340ecd2SGreg Roach { 3862ff2f18SGreg Roach $tree = $this->createMock(Tree::class); 393340ecd2SGreg Roach $tree 403340ecd2SGreg Roach ->method('name') 413340ecd2SGreg Roach ->willReturn('tree1'); 423340ecd2SGreg Roach 4362ff2f18SGreg Roach $tree_service = $this->createMock(TreeService::class); 443340ecd2SGreg Roach $tree_service 45*00ef1d3aSGreg Roach ->expects($this->once()) 463340ecd2SGreg Roach ->method('all') 473340ecd2SGreg Roach ->willReturn(new Collection(['tree1' => $tree])); 483340ecd2SGreg Roach 493340ecd2SGreg Roach $handler = new RedirectCalendarPhp($tree_service); 503340ecd2SGreg Roach 513340ecd2SGreg Roach $request = self::createRequest( 523340ecd2SGreg Roach RequestMethodInterface::METHOD_GET, 533340ecd2SGreg Roach ['ged' => 'tree1'], 543340ecd2SGreg Roach [], 553340ecd2SGreg Roach [], 563340ecd2SGreg Roach ['base_url' => 'https://www.example.com'] 573340ecd2SGreg Roach ); 583340ecd2SGreg Roach 593340ecd2SGreg Roach $response = $handler->handle($request); 603340ecd2SGreg Roach 613340ecd2SGreg Roach self::assertSame(StatusCodeInterface::STATUS_MOVED_PERMANENTLY, $response->getStatusCode()); 623340ecd2SGreg Roach self::assertSame( 63266e9c61SGreg Roach 'https://www.example.com/index.php?route=%2Ftree1%2Fcalendar%2Fday&cal=&day=&month=&year=&filterev=&filterof=&filtersx=', 643340ecd2SGreg Roach $response->getHeaderLine('Location') 653340ecd2SGreg Roach ); 663340ecd2SGreg Roach } 673340ecd2SGreg Roach 683340ecd2SGreg Roach public function testNoSuchTree(): void 693340ecd2SGreg Roach { 7062ff2f18SGreg Roach $tree_service = $this->createMock(TreeService::class); 713340ecd2SGreg Roach $tree_service 72*00ef1d3aSGreg Roach ->expects($this->once()) 733340ecd2SGreg Roach ->method('all') 743340ecd2SGreg Roach ->willReturn(new Collection([])); 753340ecd2SGreg Roach 763340ecd2SGreg Roach $handler = new RedirectCalendarPhp($tree_service); 773340ecd2SGreg Roach 783340ecd2SGreg Roach $request = self::createRequest(RequestMethodInterface::METHOD_GET, ['ged' => 'tree1']); 793340ecd2SGreg Roach 8015c4f62cSGreg Roach $this->expectException(HttpGoneException::class); 813340ecd2SGreg Roach 823340ecd2SGreg Roach $handler->handle($request); 833340ecd2SGreg Roach } 843340ecd2SGreg Roach} 85