14ca7e03cSGreg Roach<?php 23976b470SGreg Roach 34ca7e03cSGreg Roach/** 44ca7e03cSGreg Roach * webtrees: online genealogy 5d11be702SGreg Roach * Copyright (C) 2023 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 1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 164ca7e03cSGreg Roach */ 17fcfa147eSGreg Roach 184ca7e03cSGreg Roachdeclare(strict_types=1); 194ca7e03cSGreg Roach 204ca7e03cSGreg Roachnamespace Fisharebest\Webtrees\Services; 214ca7e03cSGreg Roach 226f4ec3caSGreg Roachuse Fisharebest\Webtrees\DB; 234ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleAnalyticsInterface; 244ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleBlockInterface; 254ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleChartInterface; 264ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleConfigInterface; 2759500b5bSGreg Roachuse Fisharebest\Webtrees\Module\ModuleCustomInterface; 28ce42304aSGreg Roachuse Fisharebest\Webtrees\Module\ModuleDataFixInterface; 294ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleInterface; 304ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleMenuInterface; 314ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleReportInterface; 324ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleSidebarInterface; 334ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleTabInterface; 344ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleThemeInterface; 354ca7e03cSGreg Roachuse Fisharebest\Webtrees\TestCase; 36202c018bSGreg Roachuse PHPUnit\Framework\Attributes\CoversClass; 374ca7e03cSGreg Roach 38202c018bSGreg Roach#[CoversClass(ModuleService::class)] 394ca7e03cSGreg Roachclass ModuleServiceTest extends TestCase 404ca7e03cSGreg Roach{ 41cd94ca66SGreg Roach protected static bool $uses_database = true; 424ca7e03cSGreg Roach 434ca7e03cSGreg Roach public function testAll(): void 444ca7e03cSGreg Roach { 454ca7e03cSGreg Roach $module_service = new ModuleService(); 464ca7e03cSGreg Roach 4758a588c6SGreg Roach self::assertNotEmpty($module_service->all()->all()); 484ca7e03cSGreg Roach } 494ca7e03cSGreg Roach 504ca7e03cSGreg Roach public function testFindByComponent(): void 514ca7e03cSGreg Roach { 52e5a6b4d4SGreg Roach $user_service = new UserService(); 534ca7e03cSGreg Roach $module_service = new ModuleService(); 544ca7e03cSGreg Roach 554ca7e03cSGreg Roach $tree = $this->importTree('demo.ged'); 56e5a6b4d4SGreg Roach $user = $user_service->create('UserName', 'RealName', 'user@example.com', 'secret'); 574ca7e03cSGreg Roach 585e933c21SGreg Roach self::assertNotEmpty($module_service->findByComponent(ModuleBlockInterface::class, $tree, $user)->all()); 595e933c21SGreg Roach self::assertNotEmpty($module_service->findByComponent(ModuleChartInterface::class, $tree, $user)->all()); 605e933c21SGreg Roach self::assertNotEmpty($module_service->findByComponent(ModuleMenuInterface::class, $tree, $user)->all()); 615e933c21SGreg Roach self::assertNotEmpty($module_service->findByComponent(ModuleReportInterface::class, $tree, $user)->all()); 625e933c21SGreg Roach self::assertNotEmpty($module_service->findByComponent(ModuleSidebarInterface::class, $tree, $user)->all()); 635e933c21SGreg Roach self::assertNotEmpty($module_service->findByComponent(ModuleTabInterface::class, $tree, $user)->all()); 644ca7e03cSGreg Roach } 654ca7e03cSGreg Roach 664ca7e03cSGreg Roach public function testFindByInterface(): void 674ca7e03cSGreg Roach { 684ca7e03cSGreg Roach $module_service = new ModuleService(); 694ca7e03cSGreg Roach 705e933c21SGreg Roach self::assertNotEmpty($module_service->findByInterface(ModuleAnalyticsInterface::class, true)->all()); 715e933c21SGreg Roach self::assertNotEmpty($module_service->findByInterface(ModuleBlockInterface::class, true)->all()); 725e933c21SGreg Roach self::assertNotEmpty($module_service->findByInterface(ModuleChartInterface::class, true)->all()); 735e933c21SGreg Roach self::assertNotEmpty($module_service->findByInterface(ModuleConfigInterface::class, true)->all()); 745e933c21SGreg Roach self::assertNotEmpty($module_service->findByInterface(ModuleDataFixInterface::class, true)->all()); 755e933c21SGreg Roach self::assertNotEmpty($module_service->findByInterface(ModuleMenuInterface::class, true)->all()); 765e933c21SGreg Roach self::assertNotEmpty($module_service->findByInterface(ModuleInterface::class, true)->all()); 775e933c21SGreg Roach self::assertNotEmpty($module_service->findByInterface(ModuleReportInterface::class, true)->all()); 785e933c21SGreg Roach self::assertNotEmpty($module_service->findByInterface(ModuleSidebarInterface::class, true)->all()); 795e933c21SGreg Roach self::assertNotEmpty($module_service->findByInterface(ModuleTabInterface::class, true)->all()); 805e933c21SGreg Roach self::assertNotEmpty($module_service->findByInterface(ModuleThemeInterface::class, true)->all()); 814ca7e03cSGreg Roach 82321a89daSGreg Roach // Search for an invalid module type 835e933c21SGreg Roach self::assertEmpty($module_service->findByInterface('not-a-valid-class-or-interface')->all()); 844ca7e03cSGreg Roach } 85bf57b580SGreg Roach 86e364afe4SGreg Roach public function testOtherModules(): void 87bf57b580SGreg Roach { 88bf57b580SGreg Roach DB::table('module')->insert(['module_name' => 'not-a-module']); 89bf57b580SGreg Roach 90bf57b580SGreg Roach $module_service = new ModuleService(); 91bf57b580SGreg Roach 9259500b5bSGreg Roach // Ignore any custom modules that happen to be installed in the development environment. 9359500b5bSGreg Roach $modules = $module_service->otherModules() 9459500b5bSGreg Roach ->filter(fn (ModuleInterface $module): bool => !$module instanceof ModuleCustomInterface); 9559500b5bSGreg Roach 96*a6d49169SGreg Roach self::assertCount(4, $modules); 97bf57b580SGreg Roach } 98bf57b580SGreg Roach 99bf57b580SGreg Roach public function testDeletedModules(): void 100bf57b580SGreg Roach { 101bf57b580SGreg Roach DB::table('module')->insert(['module_name' => 'not-a-module']); 102bf57b580SGreg Roach 103bf57b580SGreg Roach $module_service = new ModuleService(); 104bf57b580SGreg Roach 105*a6d49169SGreg Roach self::assertCount(1, $module_service->deletedModules()); 1065e933c21SGreg Roach self::assertSame('not-a-module', $module_service->deletedModules()->first()); 107bf57b580SGreg Roach } 1084ca7e03cSGreg Roach} 109