From 66ea3e83fdfa0cebd418dc6283d440a2b1519474 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Thu, 19 Sep 2019 23:24:38 +0200 Subject: [PATCH] Optimized test and CreateSourceAction --- .../src/Domain/Action/Create/CreateSourceAction.php | 10 +++++----- .../Create/CreateSourceActionIntegrationTest.php | 7 +++++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/application/symfony/src/Domain/Action/Create/CreateSourceAction.php b/application/symfony/src/Domain/Action/Create/CreateSourceAction.php index 06f2b35..75088d4 100644 --- a/application/symfony/src/Domain/Action/Create/CreateSourceAction.php +++ b/application/symfony/src/Domain/Action/Create/CreateSourceAction.php @@ -66,16 +66,16 @@ final class CreateSourceAction extends AbstractCreateAction /** * {@inheritdoc} * + * @todo Needs to be implemented and recheckt + * * @see \Infinito\Domain\Action\AbstractAction::isValid() */ protected function isValid(): bool { - //The following Exception just exists out of debuging reasons during the development process - if (!$this->form->isSubmitted()) { - throw new \Exception('The form is not submitted!'); - } + $request = $this->actionService->getRequest()->request->all(); + $this->form->submit($request); - return $this->form->isValid(); + return $this->form->isSubmitted() && $this->form->isValid(); } /** diff --git a/application/symfony/tests/Integration/Domain/Action/Create/CreateSourceActionIntegrationTest.php b/application/symfony/tests/Integration/Domain/Action/Create/CreateSourceActionIntegrationTest.php index 3f72fc1..6f5f108 100644 --- a/application/symfony/tests/Integration/Domain/Action/Create/CreateSourceActionIntegrationTest.php +++ b/application/symfony/tests/Integration/Domain/Action/Create/CreateSourceActionIntegrationTest.php @@ -66,11 +66,13 @@ class CreateSourceActionIntegrationTest extends KernelTestCase public function setUp(): void { self::bootKernel(); + $csrfToken = self::$container->get('security.csrf.token_manager')->getToken('authenticate')->getValue(); $this->formFactory = self::$container->get('form.factory'); $entityManager = static::$kernel->getContainer() ->get('doctrine') ->getManager(); - $security = $this->createMock(Security::class); + $security = self::$container->get(Security::class); + //$security = $this->createMock(Security::class); $userSourceDirectorService = new UserSourceDirectorService($entityManager, $security); $requestedEntityService = new RequestedEntityService(); $requestedRightService = new RequestedRightService($requestedEntityService); @@ -80,6 +82,7 @@ class CreateSourceActionIntegrationTest extends KernelTestCase $formClassNameService = new FormClassNameService(); $requestedActionFormBuilderService = new RequestedActionFormBuilderService($this->formFactory, $formClassNameService, $this->requestedActionService); $this->request = new Request(); + $this->request->request->set('_token', $csrfToken); $this->requestStack = new RequestStack(); $this->requestStack->push($this->request); $layerRepositoryFactoryService = new LayerRepositoryFactoryService($entityManager); @@ -97,7 +100,7 @@ class CreateSourceActionIntegrationTest extends KernelTestCase public function testCreateWithGuestUser(): void { $this->request->setMethod(Request::METHOD_POST); - $this->request->attributes->set(ClassAttributInterface::CLASS_ATTRIBUT_NAME, PureSource::class); + $this->request->request->set(ClassAttributInterface::CLASS_ATTRIBUT_NAME, PureSource::class); $this->assertInstanceOf(PureSourceInterface::class, $this->createSourceAction->execute()); }