14ca7e03cSGreg Roach<?php 2*3976b470SGreg Roach 34ca7e03cSGreg Roach/** 44ca7e03cSGreg Roach * webtrees: online genealogy 54ca7e03cSGreg Roach * Copyright (C) 2019 webtrees development team 64ca7e03cSGreg Roach * This program is free software: you can redistribute it and/or modify 74ca7e03cSGreg Roach * it under the terms of the GNU General Public License as published by 84ca7e03cSGreg Roach * the Free Software Foundation, either version 3 of the License, or 94ca7e03cSGreg Roach * (at your option) any later version. 104ca7e03cSGreg Roach * This program is distributed in the hope that it will be useful, 114ca7e03cSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 124ca7e03cSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 134ca7e03cSGreg Roach * GNU General Public License for more details. 144ca7e03cSGreg Roach * You should have received a copy of the GNU General Public License 154ca7e03cSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 164ca7e03cSGreg Roach */ 174ca7e03cSGreg Roachdeclare(strict_types=1); 184ca7e03cSGreg Roach 194ca7e03cSGreg Roachnamespace Fisharebest\Webtrees\Services; 204ca7e03cSGreg Roach 214ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleAnalyticsInterface; 224ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleBlockInterface; 234ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleChartInterface; 244ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleConfigInterface; 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\TestCase; 329219296aSGreg Roachuse Fisharebest\Webtrees\Tree; 33bf57b580SGreg Roachuse Illuminate\Database\Capsule\Manager as DB; 344ca7e03cSGreg Roach 354ca7e03cSGreg Roach/** 364ca7e03cSGreg Roach * Test the modules 374ca7e03cSGreg Roach * 384ca7e03cSGreg Roach * @coversNothing 394ca7e03cSGreg Roach */ 404ca7e03cSGreg Roachclass ModuleServiceTest extends TestCase 414ca7e03cSGreg Roach{ 424ca7e03cSGreg Roach protected static $uses_database = true; 434ca7e03cSGreg Roach 444ca7e03cSGreg Roach /** 454ca7e03cSGreg Roach * @covers \Fisharebest\Webtrees\Services\ModuleService::all 464ca7e03cSGreg Roach * @covers \Fisharebest\Webtrees\Services\ModuleService::coreModules 474ca7e03cSGreg Roach * @covers \Fisharebest\Webtrees\Services\ModuleService::customModules 484ca7e03cSGreg Roach * @covers \Fisharebest\Webtrees\Services\ModuleService::moduleSorter 494ca7e03cSGreg Roach * @return void 504ca7e03cSGreg Roach */ 514ca7e03cSGreg Roach public function testAll(): void 524ca7e03cSGreg Roach { 53bf57b580SGreg Roach app()->instance(Tree::class, Tree::create('name', 'title')); 549219296aSGreg Roach 554ca7e03cSGreg Roach $module_service = new ModuleService(); 564ca7e03cSGreg Roach 574ca7e03cSGreg Roach $this->assertNotEmpty($module_service->all()); 584ca7e03cSGreg Roach } 594ca7e03cSGreg Roach 604ca7e03cSGreg Roach /** 614ca7e03cSGreg Roach * @covers \Fisharebest\Webtrees\Services\ModuleService::findByComponent 624ca7e03cSGreg Roach * @covers \Fisharebest\Webtrees\Services\ModuleService::menuSorter 634ca7e03cSGreg Roach * @covers \Fisharebest\Webtrees\Services\ModuleService::sidebarSorter 644ca7e03cSGreg Roach * @covers \Fisharebest\Webtrees\Services\ModuleService::tabSorter 654ca7e03cSGreg Roach * @return void 664ca7e03cSGreg Roach */ 674ca7e03cSGreg Roach public function testFindByComponent(): void 684ca7e03cSGreg Roach { 69e5a6b4d4SGreg Roach $user_service = new UserService(); 70bf57b580SGreg Roach app()->instance(Tree::class, Tree::create('name', 'title')); 719219296aSGreg Roach 724ca7e03cSGreg Roach $module_service = new ModuleService(); 734ca7e03cSGreg Roach 744ca7e03cSGreg Roach $tree = $this->importTree('demo.ged'); 75e5a6b4d4SGreg Roach $user = $user_service->create('UserName', 'RealName', 'user@example.com', 'secret'); 764ca7e03cSGreg Roach 7787cca37cSGreg Roach $this->assertNotEmpty($module_service->findByComponent(ModuleBlockInterface::class, $tree, $user)->all()); 7887cca37cSGreg Roach $this->assertNotEmpty($module_service->findByComponent(ModuleChartInterface::class, $tree, $user)->all()); 7987cca37cSGreg Roach $this->assertNotEmpty($module_service->findByComponent(ModuleMenuInterface::class, $tree, $user)->all()); 8087cca37cSGreg Roach $this->assertNotEmpty($module_service->findByComponent(ModuleReportInterface::class, $tree, $user)->all()); 8187cca37cSGreg Roach $this->assertNotEmpty($module_service->findByComponent(ModuleSidebarInterface::class, $tree, $user)->all()); 8287cca37cSGreg Roach $this->assertNotEmpty($module_service->findByComponent(ModuleTabInterface::class, $tree, $user)->all()); 834ca7e03cSGreg Roach } 844ca7e03cSGreg Roach 854ca7e03cSGreg Roach /** 864ca7e03cSGreg Roach * @covers \Fisharebest\Webtrees\Services\ModuleService::findByInterface 874ca7e03cSGreg Roach * @return void 884ca7e03cSGreg Roach */ 894ca7e03cSGreg Roach public function testFindByInterface(): void 904ca7e03cSGreg Roach { 91bf57b580SGreg Roach app()->instance(Tree::class, Tree::create('name', 'title')); 929219296aSGreg Roach 934ca7e03cSGreg Roach $module_service = new ModuleService(); 944ca7e03cSGreg Roach 955703d1aeSGreg Roach $this->assertNotEmpty($module_service->findByInterface(ModuleAnalyticsInterface::class, true)->all()); 965703d1aeSGreg Roach $this->assertNotEmpty($module_service->findByInterface(ModuleBlockInterface::class, true)->all()); 975703d1aeSGreg Roach $this->assertNotEmpty($module_service->findByInterface(ModuleChartInterface::class, true)->all()); 985703d1aeSGreg Roach $this->assertNotEmpty($module_service->findByInterface(ModuleConfigInterface::class, true)->all()); 995703d1aeSGreg Roach $this->assertNotEmpty($module_service->findByInterface(ModuleMenuInterface::class, true)->all()); 1005703d1aeSGreg Roach $this->assertNotEmpty($module_service->findByInterface(ModuleInterface::class, true)->all()); 1015703d1aeSGreg Roach $this->assertNotEmpty($module_service->findByInterface(ModuleReportInterface::class, true)->all()); 1025703d1aeSGreg Roach $this->assertNotEmpty($module_service->findByInterface(ModuleSidebarInterface::class, true)->all()); 1035703d1aeSGreg Roach $this->assertNotEmpty($module_service->findByInterface(ModuleTabInterface::class, true)->all()); 1045703d1aeSGreg Roach $this->assertNotEmpty($module_service->findByInterface(ModuleThemeInterface::class, true)->all()); 1054ca7e03cSGreg Roach 106321a89daSGreg Roach // Search for an invalid module type 107f9237c50SGreg Roach $this->assertEmpty($module_service->findByInterface('not-a-valid-class-or-interface')->all()); 1084ca7e03cSGreg Roach } 109bf57b580SGreg Roach 110bf57b580SGreg Roach /** 111e364afe4SGreg Roach * @covers \Fisharebest\Webtrees\Services\ModuleService::otherModules 112bf57b580SGreg Roach * @return void 113bf57b580SGreg Roach */ 114e364afe4SGreg Roach public function testOtherModules(): void 115bf57b580SGreg Roach { 116bf57b580SGreg Roach app()->instance(Tree::class, Tree::create('name', 'title')); 117bf57b580SGreg Roach DB::table('module')->insert(['module_name' => 'not-a-module']); 118bf57b580SGreg Roach 119bf57b580SGreg Roach $module_service = new ModuleService(); 120bf57b580SGreg Roach 1215703d1aeSGreg Roach $this->assertSame(3, $module_service->otherModules()->count()); 122bf57b580SGreg Roach } 123bf57b580SGreg Roach 124bf57b580SGreg Roach /** 125bf57b580SGreg Roach * @covers \Fisharebest\Webtrees\Services\ModuleService::deletedModules 126bf57b580SGreg Roach * @return void 127bf57b580SGreg Roach */ 128bf57b580SGreg Roach public function testDeletedModules(): void 129bf57b580SGreg Roach { 130bf57b580SGreg Roach app()->instance(Tree::class, Tree::create('name', 'title')); 131bf57b580SGreg Roach DB::table('module')->insert(['module_name' => 'not-a-module']); 132bf57b580SGreg Roach 133bf57b580SGreg Roach $module_service = new ModuleService(); 134bf57b580SGreg Roach 135bf57b580SGreg Roach $this->assertSame(1, $module_service->deletedModules()->count()); 136bf57b580SGreg Roach $this->assertSame('not-a-module', $module_service->deletedModules()->first()); 137bf57b580SGreg Roach } 1384ca7e03cSGreg Roach} 139