14ca7e03cSGreg Roach<?php 24ca7e03cSGreg Roach/** 34ca7e03cSGreg Roach * webtrees: online genealogy 44ca7e03cSGreg Roach * Copyright (C) 2019 webtrees development team 54ca7e03cSGreg Roach * This program is free software: you can redistribute it and/or modify 64ca7e03cSGreg Roach * it under the terms of the GNU General Public License as published by 74ca7e03cSGreg Roach * the Free Software Foundation, either version 3 of the License, or 84ca7e03cSGreg Roach * (at your option) any later version. 94ca7e03cSGreg Roach * This program is distributed in the hope that it will be useful, 104ca7e03cSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 114ca7e03cSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 124ca7e03cSGreg Roach * GNU General Public License for more details. 134ca7e03cSGreg Roach * You should have received a copy of the GNU General Public License 144ca7e03cSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 154ca7e03cSGreg Roach */ 164ca7e03cSGreg Roachdeclare(strict_types=1); 174ca7e03cSGreg Roach 184ca7e03cSGreg Roachnamespace Fisharebest\Webtrees\Services; 194ca7e03cSGreg Roach 204ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleAnalyticsInterface; 214ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleBlockInterface; 224ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleChartInterface; 234ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleConfigInterface; 244ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleHistoricEventsInterface; 254ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleInterface; 264ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleMenuInterface; 274ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleReportInterface; 284ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleSidebarInterface; 294ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleTabInterface; 304ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleThemeInterface; 314ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\TreesMenuModule; 324ca7e03cSGreg Roachuse Fisharebest\Webtrees\TestCase; 33*9219296aSGreg Roachuse Fisharebest\Webtrees\Tree; 344ca7e03cSGreg Roachuse Fisharebest\Webtrees\User; 354ca7e03cSGreg Roach 364ca7e03cSGreg Roach/** 374ca7e03cSGreg Roach * Test the modules 384ca7e03cSGreg Roach * 394ca7e03cSGreg Roach * @coversNothing 404ca7e03cSGreg Roach */ 414ca7e03cSGreg Roachclass ModuleServiceTest extends TestCase 424ca7e03cSGreg Roach{ 434ca7e03cSGreg Roach protected static $uses_database = true; 444ca7e03cSGreg Roach 454ca7e03cSGreg Roach /** 464ca7e03cSGreg Roach * @covers \Fisharebest\Webtrees\Services\ModuleService::all 474ca7e03cSGreg Roach * @covers \Fisharebest\Webtrees\Services\ModuleService::coreModules 484ca7e03cSGreg Roach * @covers \Fisharebest\Webtrees\Services\ModuleService::customModules 494ca7e03cSGreg Roach * @covers \Fisharebest\Webtrees\Services\ModuleService::moduleSorter 504ca7e03cSGreg Roach * @return void 514ca7e03cSGreg Roach */ 524ca7e03cSGreg Roach public function testAll(): void 534ca7e03cSGreg Roach { 54*9219296aSGreg Roach $tree = Tree::create('name', 'title'); 55*9219296aSGreg Roach app()->instance(Tree::class, $tree); 56*9219296aSGreg Roach 574ca7e03cSGreg Roach $module_service = new ModuleService(); 584ca7e03cSGreg Roach 594ca7e03cSGreg Roach $this->assertNotEmpty($module_service->all()); 604ca7e03cSGreg Roach } 614ca7e03cSGreg Roach 624ca7e03cSGreg Roach /** 634ca7e03cSGreg Roach * @covers \Fisharebest\Webtrees\Services\ModuleService::findByComponent 644ca7e03cSGreg Roach * @covers \Fisharebest\Webtrees\Services\ModuleService::menuSorter 654ca7e03cSGreg Roach * @covers \Fisharebest\Webtrees\Services\ModuleService::sidebarSorter 664ca7e03cSGreg Roach * @covers \Fisharebest\Webtrees\Services\ModuleService::tabSorter 674ca7e03cSGreg Roach * @return void 684ca7e03cSGreg Roach */ 694ca7e03cSGreg Roach public function testFindByComponent(): void 704ca7e03cSGreg Roach { 71*9219296aSGreg Roach $tree = Tree::create('name', 'title'); 72*9219296aSGreg Roach app()->instance(Tree::class, $tree); 73*9219296aSGreg Roach 744ca7e03cSGreg Roach $module_service = new ModuleService(); 754ca7e03cSGreg Roach 764ca7e03cSGreg Roach $tree = $this->importTree('demo.ged'); 774ca7e03cSGreg Roach $user = User::create('UserName', 'RealName', 'user@example.com', 'secret'); 784ca7e03cSGreg Roach 794ca7e03cSGreg Roach $this->assertNotEmpty($module_service->findByComponent('block', $tree, $user)->all()); 804ca7e03cSGreg Roach $this->assertNotEmpty($module_service->findByComponent('chart', $tree, $user)->all()); 814ca7e03cSGreg Roach $this->assertNotEmpty($module_service->findByComponent('menu', $tree, $user)->all()); 824ca7e03cSGreg Roach $this->assertNotEmpty($module_service->findByComponent('report', $tree, $user)->all()); 834ca7e03cSGreg Roach $this->assertNotEmpty($module_service->findByComponent('sidebar', $tree, $user)->all()); 844ca7e03cSGreg Roach $this->assertNotEmpty($module_service->findByComponent('tab', $tree, $user)->all()); 854ca7e03cSGreg Roach } 864ca7e03cSGreg Roach 874ca7e03cSGreg Roach /** 884ca7e03cSGreg Roach * @covers \Fisharebest\Webtrees\Services\ModuleService::findByInterface 894ca7e03cSGreg Roach * @return void 904ca7e03cSGreg Roach */ 914ca7e03cSGreg Roach public function testFindByInterface(): void 924ca7e03cSGreg Roach { 93*9219296aSGreg Roach $tree = Tree::create('name', 'title'); 94*9219296aSGreg Roach app()->instance(Tree::class, $tree); 95*9219296aSGreg Roach 964ca7e03cSGreg Roach $module_service = new ModuleService(); 974ca7e03cSGreg Roach 984ca7e03cSGreg Roach $this->assertNotEmpty($module_service->findByInterface(ModuleAnalyticsInterface::class)->all()); 994ca7e03cSGreg Roach $this->assertNotEmpty($module_service->findByInterface(ModuleBlockInterface::class)->all()); 1004ca7e03cSGreg Roach $this->assertNotEmpty($module_service->findByInterface(ModuleChartInterface::class)->all()); 1014ca7e03cSGreg Roach $this->assertNotEmpty($module_service->findByInterface(ModuleConfigInterface::class)->all()); 1024ca7e03cSGreg Roach $this->assertNotEmpty($module_service->findByInterface(ModuleMenuInterface::class)->all()); 1034ca7e03cSGreg Roach $this->assertNotEmpty($module_service->findByInterface(ModuleInterface::class)->all()); 1044ca7e03cSGreg Roach $this->assertNotEmpty($module_service->findByInterface(ModuleReportInterface::class)->all()); 1054ca7e03cSGreg Roach $this->assertNotEmpty($module_service->findByInterface(ModuleSidebarInterface::class)->all()); 1064ca7e03cSGreg Roach $this->assertNotEmpty($module_service->findByInterface(ModuleTabInterface::class)->all()); 1074ca7e03cSGreg Roach $this->assertNotEmpty($module_service->findByInterface(ModuleThemeInterface::class)->all()); 1084ca7e03cSGreg Roach 1094ca7e03cSGreg Roach // THe core modules do not contain any of these. 1104ca7e03cSGreg Roach $this->assertEmpty($module_service->findByInterface(ModuleHistoricEventsInterface::class)->all()); 1114ca7e03cSGreg Roach } 1124ca7e03cSGreg Roach 1134ca7e03cSGreg Roach /** 1144ca7e03cSGreg Roach * @covers \Fisharebest\Webtrees\Services\ModuleService::findByClass 1154ca7e03cSGreg Roach * @return void 1164ca7e03cSGreg Roach */ 1174ca7e03cSGreg Roach public function testFindByClass(): void 1184ca7e03cSGreg Roach { 119*9219296aSGreg Roach $tree = Tree::create('name', 'title'); 120*9219296aSGreg Roach app()->instance(Tree::class, $tree); 121*9219296aSGreg Roach 1224ca7e03cSGreg Roach $module_service = new ModuleService(); 1234ca7e03cSGreg Roach 1244ca7e03cSGreg Roach $this->assertNull($module_service->findByClass('not-a-valid-class-name')); 1254ca7e03cSGreg Roach $this->assertInstanceOf(TreesMenuModule::class, $module_service->findByClass(TreesMenuModule::class)); 1264ca7e03cSGreg Roach } 1274ca7e03cSGreg Roach 1284ca7e03cSGreg Roach /** 1294ca7e03cSGreg Roach * @covers \Fisharebest\Webtrees\Services\ModuleService::findByName 1304ca7e03cSGreg Roach * @return void 1314ca7e03cSGreg Roach */ 1324ca7e03cSGreg Roach public function testFindByName(): void 1334ca7e03cSGreg Roach { 134*9219296aSGreg Roach $tree = Tree::create('name', 'title'); 135*9219296aSGreg Roach app()->instance(Tree::class, $tree); 136*9219296aSGreg Roach 1374ca7e03cSGreg Roach $module_service = new ModuleService(); 1384ca7e03cSGreg Roach 1394ca7e03cSGreg Roach $this->assertNull($module_service->findByName('not-a-valid-module-name')); 1404ca7e03cSGreg Roach $this->assertInstanceOf(TreesMenuModule::class, $module_service->findByName('trees-menu')); 1414ca7e03cSGreg Roach } 1424ca7e03cSGreg Roach} 143