diff options
| author | Greg Roach <fisharebest@webtrees.net> | 2019-01-30 17:20:38 +0000 |
|---|---|---|
| committer | Greg Roach <fisharebest@webtrees.net> | 2019-01-30 17:29:54 +0000 |
| commit | 4ca7e03c48ab545219e9f91c7860d56cae5e1f09 (patch) | |
| tree | b7006a5d3f1b523fd9028583f21b7033f23b01a5 /tests/app | |
| parent | 77a2010793e07b8d01d1a336fa5967181694729d (diff) | |
| download | webtrees-4ca7e03c48ab545219e9f91c7860d56cae5e1f09.tar.gz webtrees-4ca7e03c48ab545219e9f91c7860d56cae5e1f09.tar.bz2 webtrees-4ca7e03c48ab545219e9f91c7860d56cae5e1f09.zip | |
Create ModuleService
Diffstat (limited to 'tests/app')
| -rw-r--r-- | tests/app/Http/Controllers/ModuleControllerTest.php | 13 | ||||
| -rw-r--r-- | tests/app/ModuleTest.php | 114 | ||||
| -rw-r--r-- | tests/app/Services/ModuleServiceTest.php | 126 |
3 files changed, 133 insertions, 120 deletions
diff --git a/tests/app/Http/Controllers/ModuleControllerTest.php b/tests/app/Http/Controllers/ModuleControllerTest.php index 87eaabf3b2..a2464086c1 100644 --- a/tests/app/Http/Controllers/ModuleControllerTest.php +++ b/tests/app/Http/Controllers/ModuleControllerTest.php @@ -19,6 +19,7 @@ namespace Fisharebest\Webtrees\Http\Controllers; use Fisharebest\Webtrees\Auth; use Fisharebest\Webtrees\Application; +use Fisharebest\Webtrees\Services\ModuleService; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -38,7 +39,7 @@ class ModuleControllerTest extends \Fisharebest\Webtrees\TestCase public function testMissingModule(): void { $user = Auth::user(); - $controller = new ModuleController(); + $controller = new ModuleController(new ModuleService()); $request = new Request(['route' => 'module']); $controller->action($request, $user, new Application()); } @@ -50,7 +51,7 @@ class ModuleControllerTest extends \Fisharebest\Webtrees\TestCase public function testInvalidModule(): void { $user = Auth::user(); - $controller = new ModuleController(); + $controller = new ModuleController(new ModuleService()); $request = new Request(['route' => 'module', 'module' => 'no-such-module']); $controller->action($request, $user, new Application()); } @@ -62,7 +63,7 @@ class ModuleControllerTest extends \Fisharebest\Webtrees\TestCase public function testMissingAction(): void { $user = Auth::user(); - $controller = new ModuleController(); + $controller = new ModuleController(new ModuleService()); $request = new Request(['route' => 'module', 'module' => 'sitemap']); $controller->action($request, $user, new Application()); } @@ -74,7 +75,7 @@ class ModuleControllerTest extends \Fisharebest\Webtrees\TestCase public function testInvalidAction(): void { $user = Auth::user(); - $controller = new ModuleController(); + $controller = new ModuleController(new ModuleService()); $request = new Request(['route' => 'module', 'module' => 'sitemap', 'action' => 'no-such-action']); $controller->action($request, $user, new Application()); } @@ -88,7 +89,7 @@ class ModuleControllerTest extends \Fisharebest\Webtrees\TestCase //$tree = $this->importTree('demo.ged'); $user = Auth::user(); - $controller = new ModuleController(); + $controller = new ModuleController(new ModuleService()); $request = new Request(['route' => 'module', 'module' => 'sitemap', 'action' => 'DoAdminStuff']); $controller->action($request, $user, new Application()); @@ -100,7 +101,7 @@ class ModuleControllerTest extends \Fisharebest\Webtrees\TestCase public function testSucessfulAction(): void { $user = Auth::user(); - $controller = new ModuleController(); + $controller = new ModuleController(new ModuleService()); $request = new Request(['route' => 'module', 'module' => 'sitemap', 'action' => 'Index']); $response = $controller->action($request, $user, new Application()); diff --git a/tests/app/ModuleTest.php b/tests/app/ModuleTest.php deleted file mode 100644 index bbe694fed6..0000000000 --- a/tests/app/ModuleTest.php +++ /dev/null @@ -1,114 +0,0 @@ -<?php -/** - * webtrees: online genealogy - * Copyright (C) 2019 webtrees development team - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ -declare(strict_types=1); - -namespace Fisharebest\Webtrees; - -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; - -/** - * Test the modules - * - * @coversNothing - */ -class ModuleTest extends \Fisharebest\Webtrees\TestCase -{ - protected static $uses_database = true; - - /** - * @covers \Fisharebest\Webtrees\Module::all - * @covers \Fisharebest\Webtrees\Module::coreModules - * @covers \Fisharebest\Webtrees\Module::customModules - * @covers \Fisharebest\Webtrees\Module::moduleSorter - * @return void - */ - public function testAll(): void - { - $this->assertNotEmpty(Module::all()); - } - - /** - * @covers \Fisharebest\Webtrees\Module::findByComponent - * @covers \Fisharebest\Webtrees\Module::menuSorter - * @covers \Fisharebest\Webtrees\Module::sidebarSorter - * @covers \Fisharebest\Webtrees\Module::tabSorter - * @return void - */ - public function testFindByComponent(): void - { - $tree = $this->importTree('demo.ged'); - $user = User::create('UserName', 'RealName', 'user@example.com', 'secret'); - - $this->assertNotEmpty(Module::findByComponent('block', $tree, $user)->all()); - $this->assertNotEmpty(Module::findByComponent('chart', $tree, $user)->all()); - $this->assertNotEmpty(Module::findByComponent('menu', $tree, $user)->all()); - $this->assertNotEmpty(Module::findByComponent('report', $tree, $user)->all()); - $this->assertNotEmpty(Module::findByComponent('sidebar', $tree, $user)->all()); - $this->assertNotEmpty(Module::findByComponent('tab', $tree, $user)->all()); - } - - /** - * @covers \Fisharebest\Webtrees\Module::findByInterface - * @return void - */ - public function testFindByInterface(): void - { - $this->assertNotEmpty(Module::findByInterface(ModuleAnalyticsInterface::class)->all()); - $this->assertNotEmpty(Module::findByInterface(ModuleBlockInterface::class)->all()); - $this->assertNotEmpty(Module::findByInterface(ModuleChartInterface::class)->all()); - $this->assertNotEmpty(Module::findByInterface(ModuleConfigInterface::class)->all()); - $this->assertNotEmpty(Module::findByInterface(ModuleMenuInterface::class)->all()); - $this->assertNotEmpty(Module::findByInterface(ModuleInterface::class)->all()); - $this->assertNotEmpty(Module::findByInterface(ModuleReportInterface::class)->all()); - $this->assertNotEmpty(Module::findByInterface(ModuleSidebarInterface::class)->all()); - $this->assertNotEmpty(Module::findByInterface(ModuleTabInterface::class)->all()); - $this->assertNotEmpty(Module::findByInterface(ModuleThemeInterface::class)->all()); - - // THe core modules do not contain any of these. - $this->assertEmpty(Module::findByInterface(ModuleHistoricEventsInterface::class)->all()); - } - - /** - * @covers \Fisharebest\Webtrees\Module::findByClass - * @return void - */ - public function testFindByClass(): void - { - $this->assertNull(Module::findByClass('not-a-valid-class-name')); - $this->assertInstanceOf(TreesMenuModule::class, Module::findByClass(TreesMenuModule::class)); - } - - /** - * @covers \Fisharebest\Webtrees\Module::findByName - * @return void - */ - public function testFindByName(): void - { - $this->assertNull(Module::findByName('not-a-valid-module-name')); - $this->assertInstanceOf(TreesMenuModule::class, Module::findByName('trees-menu')); - } -} diff --git a/tests/app/Services/ModuleServiceTest.php b/tests/app/Services/ModuleServiceTest.php new file mode 100644 index 0000000000..6f3f0f3a0b --- /dev/null +++ b/tests/app/Services/ModuleServiceTest.php @@ -0,0 +1,126 @@ +<?php +/** + * webtrees: online genealogy + * Copyright (C) 2019 webtrees development team + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +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\User; + +/** + * 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 + { + $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 + { + $module_service = new ModuleService(); + + $tree = $this->importTree('demo.ged'); + $user = User::create('UserName', 'RealName', 'user@example.com', 'secret'); + + $this->assertNotEmpty($module_service->findByComponent('block', $tree, $user)->all()); + $this->assertNotEmpty($module_service->findByComponent('chart', $tree, $user)->all()); + $this->assertNotEmpty($module_service->findByComponent('menu', $tree, $user)->all()); + $this->assertNotEmpty($module_service->findByComponent('report', $tree, $user)->all()); + $this->assertNotEmpty($module_service->findByComponent('sidebar', $tree, $user)->all()); + $this->assertNotEmpty($module_service->findByComponent('tab', $tree, $user)->all()); + } + + /** + * @covers \Fisharebest\Webtrees\Services\ModuleService::findByInterface + * @return void + */ + public function testFindByInterface(): void + { + $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 + { + $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 + { + $module_service = new ModuleService(); + + $this->assertNull($module_service->findByName('not-a-valid-module-name')); + $this->assertInstanceOf(TreesMenuModule::class, $module_service->findByName('trees-menu')); + } +} |
