[TASK] Move arguments to initializeArguments() in Nl2brVH in ext:fluid 28/48928/3
authorRoberto Torresani <erreti@gmail.com>
Tue, 12 Jul 2016 10:59:33 +0000 (12:59 +0200)
committerSusanne Moog <typo3@susannemoog.de>
Tue, 19 Jul 2016 07:23:14 +0000 (09:23 +0200)
Move the argument registrations away from the render() method
to initializeArguments(), to prevent any errors with PHP7 and
subclassed ViewHelpers if/when render() method signatures change.
Change the UnitTest Nl2brViewHelperTest with setArguments()

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

index 22725f2..a8391c2 100644 (file)
@@ -47,14 +47,26 @@ class Nl2brViewHelper extends AbstractViewHelper
     protected $escapeOutput = false;
 
     /**
+     * Initialize arguments.
+     *
+     * @api
+     * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception
+     */
+    public function initializeArguments()
+    {
+        parent::initializeArguments();
+        $this->registerArgument('value', 'string', 'string to format');
+    }
+
+    /**
      * Replaces newline characters by HTML line breaks.
      *
-     * @param string $value string to format
      * @return string the altered string.
      * @api
      */
-    public function render($value = null)
+    public function render()
     {
+        $value = $this->arguments['value'];
         return static::renderStatic(
             array(
                 'value' => $value
index bf93455..35b5751 100644 (file)
@@ -29,11 +29,8 @@ class Nl2brViewHelperTest extends ViewHelperBaseTestcase
     protected function setUp()
     {
         parent::setUp();
-        $this->viewHelper = $this->getMockBuilder(Nl2brViewHelper::class)
-            ->setMethods(array('renderChildren'))
-            ->getMock();
+        $this->viewHelper = new Nl2brViewHelper();
         $this->injectDependenciesIntoViewHelper($this->viewHelper);
-        $this->viewHelper->initializeArguments();
     }
 
     /**
@@ -41,8 +38,17 @@ class Nl2brViewHelperTest extends ViewHelperBaseTestcase
      */
     public function viewHelperDoesNotModifyTextWithoutLineBreaks()
     {
-        $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('<p class="bodytext">Some Text without line breaks</p>'));
-        $actualResult = $this->viewHelper->render();
+        $this->viewHelper->setRenderChildrenClosure(
+            function () {
+                return '<p class="bodytext">Some Text without line breaks</p>';
+            }
+        );
+        $this->setArgumentsUnderTest(
+            $this->viewHelper,
+            [
+            ]
+        );
+        $actualResult = $this->viewHelper->initializeArgumentsAndRender();
         $this->assertEquals('<p class="bodytext">Some Text without line breaks</p>', $actualResult);
     }
 
@@ -51,8 +57,17 @@ class Nl2brViewHelperTest extends ViewHelperBaseTestcase
      */
     public function viewHelperConvertsLineBreaksToBRTags()
     {
-        $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('Line 1' . chr(10) . 'Line 2'));
-        $actualResult = $this->viewHelper->render();
+        $this->viewHelper->setRenderChildrenClosure(
+            function () {
+                return 'Line 1' . chr(10) . 'Line 2';
+            }
+        );
+        $this->setArgumentsUnderTest(
+            $this->viewHelper,
+            [
+            ]
+        );
+        $actualResult = $this->viewHelper->initializeArgumentsAndRender();
         $this->assertEquals('Line 1<br />' . chr(10) . 'Line 2', $actualResult);
     }
 
@@ -61,8 +76,17 @@ class Nl2brViewHelperTest extends ViewHelperBaseTestcase
      */
     public function viewHelperConvertsWindowsLineBreaksToBRTags()
     {
-        $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('Line 1' . chr(13) . chr(10) . 'Line 2'));
-        $actualResult = $this->viewHelper->render();
+        $this->viewHelper->setRenderChildrenClosure(
+            function () {
+                return 'Line 1' . chr(13) . chr(10) . 'Line 2';
+            }
+        );
+        $this->setArgumentsUnderTest(
+            $this->viewHelper,
+            [
+            ]
+        );
+        $actualResult = $this->viewHelper->initializeArgumentsAndRender();
         $this->assertEquals('Line 1<br />' . chr(13) . chr(10) . 'Line 2', $actualResult);
     }
 }