[FEATURE] Introduce prepend option for Select ViewHelper
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / Unit / ViewHelpers / Form / SelectViewHelperTest.php
index c133550..a65818a 100644 (file)
@@ -383,6 +383,47 @@ class SelectViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\
                $this->viewHelper->initialize();
                $this->viewHelper->render();
        }
+
+       /**
+        * @test
+        */
+       public function optionsContainPrependedItemWithEmptyValueIfPrependOptionLabelIsSet() {
+               $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="">please choose</option>' . chr(10) . '<option value="value1">label1</option>' . chr(10) . '<option value="value2">label2</option>' . chr(10) . '<option value="value3">label3</option>' . chr(10));
+               $this->tagBuilder->expects($this->once())->method('render');
+               $this->arguments['options'] = array(
+                       'value1' => 'label1',
+                       'value2' => 'label2',
+                       'value3' => 'label3'
+               );
+               $this->arguments['name'] = 'myName';
+               $this->arguments['prependOptionLabel'] = 'please choose';
+               $this->injectDependenciesIntoViewHelper($this->viewHelper);
+               $this->viewHelper->initialize();
+               $this->viewHelper->render();
+       }
+
+       /**
+        * @test
+        */
+       public function optionsContainPrependedItemWithCorrectValueIfPrependOptionLabelAndPrependOptionValueAreSet() {
+               $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="-1">please choose</option>' . chr(10) . '<option value="value1">label1</option>' . chr(10) . '<option value="value2">label2</option>' . chr(10) . '<option value="value3">label3</option>' . chr(10));
+               $this->tagBuilder->expects($this->once())->method('render');
+               $this->arguments['options'] = array(
+                       'value1' => 'label1',
+                       'value2' => 'label2',
+                       'value3' => 'label3'
+               );
+               $this->arguments['name'] = 'myName';
+               $this->arguments['prependOptionLabel'] = 'please choose';
+               $this->arguments['prependOptionValue'] = '-1';
+               $this->injectDependenciesIntoViewHelper($this->viewHelper);
+               $this->viewHelper->initialize();
+               $this->viewHelper->render();
+       }
 }
 
-?>
\ No newline at end of file
+?>