xref: /webtrees/tests/app/Services/ModuleServiceTest.php (revision ce42304a0e3b715b5830d587f136ecd5ca69f11b)
14ca7e03cSGreg Roach<?php
23976b470SGreg 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 */
17fcfa147eSGreg Roach
184ca7e03cSGreg Roachdeclare(strict_types=1);
194ca7e03cSGreg Roach
204ca7e03cSGreg Roachnamespace Fisharebest\Webtrees\Services;
214ca7e03cSGreg Roach
224ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleAnalyticsInterface;
234ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleBlockInterface;
244ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleChartInterface;
254ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleConfigInterface;
26*ce42304aSGreg Roachuse Fisharebest\Webtrees\Module\ModuleDataFixInterface;
274ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleInterface;
284ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleMenuInterface;
294ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleReportInterface;
304ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleSidebarInterface;
314ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleTabInterface;
324ca7e03cSGreg Roachuse Fisharebest\Webtrees\Module\ModuleThemeInterface;
334ca7e03cSGreg Roachuse Fisharebest\Webtrees\TestCase;
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    {
544ca7e03cSGreg Roach        $module_service = new ModuleService();
554ca7e03cSGreg Roach
564ca7e03cSGreg Roach        $this->assertNotEmpty($module_service->all());
574ca7e03cSGreg Roach    }
584ca7e03cSGreg Roach
594ca7e03cSGreg Roach    /**
604ca7e03cSGreg Roach     * @covers \Fisharebest\Webtrees\Services\ModuleService::findByComponent
614ca7e03cSGreg Roach     * @covers \Fisharebest\Webtrees\Services\ModuleService::menuSorter
624ca7e03cSGreg Roach     * @covers \Fisharebest\Webtrees\Services\ModuleService::sidebarSorter
634ca7e03cSGreg Roach     * @covers \Fisharebest\Webtrees\Services\ModuleService::tabSorter
644ca7e03cSGreg Roach     * @return void
654ca7e03cSGreg Roach     */
664ca7e03cSGreg Roach    public function testFindByComponent(): void
674ca7e03cSGreg Roach    {
68e5a6b4d4SGreg Roach        $user_service   = new UserService();
694ca7e03cSGreg Roach        $module_service = new ModuleService();
704ca7e03cSGreg Roach
714ca7e03cSGreg Roach        $tree = $this->importTree('demo.ged');
72e5a6b4d4SGreg Roach        $user = $user_service->create('UserName', 'RealName', 'user@example.com', 'secret');
734ca7e03cSGreg Roach
7487cca37cSGreg Roach        $this->assertNotEmpty($module_service->findByComponent(ModuleBlockInterface::class, $tree, $user)->all());
7587cca37cSGreg Roach        $this->assertNotEmpty($module_service->findByComponent(ModuleChartInterface::class, $tree, $user)->all());
7687cca37cSGreg Roach        $this->assertNotEmpty($module_service->findByComponent(ModuleMenuInterface::class, $tree, $user)->all());
7787cca37cSGreg Roach        $this->assertNotEmpty($module_service->findByComponent(ModuleReportInterface::class, $tree, $user)->all());
7887cca37cSGreg Roach        $this->assertNotEmpty($module_service->findByComponent(ModuleSidebarInterface::class, $tree, $user)->all());
7987cca37cSGreg Roach        $this->assertNotEmpty($module_service->findByComponent(ModuleTabInterface::class, $tree, $user)->all());
804ca7e03cSGreg Roach    }
814ca7e03cSGreg Roach
824ca7e03cSGreg Roach    /**
834ca7e03cSGreg Roach     * @covers \Fisharebest\Webtrees\Services\ModuleService::findByInterface
844ca7e03cSGreg Roach     * @return void
854ca7e03cSGreg Roach     */
864ca7e03cSGreg Roach    public function testFindByInterface(): void
874ca7e03cSGreg Roach    {
884ca7e03cSGreg Roach        $module_service = new ModuleService();
894ca7e03cSGreg Roach
905703d1aeSGreg Roach        $this->assertNotEmpty($module_service->findByInterface(ModuleAnalyticsInterface::class, true)->all());
915703d1aeSGreg Roach        $this->assertNotEmpty($module_service->findByInterface(ModuleBlockInterface::class, true)->all());
925703d1aeSGreg Roach        $this->assertNotEmpty($module_service->findByInterface(ModuleChartInterface::class, true)->all());
935703d1aeSGreg Roach        $this->assertNotEmpty($module_service->findByInterface(ModuleConfigInterface::class, true)->all());
94*ce42304aSGreg Roach        $this->assertNotEmpty($module_service->findByInterface(ModuleDataFixInterface::class, true)->all());
955703d1aeSGreg Roach        $this->assertNotEmpty($module_service->findByInterface(ModuleMenuInterface::class, true)->all());
965703d1aeSGreg Roach        $this->assertNotEmpty($module_service->findByInterface(ModuleInterface::class, true)->all());
975703d1aeSGreg Roach        $this->assertNotEmpty($module_service->findByInterface(ModuleReportInterface::class, true)->all());
985703d1aeSGreg Roach        $this->assertNotEmpty($module_service->findByInterface(ModuleSidebarInterface::class, true)->all());
995703d1aeSGreg Roach        $this->assertNotEmpty($module_service->findByInterface(ModuleTabInterface::class, true)->all());
1005703d1aeSGreg Roach        $this->assertNotEmpty($module_service->findByInterface(ModuleThemeInterface::class, true)->all());
1014ca7e03cSGreg Roach
102321a89daSGreg Roach        // Search for an invalid module type
103f9237c50SGreg Roach        $this->assertEmpty($module_service->findByInterface('not-a-valid-class-or-interface')->all());
1044ca7e03cSGreg Roach    }
105bf57b580SGreg Roach
106bf57b580SGreg Roach    /**
107e364afe4SGreg Roach     * @covers \Fisharebest\Webtrees\Services\ModuleService::otherModules
108bf57b580SGreg Roach     * @return void
109bf57b580SGreg Roach     */
110e364afe4SGreg Roach    public function testOtherModules(): void
111bf57b580SGreg Roach    {
112bf57b580SGreg Roach        DB::table('module')->insert(['module_name' => 'not-a-module']);
113bf57b580SGreg Roach
114bf57b580SGreg Roach        $module_service = new ModuleService();
115bf57b580SGreg Roach
116*ce42304aSGreg Roach        $this->assertSame(2, $module_service->otherModules()->count());
117bf57b580SGreg Roach    }
118bf57b580SGreg Roach
119bf57b580SGreg Roach    /**
120bf57b580SGreg Roach     * @covers \Fisharebest\Webtrees\Services\ModuleService::deletedModules
121bf57b580SGreg Roach     * @return void
122bf57b580SGreg Roach     */
123bf57b580SGreg Roach    public function testDeletedModules(): void
124bf57b580SGreg Roach    {
125bf57b580SGreg Roach        DB::table('module')->insert(['module_name' => 'not-a-module']);
126bf57b580SGreg Roach
127bf57b580SGreg Roach        $module_service = new ModuleService();
128bf57b580SGreg Roach
129bf57b580SGreg Roach        $this->assertSame(1, $module_service->deletedModules()->count());
130bf57b580SGreg Roach        $this->assertSame('not-a-module', $module_service->deletedModules()->first());
131bf57b580SGreg Roach    }
1324ca7e03cSGreg Roach}
133