1<?php 2 3/** 4 * webtrees: online genealogy 5 * Copyright (C) 2019 webtrees development team 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18declare(strict_types=1); 19 20namespace Fisharebest\Webtrees\Services; 21 22use Fisharebest\Webtrees\Module\ModuleAnalyticsInterface; 23use Fisharebest\Webtrees\Module\ModuleBlockInterface; 24use Fisharebest\Webtrees\Module\ModuleChartInterface; 25use Fisharebest\Webtrees\Module\ModuleConfigInterface; 26use Fisharebest\Webtrees\Module\ModuleDataFixInterface; 27use Fisharebest\Webtrees\Module\ModuleInterface; 28use Fisharebest\Webtrees\Module\ModuleMenuInterface; 29use Fisharebest\Webtrees\Module\ModuleReportInterface; 30use Fisharebest\Webtrees\Module\ModuleSidebarInterface; 31use Fisharebest\Webtrees\Module\ModuleTabInterface; 32use Fisharebest\Webtrees\Module\ModuleThemeInterface; 33use Fisharebest\Webtrees\TestCase; 34use Illuminate\Database\Capsule\Manager as DB; 35 36/** 37 * Test the modules 38 * 39 * @coversNothing 40 */ 41class ModuleServiceTest extends TestCase 42{ 43 protected static $uses_database = true; 44 45 /** 46 * @covers \Fisharebest\Webtrees\Services\ModuleService::all 47 * @covers \Fisharebest\Webtrees\Services\ModuleService::coreModules 48 * @covers \Fisharebest\Webtrees\Services\ModuleService::customModules 49 * @covers \Fisharebest\Webtrees\Services\ModuleService::moduleSorter 50 * @return void 51 */ 52 public function testAll(): void 53 { 54 $module_service = new ModuleService(); 55 56 $this->assertNotEmpty($module_service->all()); 57 } 58 59 /** 60 * @covers \Fisharebest\Webtrees\Services\ModuleService::findByComponent 61 * @covers \Fisharebest\Webtrees\Services\ModuleService::menuSorter 62 * @covers \Fisharebest\Webtrees\Services\ModuleService::sidebarSorter 63 * @covers \Fisharebest\Webtrees\Services\ModuleService::tabSorter 64 * @return void 65 */ 66 public function testFindByComponent(): void 67 { 68 $user_service = new UserService(); 69 $module_service = new ModuleService(); 70 71 $tree = $this->importTree('demo.ged'); 72 $user = $user_service->create('UserName', 'RealName', 'user@example.com', 'secret'); 73 74 $this->assertNotEmpty($module_service->findByComponent(ModuleBlockInterface::class, $tree, $user)->all()); 75 $this->assertNotEmpty($module_service->findByComponent(ModuleChartInterface::class, $tree, $user)->all()); 76 $this->assertNotEmpty($module_service->findByComponent(ModuleMenuInterface::class, $tree, $user)->all()); 77 $this->assertNotEmpty($module_service->findByComponent(ModuleReportInterface::class, $tree, $user)->all()); 78 $this->assertNotEmpty($module_service->findByComponent(ModuleSidebarInterface::class, $tree, $user)->all()); 79 $this->assertNotEmpty($module_service->findByComponent(ModuleTabInterface::class, $tree, $user)->all()); 80 } 81 82 /** 83 * @covers \Fisharebest\Webtrees\Services\ModuleService::findByInterface 84 * @return void 85 */ 86 public function testFindByInterface(): void 87 { 88 $module_service = new ModuleService(); 89 90 $this->assertNotEmpty($module_service->findByInterface(ModuleAnalyticsInterface::class, true)->all()); 91 $this->assertNotEmpty($module_service->findByInterface(ModuleBlockInterface::class, true)->all()); 92 $this->assertNotEmpty($module_service->findByInterface(ModuleChartInterface::class, true)->all()); 93 $this->assertNotEmpty($module_service->findByInterface(ModuleConfigInterface::class, true)->all()); 94 $this->assertNotEmpty($module_service->findByInterface(ModuleDataFixInterface::class, true)->all()); 95 $this->assertNotEmpty($module_service->findByInterface(ModuleMenuInterface::class, true)->all()); 96 $this->assertNotEmpty($module_service->findByInterface(ModuleInterface::class, true)->all()); 97 $this->assertNotEmpty($module_service->findByInterface(ModuleReportInterface::class, true)->all()); 98 $this->assertNotEmpty($module_service->findByInterface(ModuleSidebarInterface::class, true)->all()); 99 $this->assertNotEmpty($module_service->findByInterface(ModuleTabInterface::class, true)->all()); 100 $this->assertNotEmpty($module_service->findByInterface(ModuleThemeInterface::class, true)->all()); 101 102 // Search for an invalid module type 103 $this->assertEmpty($module_service->findByInterface('not-a-valid-class-or-interface')->all()); 104 } 105 106 /** 107 * @covers \Fisharebest\Webtrees\Services\ModuleService::otherModules 108 * @return void 109 */ 110 public function testOtherModules(): void 111 { 112 DB::table('module')->insert(['module_name' => 'not-a-module']); 113 114 $module_service = new ModuleService(); 115 116 $this->assertSame(3, $module_service->otherModules()->count()); 117 } 118 119 /** 120 * @covers \Fisharebest\Webtrees\Services\ModuleService::deletedModules 121 * @return void 122 */ 123 public function testDeletedModules(): void 124 { 125 DB::table('module')->insert(['module_name' => 'not-a-module']); 126 127 $module_service = new ModuleService(); 128 129 $this->assertSame(1, $module_service->deletedModules()->count()); 130 $this->assertSame('not-a-module', $module_service->deletedModules()->first()); 131 } 132} 133