[BUGFIX] Initialize arguments correctly in routing related ViewHelpers 79/58579/4
authorDaniel Goerz <daniel.goerz@posteo.de>
Fri, 5 Oct 2018 07:34:51 +0000 (09:34 +0200)
committerMathias Brodala <mbrodala@pagemachine.de>
Mon, 8 Oct 2018 08:33:47 +0000 (10:33 +0200)
Being initialized with the correct default value of an empty array
the Viewhelper no longer leads to a fatal error if called without
the argument "parameters".

Additionally the argument "route" is marked as required.

Resolves: #86576
Releases: master
Change-Id: I3457b4292d4409826250d4c5b1ec53d087b2bd95
Reviewed-on: https://review.typo3.org/58579
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Rudy Gnodde <rgn@windinternet.nl>
Reviewed-by: Josef Glatz <josef.glatz@typo3.org>
Tested-by: Josef Glatz <josef.glatz@typo3.org>
Reviewed-by: Mathias Brodala <mbrodala@pagemachine.de>
Tested-by: Mathias Brodala <mbrodala@pagemachine.de>
typo3/sysext/fluid/Classes/ViewHelpers/Be/LinkViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/Be/UriViewHelper.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Be/LinkViewHelperTest.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Be/UriViewHelperTest.php

index 90d9598..3d983e5 100644 (file)
@@ -44,8 +44,8 @@ class LinkViewHelper extends AbstractTagBasedViewHelper
     public function initializeArguments()
     {
         parent::initializeArguments();
-        $this->registerArgument('route', 'string', 'The name of the route');
-        $this->registerArgument('parameters', 'array', 'An array of parameters');
+        $this->registerArgument('route', 'string', 'The name of the route', true);
+        $this->registerArgument('parameters', 'array', 'An array of parameters', false, []);
         $this->registerArgument('referenceType', 'string', 'The type of reference to be generated (one of the constants)', false, UriBuilder::ABSOLUTE_PATH);
         $this->registerTagAttribute('name', 'string', 'Specifies the name of an anchor');
         $this->registerTagAttribute(
index f5d9a47..16f2363 100644 (file)
@@ -45,8 +45,8 @@ class UriViewHelper extends AbstractBackendViewHelper
     public function initializeArguments()
     {
         parent::initializeArguments();
-        $this->registerArgument('route', 'string', 'The name of the route');
-        $this->registerArgument('parameters', 'array', 'An array of parameters');
+        $this->registerArgument('route', 'string', 'The name of the route', true);
+        $this->registerArgument('parameters', 'array', 'An array of parameters', false, []);
         $this->registerArgument(
             'referenceType',
             'string',
index b62afba..1e45076 100644 (file)
@@ -103,4 +103,23 @@ class LinkViewHelperTest extends ViewHelperBaseTestcase
 
         $this->viewHelper->render();
     }
+
+    /**
+     * @test
+     */
+    public function renderPassesEmptyArrayToUriBuilderForNoParameters()
+    {
+        $this->setArgumentsUnderTest(
+            $this->viewHelper,
+            [
+                'route' => 'theRouteArgument',
+                'referenceType' => 'theReferenceTypeArgument'
+            ]
+        );
+        GeneralUtility::addInstance(UriBuilder::class, $this->uriBuilderMock);
+
+        $this->uriBuilderMock->expects($this->once())->method('buildUriFromRoute')
+            ->with('theRouteArgument', [], 'theReferenceTypeArgument')->willReturn('theUri');
+        $this->viewHelper->render();
+    }
 }
index 1b97e7d..dd52c81 100644 (file)
@@ -82,4 +82,23 @@ class UriViewHelperTest extends ViewHelperBaseTestcase
 
         $this->assertEquals('theUri', $this->viewHelper->render());
     }
+
+    /**
+     * @test
+     */
+    public function renderPassesEmptyArrayToUriBuilderForNoParameters()
+    {
+        $this->setArgumentsUnderTest(
+            $this->viewHelper,
+            [
+                'route' => 'theRouteArgument',
+                'referenceType' => 'theReferenceTypeArgument'
+            ]
+        );
+        GeneralUtility::addInstance(UriBuilder::class, $this->uriBuilderMock);
+
+        $this->uriBuilderMock->expects($this->once())->method('buildUriFromRoute')
+            ->with('theRouteArgument', [], 'theReferenceTypeArgument')->willReturn('theUri');
+        $this->viewHelper->render();
+    }
 }