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 */ 17declare(strict_types=1); 18 19namespace Fisharebest\Webtrees\Services; 20 21use Fisharebest\Webtrees\Module\ModuleAnalyticsInterface; 22use Fisharebest\Webtrees\Module\ModuleBlockInterface; 23use Fisharebest\Webtrees\Module\ModuleChartInterface; 24use Fisharebest\Webtrees\Module\ModuleConfigInterface; 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\TestCase; 32use Fisharebest\Webtrees\Tree; 33use Illuminate\Database\Capsule\Manager as DB; 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 app()->instance(Tree::class, Tree::create('name', 'title')); 54 55 $module_service = new ModuleService(); 56 57 $this->assertNotEmpty($module_service->all()); 58 } 59 60 /** 61 * @covers \Fisharebest\Webtrees\Services\ModuleService::findByComponent 62 * @covers \Fisharebest\Webtrees\Services\ModuleService::menuSorter 63 * @covers \Fisharebest\Webtrees\Services\ModuleService::sidebarSorter 64 * @covers \Fisharebest\Webtrees\Services\ModuleService::tabSorter 65 * @return void 66 */ 67 public function testFindByComponent(): void 68 { 69 $user_service = new UserService(); 70 app()->instance(Tree::class, Tree::create('name', 'title')); 71 72 $module_service = new ModuleService(); 73 74 $tree = $this->importTree('demo.ged'); 75 $user = $user_service->create('UserName', 'RealName', 'user@example.com', 'secret'); 76 77 $this->assertNotEmpty($module_service->findByComponent(ModuleBlockInterface::class, $tree, $user)->all()); 78 $this->assertNotEmpty($module_service->findByComponent(ModuleChartInterface::class, $tree, $user)->all()); 79 $this->assertNotEmpty($module_service->findByComponent(ModuleMenuInterface::class, $tree, $user)->all()); 80 $this->assertNotEmpty($module_service->findByComponent(ModuleReportInterface::class, $tree, $user)->all()); 81 $this->assertNotEmpty($module_service->findByComponent(ModuleSidebarInterface::class, $tree, $user)->all()); 82 $this->assertNotEmpty($module_service->findByComponent(ModuleTabInterface::class, $tree, $user)->all()); 83 } 84 85 /** 86 * @covers \Fisharebest\Webtrees\Services\ModuleService::findByInterface 87 * @return void 88 */ 89 public function testFindByInterface(): void 90 { 91 app()->instance(Tree::class, Tree::create('name', 'title')); 92 93 $module_service = new ModuleService(); 94 95 $this->assertNotEmpty($module_service->findByInterface(ModuleAnalyticsInterface::class, true)->all()); 96 $this->assertNotEmpty($module_service->findByInterface(ModuleBlockInterface::class, true)->all()); 97 $this->assertNotEmpty($module_service->findByInterface(ModuleChartInterface::class, true)->all()); 98 $this->assertNotEmpty($module_service->findByInterface(ModuleConfigInterface::class, true)->all()); 99 $this->assertNotEmpty($module_service->findByInterface(ModuleMenuInterface::class, true)->all()); 100 $this->assertNotEmpty($module_service->findByInterface(ModuleInterface::class, true)->all()); 101 $this->assertNotEmpty($module_service->findByInterface(ModuleReportInterface::class, true)->all()); 102 $this->assertNotEmpty($module_service->findByInterface(ModuleSidebarInterface::class, true)->all()); 103 $this->assertNotEmpty($module_service->findByInterface(ModuleTabInterface::class, true)->all()); 104 $this->assertNotEmpty($module_service->findByInterface(ModuleThemeInterface::class, true)->all()); 105 106 // Search for an invalid module type 107 $this->assertEmpty($module_service->findByInterface('not-a-valid-class-or-interface')->all()); 108 } 109 110 /** 111 * @covers \Fisharebest\Webtrees\Services\ModuleService::otherModules 112 * @return void 113 */ 114 public function testOtherModules(): void 115 { 116 app()->instance(Tree::class, Tree::create('name', 'title')); 117 DB::table('module')->insert(['module_name' => 'not-a-module']); 118 119 $module_service = new ModuleService(); 120 121 $this->assertSame(3, $module_service->otherModules()->count()); 122 } 123 124 /** 125 * @covers \Fisharebest\Webtrees\Services\ModuleService::deletedModules 126 * @return void 127 */ 128 public function testDeletedModules(): void 129 { 130 app()->instance(Tree::class, Tree::create('name', 'title')); 131 DB::table('module')->insert(['module_name' => 'not-a-module']); 132 133 $module_service = new ModuleService(); 134 135 $this->assertSame(1, $module_service->deletedModules()->count()); 136 $this->assertSame('not-a-module', $module_service->deletedModules()->first()); 137 } 138} 139