[TASK] Makes Format/UrlencodeViewHelper compilable 63/39163/2
authorJan Helke <typo3@helke.de>
Fri, 1 May 2015 17:19:49 +0000 (19:19 +0200)
committerFrank Nägler <typo3@naegler.net>
Fri, 1 May 2015 20:10:18 +0000 (22:10 +0200)
Resolves: #66713
Releases: master
Change-Id: Ia079f24e86df63dbd8467e5750d660739af1beb7
Reviewed-on: http://review.typo3.org/39163
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Frank Nägler <typo3@naegler.net>
Tested-by: Frank Nägler <typo3@naegler.net>
typo3/sysext/fluid/Classes/ViewHelpers/Format/UrlencodeViewHelper.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Format/UrlencodeViewHelperTest.php

index 59c3c24..1832d29 100644 (file)
@@ -10,6 +10,9 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Format;
  *                                                                        *
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
+use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
+use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
+use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
 
 /**
  * Encodes the given string according to http://www.faqs.org/rfcs/rfc3986.html (applying PHPs rawurlencode() function)
@@ -33,7 +36,7 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Format;
  *
  * @api
  */
-class UrlencodeViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
+class UrlencodeViewHelper extends AbstractViewHelper implements CompilableInterface {
 
        /**
         * Disable the escaping interceptor because otherwise the child nodes would be escaped before this view helper
@@ -52,13 +55,31 @@ class UrlencodeViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewH
         * @api
         */
        public function render($value = NULL) {
+               return self::renderStatic(
+                       array(
+                               'value' => $value
+                       ),
+                       $this->buildRenderChildrenClosure(),
+                       $this->renderingContext
+               );
+       }
+
+       /**
+        * @param array $arguments
+        * @param callable $renderChildrenClosure
+        * @param RenderingContextInterface $renderingContext
+        *
+        * @return string
+        */
+       static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
+               $value = $arguments['value'];
+
                if ($value === NULL) {
-                       $value = $this->renderChildren();
+                       $value = $renderChildrenClosure();
                }
                if (!is_string($value)) {
                        return $value;
                }
                return rawurlencode($value);
        }
-
 }
index 1fada50..336f64b 100644 (file)
@@ -10,11 +10,14 @@ namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format;
  *                                                                        *
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
+use TYPO3\CMS\Core\Tests\UnitTestCase;
+use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;
+use TYPO3\CMS\Fluid\ViewHelpers\Format\UrlencodeViewHelper;
 
 /**
  * Test case
  */
-class UrlencodeViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
+class UrlencodeViewHelperTest extends UnitTestCase {
 
        /**
         * @var \TYPO3\CMS\Fluid\ViewHelpers\Format\UrlencodeViewHelper
@@ -22,7 +25,11 @@ class UrlencodeViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        protected $viewHelper;
 
        protected function setUp() {
-               $this->viewHelper = $this->getMock(\TYPO3\CMS\Fluid\ViewHelpers\Format\UrlencodeViewHelper::class, array('renderChildren'));
+               $this->viewHelper = $this->getMock(UrlencodeViewHelper::class, array('renderChildren'));
+
+               /** @var RenderingContext $renderingContext */
+               $renderingContext = $this->getMock(RenderingContext::class);
+               $this->viewHelper->setRenderingContext($renderingContext);
        }
 
        /**