1<?php 2 3/** 4 * webtrees: online genealogy 5 * Copyright (C) 2019 webtrees development team 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17declare(strict_types=1); 18 19namespace Fisharebest\Webtrees\Http\Middleware; 20 21use Fisharebest\Webtrees\Module\WebtreesTheme; 22use Fisharebest\Webtrees\Module\XeneaTheme; 23use Fisharebest\Webtrees\Services\ModuleService; 24use Fisharebest\Webtrees\TestCase; 25use Illuminate\Support\Collection; 26use Psr\Http\Server\RequestHandlerInterface; 27 28use function response; 29 30/** 31 * Test the BootModules middleware. 32 * 33 * @covers \Fisharebest\Webtrees\Http\Middleware\BootModules 34 */ 35class BootModulesTest extends TestCase 36{ 37 /** 38 * @return void 39 */ 40 public function testMiddleware(): void 41 { 42 $handler = $this->createMock(RequestHandlerInterface::class); 43 $handler->method('handle')->willReturn(response()); 44 45 // Theme 1 (not default) is not booted. 46 $theme1 = new class extends WebtreesTheme 47 { 48 public function boot() 49 { 50 throw new \Exception('Should not get here!'); 51 } 52 }; 53 54 // Theme 2 (default) is booted. 55 $theme2 = new class ($this) extends XeneaTheme 56 { 57 private $booted = false; 58 private $test; 59 60 public function __construct($test) 61 { 62 $this->test = $test; 63 } 64 65 public function boot() 66 { 67 $this->booted = true; 68 } 69 70 public function __destruct() 71 { 72 $this->test->assertTrue($this->booted); 73 } 74 }; 75 76 $module_service = $this->createMock(ModuleService::class); 77 $module_service->method('all')->willReturn(new Collection([$theme1, $theme2])); 78 79 $request = self::createRequest(); 80 $middleware = new BootModules($module_service, $theme2); 81 $response = $middleware->process($request, $handler); 82 83 $this->assertSame(self::STATUS_OK, $response->getStatusCode()); 84 } 85} 86