[BUGFIX] Fix empty href parameter 89/22789/6
authorAnja Leichsenring <aleichsenring@ab-softlab.de>
Sat, 3 Aug 2013 13:38:46 +0000 (15:38 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Mon, 5 Aug 2013 21:00:32 +0000 (23:00 +0200)
In case the link target is not available (maybe hidden), the behaviour
known from the Core is to render the link text, but no a tag. The pageVH
renders the link, but the href parameter will be empty.

Resolves: #50751
Releases: 6.2, 6.1, 6.0
Change-Id: I526aa0e3d42f8aba867b3f996bac2366dc1f6d19
Reviewed-on: https://review.typo3.org/22789
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
typo3/sysext/fluid/Classes/ViewHelpers/Link/PageViewHelper.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Link/PageViewHelperTest.php [new file with mode: 0644]

index a9a06dc..a16e717 100644 (file)
@@ -76,9 +76,14 @@ class PageViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedVi
        public function render($pageUid = NULL, array $additionalParams = array(), $pageType = 0, $noCache = FALSE, $noCacheHash = FALSE, $section = '', $linkAccessRestrictedPages = FALSE, $absolute = FALSE, $addQueryString = FALSE, array $argumentsToBeExcludedFromQueryString = array()) {
                $uriBuilder = $this->controllerContext->getUriBuilder();
                $uri = $uriBuilder->reset()->setTargetPageUid($pageUid)->setTargetPageType($pageType)->setNoCache($noCache)->setUseCacheHash(!$noCacheHash)->setSection($section)->setLinkAccessRestrictedPages($linkAccessRestrictedPages)->setArguments($additionalParams)->setCreateAbsoluteUri($absolute)->setAddQueryString($addQueryString)->setArgumentsToBeExcludedFromQueryString($argumentsToBeExcludedFromQueryString)->build();
-               $this->tag->addAttribute('href', $uri);
-               $this->tag->setContent($this->renderChildren());
-               return $this->tag->render();
+               if (strlen($uri)) {
+                       $this->tag->addAttribute('href', $uri);
+                       $this->tag->setContent($this->renderChildren());
+                       $result = $this->tag->render();
+               } else {
+                       $result = $this->renderChildren();
+               }
+               return $result;
        }
 }
 
diff --git a/typo3/sysext/fluid/Tests/Unit/ViewHelpers/Link/PageViewHelperTest.php b/typo3/sysext/fluid/Tests/Unit/ViewHelpers/Link/PageViewHelperTest.php
new file mode 100644 (file)
index 0000000..91f80ba
--- /dev/null
@@ -0,0 +1,63 @@
+<?php
+namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Link;
+
+/*                                                                        *
+ * This script is part of the TYPO3 project - inspiring people to share!  *
+ *                                                                        *
+ * TYPO3 is free software; you can redistribute it and/or modify it under *
+ * the terms of the GNU General Public License version 2 as published by  *
+ * the Free Software Foundation.                                          *
+ *                                                                        *
+ * This script is distributed in the hope that it will be useful, but     *
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
+ * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General      *
+ * Public License for more details.                                       *
+ *                                                                        */
+
+use TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext;
+use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
+use TYPO3\CMS\Fluid\ViewHelpers\Link\PageViewHelper;
+
+require_once __DIR__ . '/../ViewHelperBaseTestcase.php';
+
+/**
+ * Test-case for Link\PageViewHelper
+ */
+class PageViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHelperBaseTestcase {
+
+       /**
+        * @var PageViewHelper
+        */
+       protected $viewHelper;
+
+       /**
+        * setUp function
+        */
+       public function setUp() {
+               parent::setUp();
+               $this->viewHelper = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\ViewHelpers\\Link\\PageViewHelper', array('renderChildren'));
+               $this->injectDependenciesIntoViewHelper($this->viewHelper);
+               $this->viewHelper->initializeArguments();
+       }
+
+       /**
+        * @test
+        */
+       public function renderProvidesATagForValidLinkTarget() {
+               $this->uriBuilder->expects($this->once())->method('build')->will($this->returnValue('index.php'));
+               $this->tagBuilder->expects($this->once())->method('render');
+               $this->viewHelper->render();
+       }
+
+       /**
+        * @test
+        */
+       public function renderWillNotProvideATagForNonValidLinkTarget() {
+               $this->uriBuilder->expects($this->once())->method('build')->will($this->returnValue(NULL));
+               $this->tagBuilder->expects($this->never())->method('render');
+               $this->viewHelper->render();
+       }
+
+}
+
+?>
\ No newline at end of file