[TASK] Move ViewHelper arguments to initializeArguments() in ext:fluid 03/48903/4
authorAnna Färber <anna.faerber@dkd.de>
Mon, 11 Jul 2016 14:44:20 +0000 (16:44 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Mon, 11 Jul 2016 16:16:18 +0000 (18:16 +0200)
CaseViewHelperTest, Format/CaseViewHelperTest and
Format/CaseViewHelperTest are affected.

Resolves: #77005
Releases: master
Change-Id: I899a51382176071e210cfdf20d662ad4ac28d466
Reviewed-on: https://review.typo3.org/48903
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
Tested-by: Bamboo TYPO3com <info@typo3.com>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/fluid/Classes/ViewHelpers/CaseViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/Format/CaseViewHelper.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Format/CaseViewHelperTest.php

index c12562c..9e95da6 100644 (file)
@@ -31,20 +31,28 @@ class CaseViewHelper extends AbstractViewHelper
     protected $escapeOutput = false;
 
     /**
-     * @param mixed $value The switch value. If it matches, the child will be rendered
-     * @param bool $default If this is set, this child will be rendered, if none else matches
+     * Initialize ViewHelper arguments
      *
+     * @return void
+     */
+    public function initializeArguments()
+    {
+        $this->registerArgument('value', 'mixed', 'The switch value. If it matches, the child will be rendered.', false, null);
+        $this->registerArgument('default', 'bool', 'If this is set, this child will be rendered, if none else matches.', false, false);
+    }
+
+    /***
      * @return string the contents of this view helper if $value equals the expression of the surrounding switch view helper, or $default is TRUE. otherwise an empty string
      * @throws Exception
      *
      * @api
      */
-    public function render($value = null, $default = false)
+    public function render()
     {
         return static::renderStatic(
             array(
-                'value' => $value,
-                'default' => $default
+                'value' => $this->arguments['value'],
+                'default' => $this->arguments['default']
             ),
             $this->buildRenderChildrenClosure(),
             $this->renderingContext
index 59f0be8..ba3e327 100644 (file)
@@ -103,20 +103,29 @@ class CaseViewHelper extends AbstractViewHelper
      */
     protected static $charsetConverter = null;
 
+    /**
+     * Initialize ViewHelper arguments
+     *
+     * @return void
+     */
+    public function initializeArguments()
+    {
+        $this->registerArgument('value', 'string', 'The input value. If not given, the evaluated child nodes will be used.', false, null);
+        $this->registerArgument('mode', 'string', 'The case to apply, must be one of this\' CASE_* constants. Defaults to uppercase application.', false, self::CASE_UPPER);
+    }
+
     /**
      * Changes the case of the input string
      *
-     * @param string $value The input value. If not given, the evaluated child nodes will be used
-     * @param string $mode The case to apply, must be one of this' CASE_* constants. Defaults to uppercase application
      * @return string the altered string.
      * @api
      */
-    public function render($value = null, $mode = self::CASE_UPPER)
+    public function render()
     {
         return static::renderStatic(
             array(
-                'value' => $value,
-                'mode' => $mode,
+                'value' => $this->arguments['value'],
+                'mode' => $this->arguments['mode']
             ),
             $this->buildRenderChildrenClosure(),
             $this->renderingContext
index e92087f..8525a5c 100644 (file)
@@ -22,17 +22,15 @@ use TYPO3\CMS\Fluid\ViewHelpers\Format\CaseViewHelper;
 class CaseViewHelperTest extends ViewHelperBaseTestcase
 {
     /**
-     * @var CaseViewHelper|\PHPUnit_Framework_MockObject_MockObject
+     * @var CaseViewHelper
      */
-    protected $subject;
+    protected $viewHelper;
 
     protected function setUp()
     {
         parent::setUp();
-        $this->subject = $this->getMockBuilder(CaseViewHelper::class)
-            ->setMethods(array('renderChildren'))
-            ->getMock();
-        $this->injectDependenciesIntoViewHelper($this->subject);
+        $this->viewHelper = new CaseViewHelper();
+        $this->injectDependenciesIntoViewHelper($this->viewHelper);
     }
 
     /**
@@ -40,8 +38,14 @@ class CaseViewHelperTest extends ViewHelperBaseTestcase
      */
     public function viewHelperRendersChildrenIfGivenValueIsNull()
     {
-        $this->subject->expects($this->once())->method('renderChildren');
-        $this->subject->render();
+        $this->setArgumentsUnderTest(
+            $this->viewHelper,
+            [
+                'value' => ''
+            ]
+        );
+        $actualResult = $this->viewHelper->initializeArgumentsAndRender();
+        $this->assertEquals('', $actualResult);
     }
 
     /**
@@ -49,10 +53,14 @@ class CaseViewHelperTest extends ViewHelperBaseTestcase
      */
     public function viewHelperDoesNotRenderChildrenIfGivenValueIsNotNull()
     {
-        $this->subject->expects($this->never())->method('renderChildren');
-        $this->subject->render('');
-        $this->subject->render(0);
-        $this->subject->render('foo');
+        $this->setArgumentsUnderTest(
+            $this->viewHelper,
+            [
+                'value' => 'Some string'
+            ]
+        );
+        $actualResult = $this->viewHelper->initializeArgumentsAndRender();
+        $this->assertEquals('SOME STRING', $actualResult);
     }
 
     /**
@@ -62,8 +70,14 @@ class CaseViewHelperTest extends ViewHelperBaseTestcase
     {
         $this->expectException(\TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException::class);
         $this->expectExceptionCode(1358349150);
-
-        $this->subject->render('Foo', 'incorrectMode');
+        $this->setArgumentsUnderTest(
+            $this->viewHelper,
+            [
+                'value' => 'Foo',
+                'mode' => 'incorrectMode'
+            ]
+        );
+        $this->viewHelper->initializeArgumentsAndRender();
     }
 
     /**
@@ -71,7 +85,14 @@ class CaseViewHelperTest extends ViewHelperBaseTestcase
      */
     public function viewHelperConvertsUppercasePerDefault()
     {
-        $this->assertSame('FOOB4R', $this->subject->render('FooB4r'));
+        $this->setArgumentsUnderTest(
+            $this->viewHelper,
+            [
+                'value' => 'FooB4r'
+            ]
+        );
+        $actualResult = $this->viewHelper->initializeArgumentsAndRender();
+        $this->assertSame('FOOB4R', $actualResult);
     }
 
     /**
@@ -97,6 +118,14 @@ class CaseViewHelperTest extends ViewHelperBaseTestcase
      */
     public function viewHelperConvertsCorrectly($input, $mode, $expected)
     {
-        $this->assertSame($expected, $this->subject->render($input, $mode), sprintf('The conversion with mode "%s" did not perform as expected.', $mode));
+        $this->setArgumentsUnderTest(
+            $this->viewHelper,
+            [
+                'value' => $input,
+                'mode' => $mode
+            ]
+        );
+        $actualResult = $this->viewHelper->initializeArgumentsAndRender();
+        $this->assertSame($expected, $actualResult, sprintf('The conversion with mode "%s" did not perform as expected.', $mode));
     }
 }