1<?php 2/** 3 * webtrees: online genealogy 4 * Copyright (C) 2019 webtrees development team 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 */ 16declare(strict_types=1); 17 18use Fisharebest\Webtrees\GuestUser; 19use Fisharebest\Webtrees\Http\RequestHandlers\ModuleAction; 20use Fisharebest\Webtrees\Services\ModuleService; 21use Fisharebest\Webtrees\TestCase; 22use Fisharebest\Webtrees\Tree; 23 24/** 25 * @covers \Fisharebest\Webtrees\Http\RequestHandlers\ModuleAction 26 */ 27class ModuleActionTest extends TestCase 28{ 29 protected static $uses_database = true; 30 31 /** 32 * @return void 33 */ 34 public function testModuleAction(): void 35 { 36 $tree = Tree::create('tree', 'tree'); 37 app()->instance(Tree::class, $tree); 38 $user = new GuestUser(); 39 $module_service = new ModuleService(); 40 $handler = new ModuleAction($module_service, $user); 41 $request = self::createRequest('GET', ['route' => 'module', 'module' => 'faq', 'action' => 'Show', 'ged' => $tree->name()]); 42 $response = $handler->handle($request); 43 44 $this->assertSame(self::STATUS_OK, $response->getStatusCode()); 45 } 46 47 /** 48 * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException 49 * @expectedExceptionMessage Method getFishAction() not found in faq 50 * @return void 51 */ 52 public function testNonExistingAction(): void 53 { 54 $user = new GuestUser(); 55 $module_service = new ModuleService(); 56 $handler = new ModuleAction($module_service, $user); 57 $request = self::createRequest('GET', ['route' => 'module', 'module' => 'faq', 'action' => 'Fish']); 58 $handler->handle($request); 59 } 60 61 /** 62 * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException 63 * @expectedExceptionMessage Module fish does not exist 64 * @return void 65 */ 66 public function testNonExistingModule(): void 67 { 68 $user = new GuestUser(); 69 $module_service = new ModuleService(); 70 $handler = new ModuleAction($module_service, $user); 71 $request = self::createRequest('GET', ['route' => 'module', 'module' => 'fish', 'action' => 'Show']); 72 $response = $handler->handle($request); 73 74 $this->assertSame(self::STATUS_OK, $response->getStatusCode()); 75 } 76 77 /** 78 * @expectedException \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException 79 * @expectedExceptionMessage Admin only action 80 * @return void 81 */ 82 public function testAdminAction(): void 83 { 84 $tree = Tree::create('tree', 'tree'); 85 app()->instance(Tree::class, $tree); 86 $user = new GuestUser(); 87 $module_service = new ModuleService(); 88 $handler = new ModuleAction($module_service, $user); 89 $request = self::createRequest('GET', ['route' => 'module', 'module' => 'faq', 'action' => 'Admin', 'ged' => $tree->name()]); 90 $handler->handle($request); 91 } 92} 93