xref: /webtrees/tests/app/Http/RequestHandlers/ModuleActionTest.php (revision 6b1381a306f9b3ddbe167a71b6a607d5ab7a609d)
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
18namespace Fisharebest\Webtrees\Http\RequestHandlers;
19
20use Fisharebest\Webtrees\GuestUser;
21use Fisharebest\Webtrees\Services\ModuleService;
22use Fisharebest\Webtrees\TestCase;
23use Fisharebest\Webtrees\Tree;
24
25/**
26 * @covers \Fisharebest\Webtrees\Http\RequestHandlers\ModuleAction
27 */
28class ModuleActionTest extends TestCase
29{
30    protected static $uses_database = true;
31
32    /**
33     * @return void
34     */
35    public function testModuleAction(): void
36    {
37        $tree = Tree::create('tree', 'tree');
38        app()->instance(Tree::class, $tree);
39        $user           = new GuestUser();
40        $module_service = new ModuleService();
41        $handler        = new ModuleAction($module_service, $user);
42        $request        = self::createRequest('GET', ['route' => 'module', 'module' => 'faq', 'action' => 'Show', 'ged' => $tree->name()]);
43        $response       = $handler->handle($request);
44
45        $this->assertSame(self::STATUS_OK, $response->getStatusCode());
46    }
47
48    /**
49     * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
50     * @expectedExceptionMessage Method getFishAction() not found in faq
51     * @return void
52     */
53    public function testNonExistingAction(): void
54    {
55        $user           = new GuestUser();
56        $module_service = new ModuleService();
57        $handler        = new ModuleAction($module_service, $user);
58        $request        = self::createRequest('GET', ['route' => 'module', 'module' => 'faq', 'action' => 'Fish']);
59        $handler->handle($request);
60    }
61
62    /**
63     * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
64     * @expectedExceptionMessage Module fish does not exist
65     * @return void
66     */
67    public function testNonExistingModule(): void
68    {
69        $user           = new GuestUser();
70        $module_service = new ModuleService();
71        $handler        = new ModuleAction($module_service, $user);
72        $request        = self::createRequest('GET', ['route' => 'module', 'module' => 'fish', 'action' => 'Show']);
73        $response       = $handler->handle($request);
74
75        $this->assertSame(self::STATUS_OK, $response->getStatusCode());
76    }
77
78    /**
79     * @expectedException \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
80     * @expectedExceptionMessage Admin only action
81     * @return void
82     */
83    public function testAdminAction(): void
84    {
85        $tree = Tree::create('tree', 'tree');
86        app()->instance(Tree::class, $tree);
87        $user           = new GuestUser();
88        $module_service = new ModuleService();
89        $handler        = new ModuleAction($module_service, $user);
90        $request        = self::createRequest('GET', ['route' => 'module', 'module' => 'faq', 'action' => 'Admin', 'ged' => $tree->name()]);
91        $handler->handle($request);
92    }
93}
94