xref: /webtrees/tests/app/Services/ModuleServiceTest.php (revision a34b54dc84837d4fd1e3b55dfaf41e1761acb658)
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\Services;
19
20use Fisharebest\Webtrees\Module\ModuleAnalyticsInterface;
21use Fisharebest\Webtrees\Module\ModuleBlockInterface;
22use Fisharebest\Webtrees\Module\ModuleChartInterface;
23use Fisharebest\Webtrees\Module\ModuleConfigInterface;
24use Fisharebest\Webtrees\Module\ModuleHistoricEventsInterface;
25use Fisharebest\Webtrees\Module\ModuleInterface;
26use Fisharebest\Webtrees\Module\ModuleMenuInterface;
27use Fisharebest\Webtrees\Module\ModuleReportInterface;
28use Fisharebest\Webtrees\Module\ModuleSidebarInterface;
29use Fisharebest\Webtrees\Module\ModuleTabInterface;
30use Fisharebest\Webtrees\Module\ModuleThemeInterface;
31use Fisharebest\Webtrees\Module\TreesMenuModule;
32use Fisharebest\Webtrees\TestCase;
33use Fisharebest\Webtrees\Tree;
34
35/**
36 * Test the modules
37 *
38 * @coversNothing
39 */
40class ModuleServiceTest extends TestCase
41{
42    protected static $uses_database = true;
43
44    /**
45     * @covers \Fisharebest\Webtrees\Services\ModuleService::all
46     * @covers \Fisharebest\Webtrees\Services\ModuleService::coreModules
47     * @covers \Fisharebest\Webtrees\Services\ModuleService::customModules
48     * @covers \Fisharebest\Webtrees\Services\ModuleService::moduleSorter
49     * @return void
50     */
51    public function testAll(): void
52    {
53        $tree = Tree::create('name', 'title');
54        app()->instance(Tree::class, $tree);
55
56        $module_service = new ModuleService();
57
58        $this->assertNotEmpty($module_service->all());
59    }
60
61    /**
62     * @covers \Fisharebest\Webtrees\Services\ModuleService::findByComponent
63     * @covers \Fisharebest\Webtrees\Services\ModuleService::menuSorter
64     * @covers \Fisharebest\Webtrees\Services\ModuleService::sidebarSorter
65     * @covers \Fisharebest\Webtrees\Services\ModuleService::tabSorter
66     * @return void
67     */
68    public function testFindByComponent(): void
69    {
70        $user_service = new UserService();
71        $tree         = Tree::create('name', 'title');
72        app()->instance(Tree::class, $tree);
73
74        $module_service = new ModuleService();
75
76        $tree = $this->importTree('demo.ged');
77        $user = $user_service->create('UserName', 'RealName', 'user@example.com', 'secret');
78
79        $this->assertNotEmpty($module_service->findByComponent('block', $tree, $user)->all());
80        $this->assertNotEmpty($module_service->findByComponent('chart', $tree, $user)->all());
81        $this->assertNotEmpty($module_service->findByComponent('menu', $tree, $user)->all());
82        $this->assertNotEmpty($module_service->findByComponent('report', $tree, $user)->all());
83        $this->assertNotEmpty($module_service->findByComponent('sidebar', $tree, $user)->all());
84        $this->assertNotEmpty($module_service->findByComponent('tab', $tree, $user)->all());
85    }
86
87    /**
88     * @covers \Fisharebest\Webtrees\Services\ModuleService::findByInterface
89     * @return void
90     */
91    public function testFindByInterface(): void
92    {
93        $tree = Tree::create('name', 'title');
94        app()->instance(Tree::class, $tree);
95
96        $module_service = new ModuleService();
97
98        $this->assertNotEmpty($module_service->findByInterface(ModuleAnalyticsInterface::class)->all());
99        $this->assertNotEmpty($module_service->findByInterface(ModuleBlockInterface::class)->all());
100        $this->assertNotEmpty($module_service->findByInterface(ModuleChartInterface::class)->all());
101        $this->assertNotEmpty($module_service->findByInterface(ModuleConfigInterface::class)->all());
102        $this->assertNotEmpty($module_service->findByInterface(ModuleMenuInterface::class)->all());
103        $this->assertNotEmpty($module_service->findByInterface(ModuleInterface::class)->all());
104        $this->assertNotEmpty($module_service->findByInterface(ModuleReportInterface::class)->all());
105        $this->assertNotEmpty($module_service->findByInterface(ModuleSidebarInterface::class)->all());
106        $this->assertNotEmpty($module_service->findByInterface(ModuleTabInterface::class)->all());
107        $this->assertNotEmpty($module_service->findByInterface(ModuleThemeInterface::class)->all());
108
109        // THe core modules do not contain any of these.
110        $this->assertEmpty($module_service->findByInterface(ModuleHistoricEventsInterface::class)->all());
111    }
112
113    /**
114     * @covers \Fisharebest\Webtrees\Services\ModuleService::findByClass
115     * @return void
116     */
117    public function testFindByClass(): void
118    {
119        $tree = Tree::create('name', 'title');
120        app()->instance(Tree::class, $tree);
121
122        $module_service = new ModuleService();
123
124        $this->assertNull($module_service->findByClass('not-a-valid-class-name'));
125        $this->assertInstanceOf(TreesMenuModule::class, $module_service->findByClass(TreesMenuModule::class));
126    }
127
128    /**
129     * @covers \Fisharebest\Webtrees\Services\ModuleService::findByName
130     * @return void
131     */
132    public function testFindByName(): void
133    {
134        $tree = Tree::create('name', 'title');
135        app()->instance(Tree::class, $tree);
136
137        $module_service = new ModuleService();
138
139        $this->assertNull($module_service->findByName('not-a-valid-module-name'));
140        $this->assertInstanceOf(TreesMenuModule::class, $module_service->findByName('trees-menu'));
141    }
142}
143