[TASK] Move ViewHelper arguments to initializeArguments() in ext:fluid 08/48908/10
authorivaylo.ivanov <ivaylo.ivanov@dkd.de>
Mon, 11 Jul 2016 15:53:26 +0000 (17:53 +0200)
committerSusanne Moog <typo3@susannemoog.de>
Tue, 19 Jul 2016 07:51:11 +0000 (09:51 +0200)
UrlencodeViewHelperTest is affected.
UrlencodeViewHelper is affected.

Resolves: #77002
Releases: master
Change-Id: I16c0f02d9a49649323c09b58b407dffbfeea71ed
Reviewed-on: https://review.typo3.org/48908
Reviewed-by: Joerg Boesche <typo3@joergboesche.de>
Tested-by: Joerg Boesche <typo3@joergboesche.de>
Tested-by: Bamboo TYPO3com <info@typo3.com>
Reviewed-by: Susanne Moog <typo3@susannemoog.de>
Tested-by: Susanne Moog <typo3@susannemoog.de>
typo3/sysext/fluid/Classes/ViewHelpers/Format/UrlencodeViewHelper.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Format/UrlencodeViewHelperTest.php

index a698222..11a3795 100644 (file)
@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Format;
 
 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
+use TYPO3Fluid\Fluid\Core\ViewHelper\Exception;
 
 /**
  * Encodes the given string according to http://www.faqs.org/rfcs/rfc3986.html (applying PHPs rawurlencode() function)
@@ -50,30 +51,29 @@ class UrlencodeViewHelper extends AbstractViewHelper
     protected $escapeChildren = false;
 
     /**
-     * Initialize arguments.
+     * Initialize ViewHelper arguments
      *
      * @api
-     * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception
+     * @return void
+     * @throws Exception
      */
     public function initializeArguments()
     {
+        parent::initializeArguments();
         $this->registerArgument('value', 'string', 'string to format');
     }
 
     /**
      * Escapes special characters with their escaped counterparts as needed using PHPs rawurlencode() function.
      *
-     * @return mixed
      * @see http://www.php.net/manual/function.rawurlencode.php
      * @api
+     * @return mixed
      */
     public function render()
     {
-        $value = $this->arguments['value'];
         return static::renderStatic(
-            array(
-                'value' => $value
-            ),
+            $this->arguments,
             $this->buildRenderChildrenClosure(),
             $this->renderingContext
         );
index 86f4dc7..35bdc58 100644 (file)
@@ -22,7 +22,7 @@ use TYPO3\CMS\Fluid\ViewHelpers\Format\UrlencodeViewHelper;
 class UrlencodeViewHelperTest extends ViewHelperBaseTestcase
 {
     /**
-     * @var \TYPO3\CMS\Fluid\ViewHelpers\Format\UrlencodeViewHelper
+     * @var UrlencodeViewHelper
      */
     protected $viewHelper;
 
@@ -53,16 +53,13 @@ class UrlencodeViewHelperTest extends ViewHelperBaseTestcase
      */
     public function renderUsesChildnodesAsSourceIfSpecified()
     {
-        $this->viewHelper->setRenderChildrenClosure(
-            function () {
-                return 'Source';
-            }
-        );
         $this->setArgumentsUnderTest(
             $this->viewHelper,
             [
+                'value' => 'Source'
             ]
         );
+
         $actualResult = $this->viewHelper->initializeArgumentsAndRender();
         $this->assertEquals('Source', $actualResult);
     }
@@ -73,6 +70,7 @@ class UrlencodeViewHelperTest extends ViewHelperBaseTestcase
     public function renderDoesNotModifyValueIfItDoesNotContainSpecialCharacters()
     {
         $source = 'StringWithoutSpecialCharacters';
+
         $this->setArgumentsUnderTest(
             $this->viewHelper,
             [
@@ -90,13 +88,33 @@ class UrlencodeViewHelperTest extends ViewHelperBaseTestcase
     {
         $source = 'Foo @+%/ "';
         $expectedResult = 'Foo%20%40%2B%25%2F%20%22';
+
         $this->setArgumentsUnderTest(
             $this->viewHelper,
             [
                 'value' => $source
             ]
         );
+
         $actualResult = $this->viewHelper->initializeArgumentsAndRender();
         $this->assertEquals($expectedResult, $actualResult);
     }
+
+    /**
+     * @test
+     */
+    public function renderReturnsUnmodifiedSourceIfItIsNoString()
+    {
+        $source = new \stdClass();
+
+        $this->setArgumentsUnderTest(
+            $this->viewHelper,
+            [
+                'value' => $source
+            ]
+        );
+
+        $actualResult = $this->viewHelper->render();
+        $this->assertSame($source, $actualResult);
+    }
 }