xref: /webtrees/tests/app/Services/ModuleServiceTest.php (revision f9237c50b1fa187b551abf31d7b2ed970bed7446)
14ca7e03cSGreg Roach<?php
24ca7e03cSGreg Roach/**
34ca7e03cSGreg Roach * webtrees: online genealogy
44ca7e03cSGreg Roach * Copyright (C) 2019 webtrees development team
54ca7e03cSGreg Roach * This program is free software: you can redistribute it and/or modify
64ca7e03cSGreg Roach * it under the terms of the GNU General Public License as published by
74ca7e03cSGreg Roach * the Free Software Foundation, either version 3 of the License, or
84ca7e03cSGreg Roach * (at your option) any later version.
94ca7e03cSGreg Roach * This program is distributed in the hope that it will be useful,
104ca7e03cSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
114ca7e03cSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
124ca7e03cSGreg Roach * GNU General Public License for more details.
134ca7e03cSGreg Roach * You should have received a copy of the GNU General Public License
144ca7e03cSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
154ca7e03cSGreg Roach */
164ca7e03cSGreg Roachdeclare(strict_types=1);
174ca7e03cSGreg Roach
184ca7e03cSGreg Roachnamespace Fisharebest\Webtrees\Services;
194ca7e03cSGreg Roach
204ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleAnalyticsInterface;
214ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleBlockInterface;
224ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleChartInterface;
234ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleConfigInterface;
244ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleHistoricEventsInterface;
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\Module\TreesMenuModule;
324ca7e03cSGreg Roachuse Fisharebest\Webtrees\TestCase;
339219296aSGreg Roachuse Fisharebest\Webtrees\Tree;
34bf57b580SGreg Roachuse Illuminate\Database\Capsule\Manager as DB;
354ca7e03cSGreg Roach
364ca7e03cSGreg Roach/**
374ca7e03cSGreg Roach * Test the modules
384ca7e03cSGreg Roach *
394ca7e03cSGreg Roach * @coversNothing
404ca7e03cSGreg Roach */
414ca7e03cSGreg Roachclass ModuleServiceTest extends TestCase
424ca7e03cSGreg Roach{
434ca7e03cSGreg Roach    protected static $uses_database = true;
444ca7e03cSGreg Roach
454ca7e03cSGreg Roach    /**
464ca7e03cSGreg Roach     * @covers \Fisharebest\Webtrees\Services\ModuleService::all
474ca7e03cSGreg Roach     * @covers \Fisharebest\Webtrees\Services\ModuleService::coreModules
484ca7e03cSGreg Roach     * @covers \Fisharebest\Webtrees\Services\ModuleService::customModules
494ca7e03cSGreg Roach     * @covers \Fisharebest\Webtrees\Services\ModuleService::moduleSorter
504ca7e03cSGreg Roach     * @return void
514ca7e03cSGreg Roach     */
524ca7e03cSGreg Roach    public function testAll(): void
534ca7e03cSGreg Roach    {
54bf57b580SGreg Roach        app()->instance(Tree::class, Tree::create('name', 'title'));
559219296aSGreg Roach
564ca7e03cSGreg Roach        $module_service = new ModuleService();
574ca7e03cSGreg Roach
584ca7e03cSGreg Roach        $this->assertNotEmpty($module_service->all());
594ca7e03cSGreg Roach    }
604ca7e03cSGreg Roach
614ca7e03cSGreg Roach    /**
624ca7e03cSGreg Roach     * @covers \Fisharebest\Webtrees\Services\ModuleService::findByComponent
634ca7e03cSGreg Roach     * @covers \Fisharebest\Webtrees\Services\ModuleService::menuSorter
644ca7e03cSGreg Roach     * @covers \Fisharebest\Webtrees\Services\ModuleService::sidebarSorter
654ca7e03cSGreg Roach     * @covers \Fisharebest\Webtrees\Services\ModuleService::tabSorter
664ca7e03cSGreg Roach     * @return void
674ca7e03cSGreg Roach     */
684ca7e03cSGreg Roach    public function testFindByComponent(): void
694ca7e03cSGreg Roach    {
70e5a6b4d4SGreg Roach        $user_service = new UserService();
71bf57b580SGreg Roach        app()->instance(Tree::class, Tree::create('name', 'title'));
729219296aSGreg Roach
734ca7e03cSGreg Roach        $module_service = new ModuleService();
744ca7e03cSGreg Roach
754ca7e03cSGreg Roach        $tree = $this->importTree('demo.ged');
76e5a6b4d4SGreg Roach        $user = $user_service->create('UserName', 'RealName', 'user@example.com', 'secret');
774ca7e03cSGreg Roach
7887cca37cSGreg Roach        $this->assertNotEmpty($module_service->findByComponent(ModuleBlockInterface::class, $tree, $user)->all());
7987cca37cSGreg Roach        $this->assertNotEmpty($module_service->findByComponent(ModuleChartInterface::class, $tree, $user)->all());
8087cca37cSGreg Roach        $this->assertNotEmpty($module_service->findByComponent(ModuleMenuInterface::class, $tree, $user)->all());
8187cca37cSGreg Roach        $this->assertNotEmpty($module_service->findByComponent(ModuleReportInterface::class, $tree, $user)->all());
8287cca37cSGreg Roach        $this->assertNotEmpty($module_service->findByComponent(ModuleSidebarInterface::class, $tree, $user)->all());
8387cca37cSGreg Roach        $this->assertNotEmpty($module_service->findByComponent(ModuleTabInterface::class, $tree, $user)->all());
844ca7e03cSGreg Roach    }
854ca7e03cSGreg Roach
864ca7e03cSGreg Roach    /**
874ca7e03cSGreg Roach     * @covers \Fisharebest\Webtrees\Services\ModuleService::findByInterface
884ca7e03cSGreg Roach     * @return void
894ca7e03cSGreg Roach     */
904ca7e03cSGreg Roach    public function testFindByInterface(): void
914ca7e03cSGreg Roach    {
92bf57b580SGreg Roach        app()->instance(Tree::class, Tree::create('name', 'title'));
939219296aSGreg Roach
944ca7e03cSGreg Roach        $module_service = new ModuleService();
954ca7e03cSGreg Roach
964ca7e03cSGreg Roach        $this->assertNotEmpty($module_service->findByInterface(ModuleAnalyticsInterface::class)->all());
974ca7e03cSGreg Roach        $this->assertNotEmpty($module_service->findByInterface(ModuleBlockInterface::class)->all());
984ca7e03cSGreg Roach        $this->assertNotEmpty($module_service->findByInterface(ModuleChartInterface::class)->all());
994ca7e03cSGreg Roach        $this->assertNotEmpty($module_service->findByInterface(ModuleConfigInterface::class)->all());
1004ca7e03cSGreg Roach        $this->assertNotEmpty($module_service->findByInterface(ModuleMenuInterface::class)->all());
1014ca7e03cSGreg Roach        $this->assertNotEmpty($module_service->findByInterface(ModuleInterface::class)->all());
1024ca7e03cSGreg Roach        $this->assertNotEmpty($module_service->findByInterface(ModuleReportInterface::class)->all());
1034ca7e03cSGreg Roach        $this->assertNotEmpty($module_service->findByInterface(ModuleSidebarInterface::class)->all());
1044ca7e03cSGreg Roach        $this->assertNotEmpty($module_service->findByInterface(ModuleTabInterface::class)->all());
1054ca7e03cSGreg Roach        $this->assertNotEmpty($module_service->findByInterface(ModuleThemeInterface::class)->all());
1064ca7e03cSGreg Roach
107321a89daSGreg Roach        // Search for an invalid module type
108*f9237c50SGreg Roach        $this->assertEmpty($module_service->findByInterface('not-a-valid-class-or-interface')->all());
1094ca7e03cSGreg Roach    }
110bf57b580SGreg Roach
111bf57b580SGreg Roach    /**
112bf57b580SGreg Roach     * @covers \Fisharebest\Webtrees\Services\ModuleService::configOnlyModules
113bf57b580SGreg Roach     * @return void
114bf57b580SGreg Roach     */
115bf57b580SGreg Roach    public function testconfigOnlyModules(): void
116bf57b580SGreg Roach    {
117bf57b580SGreg Roach        app()->instance(Tree::class, Tree::create('name', 'title'));
118bf57b580SGreg Roach        DB::table('module')->insert(['module_name' => 'not-a-module']);
119bf57b580SGreg Roach
120bf57b580SGreg Roach        $module_service = new ModuleService();
121bf57b580SGreg Roach
122bf57b580SGreg Roach        $this->assertSame(2, $module_service->configOnlyModules()->count());
123bf57b580SGreg Roach    }
124bf57b580SGreg Roach
125bf57b580SGreg Roach    /**
126bf57b580SGreg Roach     * @covers \Fisharebest\Webtrees\Services\ModuleService::deletedModules
127bf57b580SGreg Roach     * @return void
128bf57b580SGreg Roach     */
129bf57b580SGreg Roach    public function testDeletedModules(): void
130bf57b580SGreg Roach    {
131bf57b580SGreg Roach        app()->instance(Tree::class, Tree::create('name', 'title'));
132bf57b580SGreg Roach        DB::table('module')->insert(['module_name' => 'not-a-module']);
133bf57b580SGreg Roach
134bf57b580SGreg Roach        $module_service = new ModuleService();
135bf57b580SGreg Roach
136bf57b580SGreg Roach        $this->assertSame(1, $module_service->deletedModules()->count());
137bf57b580SGreg Roach        $this->assertSame('not-a-module', $module_service->deletedModules()->first());
138bf57b580SGreg Roach    }
1394ca7e03cSGreg Roach}
140