‪TYPO3CMS  9.5
OptionViewHelperTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
20 use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
21 use TYPO3Fluid\Fluid\Core\ViewHelper\TagBuilder;
22 
26 class ‪OptionViewHelperTest extends ViewHelperBaseTestcase
27 {
31  protected ‪$viewHelper;
32 
33  protected function ‪setUp(): void
34  {
35  parent::setUp();
36  $this->viewHelper = $this->getMockBuilder(OptionViewHelper::class)
37  ->setMethods(['isValueSelected', 'registerFieldNameForFormTokenGeneration', 'renderChildren'])
38  ->getMock();
39  $this->arguments['selected'] = null;
40  $this->arguments['value'] = null;
41  $this->tagBuilder = new TagBuilder();
42  $this->viewHelper->setTagBuilder($this->tagBuilder);
43  $this->injectDependenciesIntoViewHelper($this->viewHelper);
44  }
45 
49  public function ‪optionTagNameIsSet(): void
50  {
51  $tagBuilder = $this->createMock(TagBuilder::class);
52  $tagBuilder->expects($this->atLeastOnce())->method('setTagName')->with('option');
53  $this->viewHelper->setTagBuilder($tagBuilder);
54  $this->viewHelper->initializeArgumentsAndRender();
55  }
56 
61  {
62  $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('Option Label'));
63  $expected = '<option value="Option Label">Option Label</option>';
64  $this->assertEquals($expected, $this->viewHelper->initializeArgumentsAndRender());
65  }
66 
70  public function ‪valueCanBeOverwrittenByArgument(): void
71  {
72  $this->arguments['value'] = 'value';
73  $this->viewHelper->setArguments($this->arguments);
74  $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('Option Label'));
75  $expected = '<option value="value">Option Label</option>';
76  $this->assertEquals($expected, $this->viewHelper->initializeArgumentsAndRender());
77  }
78 
83  {
84  $this->arguments['selected'] = null;
85  $this->viewHelper->setArguments($this->arguments);
86 
87  $this->viewHelper->expects($this->once())->method('isValueSelected')->will($this->returnValue(true));
88  $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('Option Label'));
89 
90  $expected = '<option selected="selected" value="Option Label">Option Label</option>';
91  $this->assertEquals($expected, $this->viewHelper->initializeArgumentsAndRender());
92  }
93 
98  {
99  $this->arguments['selected'] = null;
100  $this->viewHelper->setArguments($this->arguments);
101 
102  $this->viewHelper->expects($this->once())->method('isValueSelected')->will($this->returnValue(false));
103  $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('Option Label'));
104 
105  $expected = '<option value="Option Label">Option Label</option>';
106  $this->assertEquals($expected, $this->viewHelper->initializeArgumentsAndRender());
107  }
108 
113  {
114  $this->arguments['selected'] = false;
115  $this->viewHelper->setArguments($this->arguments);
116  $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('Option Label'));
117 
118  $expected = '<option value="Option Label">Option Label</option>';
119  $this->assertEquals($expected, $this->viewHelper->initializeArgumentsAndRender());
120  }
121 
125  public function ‪selectedIsAddedToOptionForExplicitOverride(): void
126  {
127  $this->arguments['selected'] = true;
128  $this->viewHelper->setArguments($this->arguments);
129  $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('Option Label'));
130 
131  $expected = '<option selected="selected" value="Option Label">Option Label</option>';
132  $this->assertEquals($expected, $this->viewHelper->initializeArgumentsAndRender());
133  }
134 }
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Select\OptionViewHelperTest\valueCanBeOverwrittenByArgument
‪valueCanBeOverwrittenByArgument()
Definition: OptionViewHelperTest.php:69
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Select\OptionViewHelperTest\childrenContentIsUsedAsValueAndLabelByDefault
‪childrenContentIsUsedAsValueAndLabelByDefault()
Definition: OptionViewHelperTest.php:59
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Select\OptionViewHelperTest\selectedIsNotAddedToUnselectedOptionForNoSelectionOverride
‪selectedIsNotAddedToUnselectedOptionForNoSelectionOverride()
Definition: OptionViewHelperTest.php:96
‪TYPO3\CMS\Fluid\ViewHelpers\Form\Select\OptionViewHelper
Definition: OptionViewHelper.php:22
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Select\OptionViewHelperTest\setUp
‪setUp()
Definition: OptionViewHelperTest.php:32
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Select
Definition: OptionViewHelperTest.php:4
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Select\OptionViewHelperTest\$viewHelper
‪OptionViewHelper PHPUnit_Framework_MockObject_MockObject $viewHelper
Definition: OptionViewHelperTest.php:30
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Select\OptionViewHelperTest\selectedIsNotAddedToOptionForExplicitOverride
‪selectedIsNotAddedToOptionForExplicitOverride()
Definition: OptionViewHelperTest.php:111
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Select\OptionViewHelperTest\selectedIsAddedToOptionForExplicitOverride
‪selectedIsAddedToOptionForExplicitOverride()
Definition: OptionViewHelperTest.php:124
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Select\OptionViewHelperTest
Definition: OptionViewHelperTest.php:27
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Select\OptionViewHelperTest\optionTagNameIsSet
‪optionTagNameIsSet()
Definition: OptionViewHelperTest.php:48
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Select\OptionViewHelperTest\selectedIsAddedToSelectedOptionForNoSelectionOverride
‪selectedIsAddedToSelectedOptionForNoSelectionOverride()
Definition: OptionViewHelperTest.php:81