. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Services; use Fisharebest\Webtrees\Module\ModuleAnalyticsInterface; use Fisharebest\Webtrees\Module\ModuleBlockInterface; use Fisharebest\Webtrees\Module\ModuleChartInterface; use Fisharebest\Webtrees\Module\ModuleConfigInterface; use Fisharebest\Webtrees\Module\ModuleHistoricEventsInterface; use Fisharebest\Webtrees\Module\ModuleInterface; use Fisharebest\Webtrees\Module\ModuleMenuInterface; use Fisharebest\Webtrees\Module\ModuleReportInterface; use Fisharebest\Webtrees\Module\ModuleSidebarInterface; use Fisharebest\Webtrees\Module\ModuleTabInterface; use Fisharebest\Webtrees\Module\ModuleThemeInterface; use Fisharebest\Webtrees\Module\TreesMenuModule; use Fisharebest\Webtrees\TestCase; use Fisharebest\Webtrees\Tree; use Illuminate\Database\Capsule\Manager as DB; /** * Test the modules * * @coversNothing */ class ModuleServiceTest extends TestCase { protected static $uses_database = true; /** * @covers \Fisharebest\Webtrees\Services\ModuleService::all * @covers \Fisharebest\Webtrees\Services\ModuleService::coreModules * @covers \Fisharebest\Webtrees\Services\ModuleService::customModules * @covers \Fisharebest\Webtrees\Services\ModuleService::moduleSorter * @return void */ public function testAll(): void { app()->instance(Tree::class, Tree::create('name', 'title')); $module_service = new ModuleService(); $this->assertNotEmpty($module_service->all()); } /** * @covers \Fisharebest\Webtrees\Services\ModuleService::findByComponent * @covers \Fisharebest\Webtrees\Services\ModuleService::menuSorter * @covers \Fisharebest\Webtrees\Services\ModuleService::sidebarSorter * @covers \Fisharebest\Webtrees\Services\ModuleService::tabSorter * @return void */ public function testFindByComponent(): void { $user_service = new UserService(); app()->instance(Tree::class, Tree::create('name', 'title')); $module_service = new ModuleService(); $tree = $this->importTree('demo.ged'); $user = $user_service->create('UserName', 'RealName', 'user@example.com', 'secret'); $this->assertNotEmpty($module_service->findByComponent(ModuleBlockInterface::class, $tree, $user)->all()); $this->assertNotEmpty($module_service->findByComponent(ModuleChartInterface::class, $tree, $user)->all()); $this->assertNotEmpty($module_service->findByComponent(ModuleMenuInterface::class, $tree, $user)->all()); $this->assertNotEmpty($module_service->findByComponent(ModuleReportInterface::class, $tree, $user)->all()); $this->assertNotEmpty($module_service->findByComponent(ModuleSidebarInterface::class, $tree, $user)->all()); $this->assertNotEmpty($module_service->findByComponent(ModuleTabInterface::class, $tree, $user)->all()); } /** * @covers \Fisharebest\Webtrees\Services\ModuleService::findByInterface * @return void */ public function testFindByInterface(): void { app()->instance(Tree::class, Tree::create('name', 'title')); $module_service = new ModuleService(); $this->assertNotEmpty($module_service->findByInterface(ModuleAnalyticsInterface::class)->all()); $this->assertNotEmpty($module_service->findByInterface(ModuleBlockInterface::class)->all()); $this->assertNotEmpty($module_service->findByInterface(ModuleChartInterface::class)->all()); $this->assertNotEmpty($module_service->findByInterface(ModuleConfigInterface::class)->all()); $this->assertNotEmpty($module_service->findByInterface(ModuleMenuInterface::class)->all()); $this->assertNotEmpty($module_service->findByInterface(ModuleInterface::class)->all()); $this->assertNotEmpty($module_service->findByInterface(ModuleReportInterface::class)->all()); $this->assertNotEmpty($module_service->findByInterface(ModuleSidebarInterface::class)->all()); $this->assertNotEmpty($module_service->findByInterface(ModuleTabInterface::class)->all()); $this->assertNotEmpty($module_service->findByInterface(ModuleThemeInterface::class)->all()); // THe core modules do not contain any of these. $this->assertEmpty($module_service->findByInterface(ModuleHistoricEventsInterface::class)->all()); } /** * @covers \Fisharebest\Webtrees\Services\ModuleService::findByClass * @return void */ public function testFindByClass(): void { app()->instance(Tree::class, Tree::create('name', 'title')); $module_service = new ModuleService(); $this->assertNull($module_service->findByClass('not-a-valid-class-name')); $this->assertInstanceOf(TreesMenuModule::class, $module_service->findByClass(TreesMenuModule::class)); } /** * @covers \Fisharebest\Webtrees\Services\ModuleService::findByName * @return void */ public function testFindByName(): void { app()->instance(Tree::class, Tree::create('name', 'title')); $module_service = new ModuleService(); $this->assertNull($module_service->findByName('not-a-valid-module-name')); $this->assertInstanceOf(TreesMenuModule::class, $module_service->findByName('trees-menu')); } /** * @covers \Fisharebest\Webtrees\Services\ModuleService::configOnlyModules * @return void */ public function testconfigOnlyModules(): void { app()->instance(Tree::class, Tree::create('name', 'title')); DB::table('module')->insert(['module_name' => 'not-a-module']); $module_service = new ModuleService(); $this->assertSame(2, $module_service->configOnlyModules()->count()); } /** * @covers \Fisharebest\Webtrees\Services\ModuleService::deletedModules * @return void */ public function testDeletedModules(): void { app()->instance(Tree::class, Tree::create('name', 'title')); DB::table('module')->insert(['module_name' => 'not-a-module']); $module_service = new ModuleService(); $this->assertSame(1, $module_service->deletedModules()->count()); $this->assertSame('not-a-module', $module_service->deletedModules()->first()); } }