[TASK] Move arguments to initializeArguments() in ButtonVH in ext:fluid 99/48899/4
authorRoberto Torresani <erreti@gmail.com>
Mon, 11 Jul 2016 13:49:25 +0000 (15:49 +0200)
committerSusanne Moog <typo3@susannemoog.de>
Fri, 15 Jul 2016 18:20:22 +0000 (20:20 +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

Resolves: #77018
Releases: master
Change-Id: Ibb541f765f5306be9d188668b4db331a95b02995
Reviewed-on: https://review.typo3.org/48899
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
Tested-by: Bamboo TYPO3com <info@typo3.com>
Tested-by: Anna Färber <anna.faerber@dkd.de>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Susanne Moog <typo3@susannemoog.de>
Tested-by: Susanne Moog <typo3@susannemoog.de>
typo3/sysext/fluid/Classes/ViewHelpers/Form/ButtonViewHelper.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Form/ButtonViewHelperTest.php

index 0eb9be2..4ebe9eb 100644 (file)
@@ -35,7 +35,7 @@ namespace TYPO3\CMS\Fluid\ViewHelpers\Form;
  *
  * @api
  */
-class ButtonViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper
+class ButtonViewHelper extends AbstractFormFieldViewHelper
 {
     /**
      * @var string
@@ -46,6 +46,7 @@ class ButtonViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFie
      * Initialize the arguments.
      *
      * @return void
+     * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception
      * @api
      */
     public function initializeArguments()
@@ -79,17 +80,18 @@ class ButtonViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFie
             'Specifies where to display the response after submitting the form. Only for type="submit" (e.g. "_blank", "_self", "_parent", "_top", "framename")'
         );
         $this->registerUniversalTagAttributes();
+        $this->registerArgument('type', 'string', 'Specifies the type of button (e.g. "button", "reset" or "submit")', false, 'submit');
     }
 
     /**
      * Renders the button.
      *
-     * @param string $type Specifies the type of button (e.g. "button", "reset" or "submit")
      * @return string
      * @api
      */
-    public function render($type = 'submit')
+    public function render()
     {
+        $type = $this->arguments['type'];
         $name = $this->getName();
         $this->registerFieldNameForFormTokenGeneration($name);
 
index b9baad3..e67ebe4 100644 (file)
@@ -13,25 +13,24 @@ namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form;
  *
  * The TYPO3 project - inspiring people to share!
  */
-use TYPO3Fluid\Fluid\Core\ViewHelper\TagBuilder;
+use TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHelperBaseTestcase;
+use TYPO3\CMS\Fluid\ViewHelpers\Form\ButtonViewHelper;
 
 /**
  * Test for the "Button" Form view helper
  */
-class ButtonViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\FormFieldViewHelperBaseTestcase
+class ButtonViewHelperTest extends ViewHelperBaseTestcase
 {
     /**
-     * @var \TYPO3\CMS\Fluid\ViewHelpers\Form\ButtonViewHelper
+     * @var ButtonViewHelper
      */
     protected $viewHelper;
 
     protected function setUp()
     {
         parent::setUp();
-        $this->viewHelper = $this->getAccessibleMock(\TYPO3\CMS\Fluid\ViewHelpers\Form\ButtonViewHelper::class, array('renderChildren'));
-        $this->arguments['name'] = '';
+        $this->viewHelper = new ButtonViewHelper();
         $this->injectDependenciesIntoViewHelper($this->viewHelper);
-        $this->viewHelper->initializeArguments();
     }
 
     /**
@@ -39,20 +38,21 @@ class ButtonViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\
      */
     public function renderCorrectlySetsTagNameAndDefaultAttributes()
     {
-        $mockTagBuilder = $this->getMockBuilder(TagBuilder::class)
-            ->setMethods(array('setTagName', 'addAttribute', 'setContent'))
-            ->getMock();
-        $mockTagBuilder->expects($this->once())->method('setTagName')->with('button');
-        $mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'submit');
-        $mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', '');
-        $mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', '');
-        $mockTagBuilder->expects($this->at(4))->method('setContent')->with('Button Content');
+        $this->viewHelper->setRenderChildrenClosure(
+            function () {
+                return 'Button Content';
+            }
+        );
 
-        $this->viewHelper->expects($this->atLeastOnce())->method('renderChildren')->will($this->returnValue('Button Content'));
+        $this->setArgumentsUnderTest(
+            $this->viewHelper,
+            [
+                'type' => 'submit'
+            ]
+        );
 
-        $this->viewHelper->_set('tag', $mockTagBuilder);
-
-        $this->viewHelper->initialize();
-        $this->viewHelper->render();
+        $expectedResult = '<button type="submit" name="" value="">Button Content</button>';
+        $actualResult = $this->viewHelper->initializeArgumentsAndRender();
+        $this->assertEquals($expectedResult, $actualResult);
     }
 }