[!!!][BUGFIX] Correct "required"-parameter in TextfieldViewHelper 45/40645/6
authorFrederic Gaus <frederic.gaus@flagbit.de>
Thu, 25 Jun 2015 13:42:08 +0000 (15:42 +0200)
committerBenni Mack <benni@typo3.org>
Tue, 18 Aug 2015 19:13:20 +0000 (21:13 +0200)
Releases: master
Resolves: #67098
Change-Id: Ifc322aba2cf95849e1541cac4df65d30aeb56bc3
Reviewed-on: http://review.typo3.org/40645
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Daniel Goerz <ervaude@gmail.com>
Tested-by: Daniel Goerz <ervaude@gmail.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/core/Documentation/Changelog/master/Breaking-67098-CorrectRequired-parameterInTextfieldViewHelper.rst [new file with mode: 0644]
typo3/sysext/fluid/Classes/ViewHelpers/Form/TextfieldViewHelper.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Form/TextfieldViewHelperTest.php

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Breaking-67098-CorrectRequired-parameterInTextfieldViewHelper.rst b/typo3/sysext/core/Documentation/Changelog/master/Breaking-67098-CorrectRequired-parameterInTextfieldViewHelper.rst
new file mode 100644 (file)
index 0000000..1ae6ad6
--- /dev/null
@@ -0,0 +1,26 @@
+====================================================================
+Breaking: #67098 - Correct required-parameter in TextfieldViewHelper
+====================================================================
+
+Description
+===========
+
+The value comparison of the required parameter is corrected. Before, a textfield was required as soon as it had a parameter "required" set to any value. Even if this value was set to FALSE, the textfield was still required.
+
+
+Impact
+======
+
+Textfelds with required="FALSE" are not required any longer.
+
+
+Affected Installations
+======================
+
+Every installation that uses the textfield viewhelper with the required attribute.
+
+
+Migration
+=========
+
+none
\ No newline at end of file
index 7abe800..807c70a 100644 (file)
@@ -59,7 +59,7 @@ class TextfieldViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractForm
         * @return string
         * @api
         */
-       public function render($required = NULL, $type = 'text') {
+       public function render($required = FALSE, $type = 'text') {
                $name = $this->getName();
                $this->registerFieldNameForFormTokenGeneration($name);
                $this->setRespectSubmittedDataValue(TRUE);
@@ -73,7 +73,7 @@ class TextfieldViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractForm
                        $this->tag->addAttribute('value', $value);
                }
 
-               if ($required !== NULL) {
+               if ($required !== FALSE) {
                        $this->tag->addAttribute('required', 'required');
                }
 
index 4016c28..2747474 100644 (file)
@@ -95,4 +95,27 @@ class TextfieldViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Fo
                $this->viewHelper->render();
        }
 
+       /**
+        * @test
+        */
+       public function renderCorrectlySetsRequiredAttribute() {
+               $mockTagBuilder = $this->getMock(\TYPO3\CMS\Fluid\Core\ViewHelper\TagBuilder::class, array('addAttribute', 'setContent', 'render'), array(), '', FALSE);
+               $mockTagBuilder->expects($this->at(0))->method('addAttribute')->with('type', 'text');
+               $mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('name', 'NameOfTextfield');
+               $this->viewHelper->expects($this->once())->method('registerFieldNameForFormTokenGeneration')->with('NameOfTextfield');
+               $mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('value', 'Current value');
+               $mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('required', 'required');
+               $mockTagBuilder->expects($this->once())->method('render');
+               $this->viewHelper->_set('tag', $mockTagBuilder);
+
+               $arguments = array(
+                       'name' => 'NameOfTextfield',
+                       'value' => 'Current value'
+               );
+               $this->viewHelper->setArguments($arguments);
+
+               $this->viewHelper->setViewHelperNode(new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\EmptySyntaxTreeNode());
+               $this->viewHelper->initialize();
+               $this->viewHelper->render(TRUE);
+       }
 }