[TASK] Makes Format/HtmlentitiesDecodeViewHelper compilable 62/39162/5
authorJan Helke <typo3@helke.de>
Fri, 1 May 2015 16:27:47 +0000 (18:27 +0200)
committerNicole Cordes <typo3@cordes.co>
Fri, 1 May 2015 18:54:27 +0000 (20:54 +0200)
Resolves: #66710
Releases: master
Change-Id: I13d0df90c4d3e03af31d9cb3c4a081136fdd96e3
Reviewed-on: http://review.typo3.org/39162
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Nicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes <typo3@cordes.co>
typo3/sysext/fluid/Classes/ViewHelpers/Format/AbstractEncodingViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/Format/HtmlentitiesDecodeViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/Format/HtmlentitiesViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/Format/HtmlspecialcharsViewHelper.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Format/HtmlentitiesDecodeViewHelperTest.php

index 4e38278..95894a5 100644 (file)
@@ -29,7 +29,7 @@ abstract class AbstractEncodingViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelp
         *
         * @return string the encoding
         */
-       protected function resolveDefaultEncoding() {
+       static protected function resolveDefaultEncoding() {
                if (self::$defaultEncoding === NULL) {
                        self::$defaultEncoding = 'UTF-8';
                }
index c8029c7..63c3eb8 100644 (file)
@@ -10,6 +10,8 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Format;
  *                                                                        *
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
+use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
+use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
 
 /**
  * Applies html_entity_decode() to a value
@@ -33,7 +35,7 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Format;
  *
  * @api
  */
-class HtmlentitiesDecodeViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Format\AbstractEncodingViewHelper {
+class HtmlentitiesDecodeViewHelper extends AbstractEncodingViewHelper implements CompilableInterface {
 
        /**
         * Disable the escaping interceptor because otherwise the child nodes would be escaped before this view helper
@@ -54,14 +56,37 @@ class HtmlentitiesDecodeViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Format\A
         * @api
         */
        public function render($value = NULL, $keepQuotes = FALSE, $encoding = NULL) {
+               return self::renderStatic(
+                       array(
+                               'value' => $value,
+                               'keepQuotes' => $keepQuotes,
+                               'encoding' => $encoding
+                       ),
+                       $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'];
+               $encoding = $arguments['encoding'];
+               $keepQuotes = $arguments['keepQuotes'];
+
                if ($value === NULL) {
-                       $value = $this->renderChildren();
+                       $value = $renderChildrenClosure();
                }
                if (!is_string($value)) {
                        return $value;
                }
                if ($encoding === NULL) {
-                       $encoding = $this->resolveDefaultEncoding();
+                       $encoding = self::resolveDefaultEncoding();
                }
                $flags = $keepQuotes ? ENT_NOQUOTES : ENT_COMPAT;
                return html_entity_decode($value, $flags, $encoding);
index a8727c5..b5b6295 100644 (file)
@@ -10,6 +10,7 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Format;
  *                                                                        *
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
+use TYPO3\CMS\Core\SingletonInterface;
 
 /**
  * Applies htmlentities() escaping to a value
@@ -33,7 +34,7 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Format;
  *
  * @api
  */
-class HtmlentitiesViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Format\AbstractEncodingViewHelper implements \TYPO3\CMS\Core\SingletonInterface {
+class HtmlentitiesViewHelper extends AbstractEncodingViewHelper implements SingletonInterface {
 
        /**
         * Disable the escaping interceptor because otherwise the child nodes would be escaped before this view helper
@@ -62,7 +63,7 @@ class HtmlentitiesViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Format\Abstrac
                        return $value;
                }
                if ($encoding === NULL) {
-                       $encoding = $this->resolveDefaultEncoding();
+                       $encoding = self::resolveDefaultEncoding();
                }
                $flags = $keepQuotes ? ENT_NOQUOTES : ENT_COMPAT;
                return htmlentities($value, $flags, $encoding, $doubleEncode);
index 88fcd30..54c6d2e 100644 (file)
@@ -10,6 +10,7 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Format;
  *                                                                        *
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
+use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
 
 /**
  * Applies htmlspecialchars() escaping to a value
@@ -33,7 +34,7 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Format;
  *
  * @api
  */
-class HtmlspecialcharsViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Format\AbstractEncodingViewHelper implements \TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface {
+class HtmlspecialcharsViewHelper extends AbstractEncodingViewHelper implements CompilableInterface {
 
        /**
         * Disable the escaping interceptor because otherwise the child nodes would be escaped before this view helper
@@ -62,7 +63,7 @@ class HtmlspecialcharsViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Format\Abs
                        return $value;
                }
                if ($encoding === NULL) {
-                       $encoding = $this->resolveDefaultEncoding();
+                       $encoding = self::resolveDefaultEncoding();
                }
                $flags = $keepQuotes ? ENT_NOQUOTES : ENT_COMPAT;
                return htmlspecialchars($value, $flags, $encoding, $doubleEncode);
index 8e239e5..4019a04 100644 (file)
@@ -11,18 +11,27 @@ namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format;
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
 
+use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;
+use TYPO3\CMS\Fluid\ViewHelpers\Format\HtmlentitiesDecodeViewHelper;
+use TYPO3\CMS\Core\Tests\UnitTestCase;
+
 /**
  * Test case
  */
-class HtmlentitiesDecodeViewHelperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
+class HtmlentitiesDecodeViewHelperTest extends UnitTestCase {
 
        /**
-        * @var \TYPO3\CMS\Fluid\ViewHelpers\Format\HtmlentitiesDecodeViewHelper
+        * @var HtmlentitiesDecodeViewHelper
         */
        protected $viewHelper;
 
        protected function setUp() {
-               $this->viewHelper = $this->getMock(\TYPO3\CMS\Fluid\ViewHelpers\Format\HtmlentitiesDecodeViewHelper::class, array('renderChildren'));
+               $this->viewHelper = $this->getMock(HtmlentitiesDecodeViewHelper::class, array('renderChildren'));
+
+               /** @var RenderingContext $renderingContext */
+               $renderingContext = $this->getMock(RenderingContext::class);
+               $this->viewHelper->setRenderingContext($renderingContext);
+
        }
 
        /**