. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Http\RequestHandlers; use Fisharebest\Webtrees\GuestUser; use Fisharebest\Webtrees\Services\ModuleService; use Fisharebest\Webtrees\TestCase; use Fisharebest\Webtrees\Tree; /** * @covers \Fisharebest\Webtrees\Http\RequestHandlers\ModuleAction */ class ModuleActionTest extends TestCase { protected static $uses_database = true; /** * @return void */ public function testModuleAction(): void { $tree = Tree::create('tree', 'tree'); app()->instance(Tree::class, $tree); $user = new GuestUser(); $module_service = new ModuleService(); $handler = new ModuleAction($module_service, $user); $request = self::createRequest('GET', ['route' => 'module', 'module' => 'faq', 'action' => 'Show', 'ged' => $tree->name()]); $response = $handler->handle($request); $this->assertSame(self::STATUS_OK, $response->getStatusCode()); } /** * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException * @expectedExceptionMessage Method getFishAction() not found in faq * @return void */ public function testNonExistingAction(): void { $user = new GuestUser(); $module_service = new ModuleService(); $handler = new ModuleAction($module_service, $user); $request = self::createRequest('GET', ['route' => 'module', 'module' => 'faq', 'action' => 'Fish']); $handler->handle($request); } /** * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException * @expectedExceptionMessage Module fish does not exist * @return void */ public function testNonExistingModule(): void { $user = new GuestUser(); $module_service = new ModuleService(); $handler = new ModuleAction($module_service, $user); $request = self::createRequest('GET', ['route' => 'module', 'module' => 'fish', 'action' => 'Show']); $response = $handler->handle($request); $this->assertSame(self::STATUS_OK, $response->getStatusCode()); } /** * @expectedException \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException * @expectedExceptionMessage Admin only action * @return void */ public function testAdminAction(): void { $tree = Tree::create('tree', 'tree'); app()->instance(Tree::class, $tree); $user = new GuestUser(); $module_service = new ModuleService(); $handler = new ModuleAction($module_service, $user); $request = self::createRequest('GET', ['route' => 'module', 'module' => 'faq', 'action' => 'Admin', 'ged' => $tree->name()]); $handler->handle($request); } }