[TASK] Move ViewHelper arguments to initializeArguments() in ext:fluid 74/48874/8
authorAnna Färber <anna.faerber@dkd.de>
Sun, 10 Jul 2016 10:36:56 +0000 (12:36 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Tue, 19 Jul 2016 17:29:31 +0000 (19:29 +0200)
Resolves: #77007
Releases: master
Change-Id: I4f672d7605d681dd7f28d5f658211f082822fe5f
Reviewed-on: https://review.typo3.org/48874
Tested-by: Bamboo TYPO3com <info@typo3.com>
Reviewed-by: Nicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes <typo3@cordes.co>
Tested-by: Gleb Levitin <gleb.levitin@dkd.de>
Reviewed-by: Gleb Levitin <gleb.levitin@dkd.de>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/fluid/Classes/ViewHelpers/Format/HtmlentitiesDecodeViewHelper.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Format/HtmlentitiesDecodeViewHelperTest.php

index 9d6dca8..0097c07 100644 (file)
@@ -54,24 +54,27 @@ class HtmlentitiesDecodeViewHelper extends AbstractEncodingViewHelper
      */
     protected $escapeOutput = false;
 
+    /**
+     * Initialize ViewHelper arguments
+     */
+    public function initializeArguments()
+    {
+        parent::initializeArguments();
+        $this->registerArgument('value', 'string', 'string to format');
+        $this->registerArgument('keepQuotes', 'bool', 'If TRUE, single and double quotes won\'t be replaced (sets ENT_NOQUOTES flag).', false, false);
+        $this->registerArgument('encoding', 'string', '');
+    }
+
     /**
      * Converts all HTML entities to their applicable characters as needed using PHPs html_entity_decode() function.
      *
-     * @param string $value string to format
-     * @param bool $keepQuotes if TRUE, single and double quotes won't be replaced (sets ENT_NOQUOTES flag)
-     * @param string $encoding
      * @return string the altered string
      * @see http://www.php.net/html_entity_decode
-     * @api
      */
-    public function render($value = null, $keepQuotes = false, $encoding = null)
+    public function render()
     {
         return static::renderStatic(
-            array(
-                'value' => $value,
-                'keepQuotes' => $keepQuotes,
-                'encoding' => $encoding
-            ),
+            $this->arguments,
             $this->buildRenderChildrenClosure(),
             $this->renderingContext
         );
index 9c772c9..6f1f7a3 100644 (file)
@@ -13,29 +13,40 @@ 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 Prophecy\Prophecy\ObjectProphecy;
+use TYPO3\CMS\Extbase\Reflection\ReflectionService;
+use TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHelperBaseTestcase;
 use TYPO3\CMS\Fluid\ViewHelpers\Format\HtmlentitiesDecodeViewHelper;
 
 /**
  * Test case
  */
-class HtmlentitiesDecodeViewHelperTest extends UnitTestCase
+class HtmlentitiesDecodeViewHelperTest extends ViewHelperBaseTestcase
 {
+    /**
+     * @var ReflectionService|ObjectProphecy
+     */
+    protected $reflectionServiceProphecy;
+
     /**
      * @var HtmlentitiesDecodeViewHelper
      */
     protected $viewHelper;
 
+    /**
+     * shortcut for default Arguments which would be prepared by initializeArguments()
+     *
+     * @var array
+     */
+    protected $defaultArguments;
+
     protected function setUp()
     {
-        $this->viewHelper = $this->getMockBuilder(HtmlentitiesDecodeViewHelper::class)
-            ->setMethods(array('renderChildren'))
-            ->getMock();
-
-        /** @var RenderingContext $renderingContext */
-        $renderingContext = $this->createMock(\TYPO3\CMS\Fluid\Tests\Unit\Core\Rendering\RenderingContextFixture::class);
-        $this->viewHelper->setRenderingContext($renderingContext);
+        parent::setUp();
+        $this->reflectionServiceProphecy = $this->prophesize(ReflectionService::class);
+        $this->viewHelper = new HtmlentitiesDecodeViewHelper();
+        $this->viewHelper->injectReflectionService($this->reflectionServiceProphecy->reveal());
+        $this->injectDependenciesIntoViewHelper($this->viewHelper);
     }
 
     /**
@@ -43,8 +54,13 @@ class HtmlentitiesDecodeViewHelperTest extends UnitTestCase
      */
     public function renderUsesValueAsSourceIfSpecified()
     {
-        $this->viewHelper->expects($this->never())->method('renderChildren');
-        $actualResult = $this->viewHelper->render('Some string');
+        $this->setArgumentsUnderTest(
+            $this->viewHelper,
+            [
+                'value' => 'Some string'
+            ]
+        );
+        $actualResult = $this->viewHelper->initializeArgumentsAndRender();
         $this->assertEquals('Some string', $actualResult);
     }
 
@@ -53,8 +69,13 @@ class HtmlentitiesDecodeViewHelperTest extends UnitTestCase
      */
     public function renderUsesChildnodesAsSourceIfSpecified()
     {
-        $this->viewHelper->expects($this->atLeastOnce())->method('renderChildren')->will($this->returnValue('Some string'));
-        $actualResult = $this->viewHelper->render();
+        $this->viewHelper->setRenderChildrenClosure(
+            function () {
+                return 'Some string';
+            }
+        );
+        $this->setArgumentsUnderTest($this->viewHelper);
+        $actualResult = $this->viewHelper->initializeArgumentsAndRender();
         $this->assertEquals('Some string', $actualResult);
     }
 
@@ -64,7 +85,13 @@ class HtmlentitiesDecodeViewHelperTest extends UnitTestCase
     public function renderDoesNotModifyValueIfItDoesNotContainSpecialCharacters()
     {
         $source = 'This is a sample text without special characters. <> &©"\'';
-        $actualResult = $this->viewHelper->render($source);
+        $this->setArgumentsUnderTest(
+            $this->viewHelper,
+            [
+                'value' => $source,
+            ]
+        );
+        $actualResult = $this->viewHelper->initializeArgumentsAndRender();
         $this->assertSame($source, $actualResult);
     }
 
@@ -75,7 +102,13 @@ class HtmlentitiesDecodeViewHelperTest extends UnitTestCase
     {
         $source = 'Some special characters: &amp; &quot; \' &lt; &gt; *';
         $expectedResult = 'Some special characters: & " \' < > *';
-        $actualResult = $this->viewHelper->render($source);
+        $this->setArgumentsUnderTest(
+            $this->viewHelper,
+            [
+                'value' => $source
+            ]
+        );
+        $actualResult = $this->viewHelper->initializeArgumentsAndRender();
         $this->assertEquals($expectedResult, $actualResult);
     }
 
@@ -86,7 +119,14 @@ class HtmlentitiesDecodeViewHelperTest extends UnitTestCase
     {
         $source = 'Some special characters: &amp; &quot; \' &lt; &gt; *';
         $expectedResult = 'Some special characters: & &quot; \' < > *';
-        $actualResult = $this->viewHelper->render($source, true);
+        $this->setArgumentsUnderTest(
+            $this->viewHelper,
+            [
+                'value' => $source,
+                'keepQuotes' => true,
+            ]
+        );
+        $actualResult = $this->viewHelper->initializeArgumentsAndRender();
         $this->assertEquals($expectedResult, $actualResult);
     }
 
@@ -97,7 +137,14 @@ class HtmlentitiesDecodeViewHelperTest extends UnitTestCase
     {
         $source = utf8_decode('Some special characters: &amp; &quot; \' &lt; &gt; *');
         $expectedResult = 'Some special characters: & " \' < > *';
-        $actualResult = $this->viewHelper->render($source, false, 'ISO-8859-1');
+        $this->setArgumentsUnderTest(
+            $this->viewHelper,
+            [
+                'value' => $source,
+                'encoding' => 'ISO-8859-1',
+            ]
+        );
+        $actualResult = $this->viewHelper->initializeArgumentsAndRender();
         $this->assertEquals($expectedResult, $actualResult);
     }
 
@@ -107,7 +154,13 @@ class HtmlentitiesDecodeViewHelperTest extends UnitTestCase
     public function renderReturnsUnmodifiedSourceIfItIsNoString()
     {
         $source = new \stdClass();
-        $actualResult = $this->viewHelper->render($source);
+        $this->setArgumentsUnderTest(
+            $this->viewHelper,
+            [
+                'value' => $source
+            ]
+        );
+        $actualResult = $this->viewHelper->render();
         $this->assertSame($source, $actualResult);
     }
 }