From fa6444d6a37b8112cc8e016067c98511db4784ae Mon Sep 17 00:00:00 2001 From: Sebastian Helzle Date: Fri, 12 Mar 2021 12:22:41 +0100 Subject: [PATCH] BUGFIX: Set uri section in form viewhelper This is due to a regression in #85f7414e --- Classes/ViewHelpers/FormViewHelper.php | 2 +- Tests/Unit/ViewHelpers/FormViewHelperTest.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Classes/ViewHelpers/FormViewHelper.php b/Classes/ViewHelpers/FormViewHelper.php index a84eb3a..48efba0 100644 --- a/Classes/ViewHelpers/FormViewHelper.php +++ b/Classes/ViewHelpers/FormViewHelper.php @@ -61,7 +61,7 @@ protected function getFormActionUri() $actionRequest = $this->controllerContext->getRequest(); $uri = $actionRequest->getHttpRequest()->getUri(); if ($this->hasArgument('section') && $this->arguments['section'] !== '') { - $uri->withFragment($this->hasArgument('section')); + $uri = $uri->withFragment($this->arguments['section']); } return (string)$uri; } diff --git a/Tests/Unit/ViewHelpers/FormViewHelperTest.php b/Tests/Unit/ViewHelpers/FormViewHelperTest.php index 617e146..c3e7dad 100644 --- a/Tests/Unit/ViewHelpers/FormViewHelperTest.php +++ b/Tests/Unit/ViewHelpers/FormViewHelperTest.php @@ -82,6 +82,12 @@ public function getFormActionUriTests($requestUri, $sectionArgument, $expectedRe $mockActionRequest->expects($this->any())->method('getHttpRequest')->will($this->returnValue($mockHttpRequest)); $mockUri = $this->getMockBuilder(Uri::class)->disableOriginalConstructor()->getMock(); + $mockUri->expects($this->any())->method('withFragment')->will($this->returnCallback(function ($fragment) use ($requestUri, $mockUri) { + $newUri = explode('#', $requestUri)[0] . '#' . $fragment; + $modifiedMockUri = $this->getMockBuilder(Uri::class)->disableOriginalConstructor()->getMock(); + $modifiedMockUri->expects($this->any())->method('__toString')->will($this->returnValue($newUri)); + return $modifiedMockUri; + })); $mockUri->expects($this->any())->method('__toString')->will($this->returnValue($requestUri)); $mockHttpRequest->expects($this->any())->method('getUri')->will($this->returnValue($mockUri));