Skip to content

Commit

Permalink
!!!TASK: Adapt to PSR-7 changes in Flow
Browse files Browse the repository at this point in the history
This change makes the form package master only compatible with Flow
dev-master or the upcoming 6.0.
  • Loading branch information
kitsunet committed Aug 17, 2019
1 parent 1668ddc commit b54712c
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 40 deletions.
5 changes: 3 additions & 2 deletions Classes/Core/Model/FormDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Neos\Flow\Http\Response;
use Neos\Flow\Mvc\ActionRequest;
use Neos\Flow\Mvc\ActionResponse;
use Neos\Form\Core\Runtime\FormRuntime;
use Neos\Form\Exception;
use Neos\Form\Exception\IdentifierNotValidException;
Expand Down Expand Up @@ -652,11 +653,11 @@ public function removePage(Page $pageToRemove)
* a new "instance" of the Form.
*
* @param ActionRequest $request
* @param Response $response
* @param ActionResponse $response
* @return FormRuntime
* @api
*/
public function bind(ActionRequest $request, Response $response)
public function bind(ActionRequest $request, ActionResponse $response)
{
return new FormRuntime($this, $request, $response);
}
Expand Down
27 changes: 15 additions & 12 deletions Classes/Core/Runtime/FormRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Http\Response;
use Neos\Flow\Mvc\ActionRequest;
use Neos\Flow\Mvc\ActionResponse;
use Neos\Flow\Mvc\Controller\Arguments;
use Neos\Flow\Mvc\Controller\ControllerContext;
use Neos\Flow\Mvc\Routing\UriBuilder;
Expand Down Expand Up @@ -82,11 +83,17 @@ class FormRuntime implements RootRenderableInterface, \ArrayAccess
protected $request;

/**
* @var Response
* @var ActionResponse
* @internal
*/
protected $response;

/**
* @var ActionResponse
* @internal
*/
protected $parentResponse;

/**
* @var FormState
* @internal
Expand Down Expand Up @@ -139,23 +146,24 @@ class FormRuntime implements RootRenderableInterface, \ArrayAccess
/**
* @param FormDefinition $formDefinition
* @param ActionRequest $request
* @param Response $response
* @param ActionResponse $response
* @throws \Neos\Form\Exception\IdentifierNotValidException
* @internal
*/
public function __construct(FormDefinition $formDefinition, ActionRequest $request, Response $response)
public function __construct(FormDefinition $formDefinition, ActionRequest $request, ActionResponse $response)
{
$this->formDefinition = $formDefinition;
$rootRequest = $request->getMainRequest() ?: $request;
$pluginArguments = $rootRequest->getPluginArguments();
$this->request = new ActionRequest($request);
$this->request = $request->createSubRequest();
$formIdentifier = $this->formDefinition->getIdentifier();
$this->request->setArgumentNamespace('--' . $formIdentifier);
if (isset($pluginArguments[$formIdentifier])) {
$this->request->setArguments($pluginArguments[$formIdentifier]);
}

$this->response = $response;
$this->parentResponse = $request;
$this->response = new ActionResponse();
}

/**
Expand Down Expand Up @@ -338,12 +346,7 @@ public function render()
{
if ($this->isAfterLastPage()) {
$this->invokeFinishers();
$parentResponse = $this->response->getParentResponse();
if ($parentResponse !== null) {
foreach ($this->response->getHeaders()->getAll() as $key => $value) {
$parentResponse->getHeaders()->set($key, $value, true);
}
}
$this->response->mergeIntoParentResponse($this->parentResponse);
return $this->response->getContent();
}

Expand Down Expand Up @@ -411,7 +414,7 @@ public function getRequest()
* This is mostly relevant inside Finishers, where you f.e. want to set response
* headers or output content.
*
* @return Response the response this object is bound to
* @return ActionResponse the response this object is bound to
* @api
*/
public function getResponse()
Expand Down
11 changes: 5 additions & 6 deletions Classes/ViewHelpers/RenderViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@
*/

use Neos\Flow\Mvc\ActionRequest;
use Neos\Flow\Mvc\ActionResponse;
use Neos\FluidAdaptor\Core\ViewHelper\AbstractViewHelper;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Http\Response;
use Neos\FluidAdaptor\Core\ViewHelper\Exception as ViewHelperException;
use Neos\Form\Core\Model\FormDefinition;
use Neos\Form\Core\Model\Renderable\RootRenderableInterface;
use Neos\Form\Core\Runtime\FormRuntime;
use Neos\Form\Factory\ArrayFormFactory;
use Neos\Form\Factory\FormFactoryInterface;
use Neos\Utility\Arrays;
use Neos\Form\Persistence\FormPersistenceManagerInterface;

Expand Down Expand Up @@ -79,12 +83,7 @@ public function render(): string
if (!$formDefinition instanceof FormDefinition) {
throw new ViewHelperException(sprintf('The factory method %s::build() has to return an instance of FormDefinition, got "%s"', $this->arguments['factoryClass'], is_object($formDefinition) ? get_class($formDefinition) : gettype($formDefinition)), 1504024351);
}
$request = $this->controllerContext->getRequest();
if (!$request instanceof ActionRequest) {
throw new ViewHelperException(sprintf('This ViewHelper only works with an ActionRequest, got "%s"', is_object($request) ? get_class($request) : gettype($request)), 1504024356);
}
$response = new Response($this->controllerContext->getResponse());
$form = $formDefinition->bind($request, $response);
$form = $formDefinition->bind($this->controllerContext->getRequest(), $this->controllerContext->getResponse());
return $form->render();
}
}
10 changes: 5 additions & 5 deletions Tests/Functional/AbstractFunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
*/

use Neos\Flow\Http\Client\Browser;
use Neos\Flow\Http\Response as HttpResponse;
use Neos\Flow\Mvc\Routing\Route;
use Neos\Flow\Tests\FunctionalTestCase;
use Psr\Http\Message\ResponseInterface;
use Symfony\Component\DomCrawler\Field\InputFormField;
use Symfony\Component\DomCrawler\Form;

Expand Down Expand Up @@ -54,9 +54,9 @@ public function setUp(): void
* Go to the next form page
*
* @param Form $form
* @return HttpResponse
* @return ResponseInterface
*/
protected function gotoNextFormPage(Form $form): HttpResponse
protected function gotoNextFormPage(Form $form): ResponseInterface
{
$nextButton = $this->browser->getCrawler()->filterXPath('//nav[@class="form-navigation"]/*/*[contains(@class, "next")]/button');
/** @var \DOMElement $node */
Expand All @@ -70,9 +70,9 @@ protected function gotoNextFormPage(Form $form): HttpResponse
* Go to the previous form page
*
* @param Form $form
* @return HttpResponse
* @return ResponseInterface
*/
protected function gotoPreviousFormPage(Form $form): HttpResponse
protected function gotoPreviousFormPage(Form $form): ResponseInterface
{
$previousButton = $this->browser->getCrawler()->filterXPath('//nav[@class="form-navigation"]/*/*[contains(@class, "previous")]/button');
/** @var \DOMElement $node */
Expand Down
5 changes: 2 additions & 3 deletions Tests/Unit/Core/Model/FormDefinitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
* source code.
*/

use Neos\Flow\Http\Response;
use Neos\Flow\Mvc\ActionRequest;
use Neos\Flow\Mvc\ActionResponse;
use Neos\Flow\Tests\UnitTestCase;
use Neos\Form\Core\Model\AbstractFormElement;
use Neos\Form\Core\Model\FinisherInterface;
Expand Down Expand Up @@ -294,8 +294,7 @@ public function bindReturnsBoundFormRuntime()

/** @var ActionRequest|MockObject $mockRequest */
$mockRequest = $this->getMockBuilder(ActionRequest::class)->disableOriginalConstructor()->getMock();
/** @var Response|MockObject $mockResponse */
$mockResponse = $this->getMockBuilder(Response::class)->getMock();
$mockResponse = new ActionResponse();

$form = $formDefinition->bind($mockRequest, $mockResponse);
Assert::assertInstanceOf(FormRuntime::class, $form);
Expand Down
20 changes: 13 additions & 7 deletions Tests/Unit/Core/Renderer/FormRuntimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
* source code.
*/

use Neos\Flow\Http\Response;
use Neos\Flow\Mvc\ActionRequest;
use Neos\Flow\Mvc\ActionResponse;
use Neos\Flow\Tests\UnitTestCase;
use Neos\Form\Core\Model\FormDefinition;
use Neos\Form\Core\Model\Page;
Expand All @@ -36,13 +36,19 @@ class FormRuntimeTest extends UnitTestCase
public function valuesSetInConstructorCanBeReadAgain()
{
$formDefinition = new FormDefinition('foo');
$mockActionRequest = $this->getMockBuilder(ActionRequest::class)->disableOriginalConstructor()->getMock();
$mockHttpResponse = $this->getMockBuilder(Response::class)->disableOriginalConstructor()->getMock();

$formRuntime = $this->getAccessibleMock(FormRuntime::class, ['dummy'], [$formDefinition, $mockActionRequest, $mockHttpResponse]);
$mockActionRequest = $this->getMockBuilder(ActionRequest::class)->setMethods(['createSubRequest'])->disableOriginalConstructor()->getMock();

$mockFormSubRequest = $this->getMockBuilder(ActionRequest::class)->setMethods(['getParentRequest'])->disableOriginalConstructor()->getMock();
$mockFormSubRequest->expects(self::any())->method('getParentRequest')->willReturn($mockActionRequest);

$mockActionRequest->expects(self::once())->method('createSubRequest')->willReturn($mockFormSubRequest);
$actionResponse = new ActionResponse();

$formRuntime = $this->getAccessibleMock(FormRuntime::class, ['dummy'], [$formDefinition, $mockActionRequest, $actionResponse]);

Assert::assertSame($mockActionRequest, $formRuntime->getRequest()->getParentRequest());
Assert::assertSame($mockHttpResponse, $formRuntime->getResponse());
Assert::assertInstanceOf(ActionResponse::class, $formRuntime->getResponse());
Assert::assertSame($formDefinition, $formRuntime->_get('formDefinition'));
}

Expand Down Expand Up @@ -212,8 +218,8 @@ public function arrayAccessReturnsDefaultValuesIfSet()
protected function createFormRuntime(FormDefinition $formDefinition)
{
$mockActionRequest = $this->getMockBuilder(ActionRequest::class)->disableOriginalConstructor()->getMock();
$mockHttpResponse = $this->getMockBuilder(Response::class)->disableOriginalConstructor()->getMock();
$actionResponse = new ActionResponse();

return $this->getAccessibleMock(FormRuntime::class, ['dummy'], [$formDefinition, $mockActionRequest, $mockHttpResponse]);
return $this->getAccessibleMock(FormRuntime::class, ['dummy'], [$formDefinition, $mockActionRequest, $actionResponse]);
}
}
6 changes: 3 additions & 3 deletions Tests/Unit/ViewHelpers/FormViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
* source code.
*/

use Neos\Flow\Http\Request;
use Neos\Flow\Http\Uri;
use GuzzleHttp\Psr7\Uri;
use Neos\Flow\Mvc\ActionRequest;
use Neos\Flow\Mvc\Controller\ControllerContext;
use Neos\Flow\Tests\UnitTestCase;
use Neos\Form\ViewHelpers\FormViewHelper;
use PHPUnit\Framework\Assert;
use Psr\Http\Message\ServerRequestInterface;

/**
* Tests for the custom FormViewHelper
Expand Down Expand Up @@ -78,7 +78,7 @@ public function getFormActionUriTests($requestUri, $sectionArgument, $expectedRe
$mockActionRequest = $this->getMockBuilder(ActionRequest::class)->disableOriginalConstructor()->getMock();
$this->mockControllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($mockActionRequest));

$mockHttpRequest = $this->getMockBuilder(Request::class)->disableOriginalConstructor()->getMock();
$mockHttpRequest = $this->getMockBuilder(ServerRequestInterface::class)->disableOriginalConstructor()->getMock();
$mockActionRequest->expects($this->any())->method('getHttpRequest')->will($this->returnValue($mockHttpRequest));

$mockUri = $this->getMockBuilder(Uri::class)->disableOriginalConstructor()->getMock();
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"description": "Extensible and flexible API for building web forms",
"require": {
"php": ">=7.1.0",
"neos/flow": ">=4.0 <6.0 || dev-master"
"neos/flow": ">=6.0 || dev-master"
},
"replace": {
"typo3/form": "self.version"
Expand All @@ -20,7 +20,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "4.1.x-dev"
"dev-master": "5.0.x-dev"
},
"applied-flow-migrations": [
"TYPO3.Form-20160601101500",
Expand Down

0 comments on commit b54712c

Please sign in to comment.