TYPO3 CMS  TYPO3_8-7
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 
23 
27 class OptionViewHelperTest extends ViewHelperBaseTestcase
28 {
32  protected $viewHelper;
33 
34  protected function setUp()
35  {
36  parent::setUp();
37  $this->viewHelper = $this->getAccessibleMock(
38  OptionViewHelper::class,
39  ['isValueSelected', 'registerFieldNameForFormTokenGeneration', 'renderChildren']
40  );
41  $this->arguments['selected'] = null;
42  $this->arguments['value'] = null;
43  $this->tagBuilder = new TagBuilder();
44  $this->viewHelper->_set('tag', $this->tagBuilder);
45  $this->injectDependenciesIntoViewHelper($this->viewHelper);
46  }
47 
51  public function optionTagNameIsSet()
52  {
53  $tagBuilder = $this->createMock(TagBuilder::class);
54  $tagBuilder->expects($this->once())->method('setTagName')->with('option');
55 
56  $this->viewHelper->_set('tag', $tagBuilder);
57  $this->viewHelper->initializeArgumentsAndRender();
58  }
59 
64  {
65  $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('Option Label'));
66  $expected = '<option value="Option Label">Option Label</option>';
67  $this->assertEquals($expected, $this->viewHelper->initializeArgumentsAndRender());
68  }
69 
74  {
75  $this->arguments['value'] = 'value';
76  $this->viewHelper->setArguments($this->arguments);
77  $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('Option Label'));
78  $expected = '<option value="value">Option Label</option>';
79  $this->assertEquals($expected, $this->viewHelper->initializeArgumentsAndRender());
80  }
81 
86  {
87  $this->arguments['selected'] = null;
88  $this->viewHelper->setArguments($this->arguments);
89 
90  $this->viewHelper->expects($this->once())->method('isValueSelected')->will($this->returnValue(true));
91  $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('Option Label'));
92 
93  $expected = '<option selected="selected" value="Option Label">Option Label</option>';
94  $this->assertEquals($expected, $this->viewHelper->initializeArgumentsAndRender());
95  }
96 
101  {
102  $this->arguments['selected'] = null;
103  $this->viewHelper->setArguments($this->arguments);
104 
105  $this->viewHelper->expects($this->once())->method('isValueSelected')->will($this->returnValue(false));
106  $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('Option Label'));
107 
108  $expected = '<option value="Option Label">Option Label</option>';
109  $this->assertEquals($expected, $this->viewHelper->initializeArgumentsAndRender());
110  }
111 
116  {
117  $this->arguments['selected'] = false;
118  $this->viewHelper->setArguments($this->arguments);
119  $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('Option Label'));
120 
121  $expected = '<option value="Option Label">Option Label</option>';
122  $this->assertEquals($expected, $this->viewHelper->initializeArgumentsAndRender());
123  }
124 
129  {
130  $this->arguments['selected'] = true;
131  $this->viewHelper->setArguments($this->arguments);
132  $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('Option Label'));
133 
134  $expected = '<option selected="selected" value="Option Label">Option Label</option>';
135  $this->assertEquals($expected, $this->viewHelper->initializeArgumentsAndRender());
136  }
137 }