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\User; 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 $module_service = new ModuleService(); 54 55 $this->assertNotEmpty($module_service->all()); 56 } 57 58 /** 59 * @covers \Fisharebest\Webtrees\Services\ModuleService::findByComponent 60 * @covers \Fisharebest\Webtrees\Services\ModuleService::menuSorter 61 * @covers \Fisharebest\Webtrees\Services\ModuleService::sidebarSorter 62 * @covers \Fisharebest\Webtrees\Services\ModuleService::tabSorter 63 * @return void 64 */ 65 public function testFindByComponent(): void 66 { 67 $module_service = new ModuleService(); 68 69 $tree = $this->importTree('demo.ged'); 70 $user = User::create('UserName', 'RealName', 'user@example.com', 'secret'); 71 72 $this->assertNotEmpty($module_service->findByComponent('block', $tree, $user)->all()); 73 $this->assertNotEmpty($module_service->findByComponent('chart', $tree, $user)->all()); 74 $this->assertNotEmpty($module_service->findByComponent('menu', $tree, $user)->all()); 75 $this->assertNotEmpty($module_service->findByComponent('report', $tree, $user)->all()); 76 $this->assertNotEmpty($module_service->findByComponent('sidebar', $tree, $user)->all()); 77 $this->assertNotEmpty($module_service->findByComponent('tab', $tree, $user)->all()); 78 } 79 80 /** 81 * @covers \Fisharebest\Webtrees\Services\ModuleService::findByInterface 82 * @return void 83 */ 84 public function testFindByInterface(): void 85 { 86 $module_service = new ModuleService(); 87 88 $this->assertNotEmpty($module_service->findByInterface(ModuleAnalyticsInterface::class)->all()); 89 $this->assertNotEmpty($module_service->findByInterface(ModuleBlockInterface::class)->all()); 90 $this->assertNotEmpty($module_service->findByInterface(ModuleChartInterface::class)->all()); 91 $this->assertNotEmpty($module_service->findByInterface(ModuleConfigInterface::class)->all()); 92 $this->assertNotEmpty($module_service->findByInterface(ModuleMenuInterface::class)->all()); 93 $this->assertNotEmpty($module_service->findByInterface(ModuleInterface::class)->all()); 94 $this->assertNotEmpty($module_service->findByInterface(ModuleReportInterface::class)->all()); 95 $this->assertNotEmpty($module_service->findByInterface(ModuleSidebarInterface::class)->all()); 96 $this->assertNotEmpty($module_service->findByInterface(ModuleTabInterface::class)->all()); 97 $this->assertNotEmpty($module_service->findByInterface(ModuleThemeInterface::class)->all()); 98 99 // THe core modules do not contain any of these. 100 $this->assertEmpty($module_service->findByInterface(ModuleHistoricEventsInterface::class)->all()); 101 } 102 103 /** 104 * @covers \Fisharebest\Webtrees\Services\ModuleService::findByClass 105 * @return void 106 */ 107 public function testFindByClass(): void 108 { 109 $module_service = new ModuleService(); 110 111 $this->assertNull($module_service->findByClass('not-a-valid-class-name')); 112 $this->assertInstanceOf(TreesMenuModule::class, $module_service->findByClass(TreesMenuModule::class)); 113 } 114 115 /** 116 * @covers \Fisharebest\Webtrees\Services\ModuleService::findByName 117 * @return void 118 */ 119 public function testFindByName(): void 120 { 121 $module_service = new ModuleService(); 122 123 $this->assertNull($module_service->findByName('not-a-valid-module-name')); 124 $this->assertInstanceOf(TreesMenuModule::class, $module_service->findByName('trees-menu')); 125 } 126} 127