[BUGFIX] Remove empty option tag in fluid select viewhelper 88/51388/8
authorMarcus Schwemer <ms@schwemer.de>
Sun, 22 Jan 2017 21:24:39 +0000 (22:24 +0100)
committerJigal van Hemert <jigal.van.hemert@typo3.org>
Wed, 1 Feb 2017 18:35:40 +0000 (19:35 +0100)
Currently the select viewhelper produces an empty option tag, if no
argument "option" is provided. This is not needed.

Resolves: #79274
Releases: master
Change-Id: Ie3a78f241cba19875c866bbc44c48d58603a1e91
Reviewed-on: https://review.typo3.org/51388
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Claus Due <claus@phpmind.net>
Tested-by: Claus Due <claus@phpmind.net>
Reviewed-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
Tested-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
typo3/sysext/fluid/Classes/ViewHelpers/Form/SelectViewHelper.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Form/SelectViewHelperTest.php

index 672c9d2..3d35fa4 100644 (file)
@@ -126,9 +126,6 @@ class SelectViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFie
         }
         $this->tag->addAttribute('name', $name);
         $options = $this->getOptions();
-        if (empty($options)) {
-            $options = ['' => ''];
-        }
 
         $this->addAdditionalIdentityPropertiesIfNeeded();
         $this->setErrorClassAttribute();
@@ -163,6 +160,7 @@ class SelectViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFie
             $tagContent .= $childContent;
         }
 
+        $this->tag->forceClosingTag(true);
         $this->tag->setContent($tagContent);
         $content .= $this->tag->render();
         return $content;
index 8259cbb..43b9c68 100644 (file)
@@ -187,25 +187,6 @@ class SelectViewHelperTest extends ViewHelperBaseTestcase
         $this->viewHelper->render();
     }
 
-    /**
-     * @test
-     */
-    public function anEmptyOptionTagIsRenderedIfOptionsArrayIsEmptyToAssureXhtmlCompatibility()
-    {
-        $this->tagBuilder->expects($this->once())->method('addAttribute')->with('name', 'myName');
-        $this->viewHelper->expects($this->once())->method('registerFieldNameForFormTokenGeneration')->with('myName');
-        $this->tagBuilder->expects($this->once())->method('setContent')->with('<option value=""></option>' . chr(10));
-        $this->tagBuilder->expects($this->once())->method('render');
-
-        $this->arguments['options'] = [];
-        $this->arguments['value'] = 'value2';
-        $this->arguments['name'] = 'myName';
-        $this->injectDependenciesIntoViewHelper($this->viewHelper);
-        $this->viewHelper->_set('tag', $this->tagBuilder);
-        $this->viewHelper->initialize();
-        $this->viewHelper->render();
-    }
-
     /**
      * @test
      */