TYPO3 CMS  TYPO3_8-7
RadioViewHelperTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
20 
24 class RadioViewHelperTest extends ViewHelperBaseTestcase
25 {
29  protected $viewHelper;
30 
31  protected function setUp()
32  {
33  parent::setUp();
34  $this->viewHelper = new RadioViewHelper();
35  $this->injectDependenciesIntoViewHelper($this->viewHelper);
36  }
37 
42  {
43  $this->setArgumentsUnderTest(
44  $this->viewHelper,
45  [
46  'name' => 'foo',
47  ]
48  );
49  $expectedResult = '<input type="radio" name="foo" value="" />';
50  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
51  $this->assertEquals($expectedResult, $actualResult);
52  }
53 
58  {
59  $this->setArgumentsUnderTest(
60  $this->viewHelper,
61  [
62  'name' => 'foo',
63  'checked' => true,
64  ]
65  );
66  $expectedResult = '<input type="radio" name="foo" value="" checked="checked" />';
67  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
68  $this->assertEquals($expectedResult, $actualResult);
69  }
70 
75  {
76  $this->setArgumentsUnderTest(
77  $this->viewHelper,
78  [
79  'value' => 'foo',
80  'property' => 'someProperty',
81  'checked' => true
82  ]
83  );
84  $formObject = new \stdClass();
85  $formObject->someProperty = false;
86 
87  $this->stubVariableContainer($formObject);
88  $this->stubRequestWithoutMappingErrors();
89 
90  $result = $this->viewHelper->initializeArgumentsAndRender();
91 
92  $this->assertContains(
93  '<input type="radio" name="fieldPrefix[objectName][someProperty]" value="foo" checked="checked" />',
94  $result
95  );
96  }
97 
102  {
103  $this->setArgumentsUnderTest(
104  $this->viewHelper,
105  [
106  'value' => 'foo',
107  'property' => 'someProperty',
108  ]
109  );
110 
111  $formObject = new \stdClass();
112  $formObject->someProperty = true;
113 
114  $this->stubVariableContainer($formObject);
115  $this->stubRequestWithoutMappingErrors();
116 
117  $result = $this->viewHelper->initializeArgumentsAndRender();
118 
119  $this->assertContains(
120  '<input type="radio" name="fieldPrefix[objectName][someProperty]" value="foo" checked="checked" />',
121  $result
122  );
123  }
124 
129  {
130  $this->setArgumentsUnderTest(
131  $this->viewHelper,
132  [
133  'value' => 'foo',
134  'property' => 'someProperty',
135  ]
136  );
137 
138  $formObject = new \stdClass();
139  $formObject->someProperty = [];
140 
141  $this->stubVariableContainer($formObject);
142  $this->stubRequestWithoutMappingErrors();
143 
144  $result = $this->viewHelper->initializeArgumentsAndRender();
145 
146  $this->assertContains(
147  '<input type="radio" name="fieldPrefix[objectName][someProperty]" value="foo" />',
148  $result
149  );
150  }
151 
156  {
157  $this->setArgumentsUnderTest(
158  $this->viewHelper,
159  [
160  'value' => 'foo',
161  'property' => 'someProperty',
162  ]
163  );
164 
165  $formObject = new \stdClass();
166  $formObject->someProperty = '';
167 
168  $this->stubVariableContainer($formObject);
169  $this->stubRequestWithoutMappingErrors();
170 
171  $result = $this->viewHelper->initializeArgumentsAndRender();
172 
173  $this->assertContains(
174  '<input type="radio" name="fieldPrefix[objectName][someProperty]" value="foo" />',
175  $result
176  );
177  }
178 
183  {
184  $this->setArgumentsUnderTest(
185  $this->viewHelper,
186  [
187  'value' => 'foo',
188  'property' => 'someProperty',
189  ]
190  );
191 
192  $formObject = new \stdClass();
193  $formObject->someProperty = null;
194 
195  $this->stubVariableContainer($formObject);
196  $this->stubRequestWithoutMappingErrors();
197 
198  $result = $this->viewHelper->initializeArgumentsAndRender();
199 
200  $this->assertContains(
201  '<input type="radio" name="fieldPrefix[objectName][someProperty]" value="foo" />',
202  $result
203  );
204  }
205 
210  {
211  $this->setArgumentsUnderTest(
212  $this->viewHelper,
213  [
214  'value' => 2,
215  'property' => 'someProperty',
216  ]
217  );
218 
219  $property1 = new \stdClass();
220  $property2 = new \stdClass();
221  $property3 = new \stdClass();
222 
223  $persistenceManager = $this->prophesize(PersistenceManager::class);
224  $persistenceManager->getIdentifierByObject($property1)->willReturn(1);
225  $persistenceManager->getIdentifierByObject($property2)->willReturn(2);
226  $persistenceManager->getIdentifierByObject($property3)->willReturn(3);
227  $this->viewHelper->injectPersistenceManager($persistenceManager->reveal());
228 
229  $formObject = new \stdClass();
230  $formObject->someProperty = [$property1, $property2, $property3];
231 
232  $this->stubVariableContainer($formObject);
233  $this->stubRequestWithoutMappingErrors();
234 
235  $result = $this->viewHelper->initializeArgumentsAndRender();
236 
237  $this->assertContains(
238  '<input type="radio" name="fieldPrefix[objectName][someProperty]" value="2" />',
239  $result
240  );
241  }
242 
247  {
248  $this->setArgumentsUnderTest(
249  $this->viewHelper,
250  [
251  'value' => 'foo',
252  'property' => 'someProperty',
253  'errorClass' => 'error',
254  ]
255  );
256 
257  $formObject = new \stdClass();
258  $formObject->someProperty = null;
259 
260  $this->stubVariableContainer($formObject);
261  $this->stubRequestWithMappingErrors();
262 
263  $result = $this->viewHelper->initializeArgumentsAndRender();
264 
265  $this->assertContains(
266  '<input type="radio" name="fieldPrefix[objectName][someProperty]" value="foo" class="error" />',
267  $result
268  );
269  }
270 
275  {
276  $this->setArgumentsUnderTest(
277  $this->viewHelper,
278  [
279  'value' => 'foo',
280  'property' => 'someProperty',
281  ]
282  );
283 
284  $formObject = new \stdClass();
285  $formObject->someProperty = null;
286 
287  $this->stubVariableContainer($formObject);
288  $this->stubRequestWithMappingErrors();
289 
290  $result = $this->viewHelper->initializeArgumentsAndRender();
291 
292  $this->assertContains(
293  '<input type="radio" name="fieldPrefix[objectName][someProperty]" value="foo" class="f3-form-error" />',
294  $result
295  );
296  }
297 
302  {
303  $this->setArgumentsUnderTest(
304  $this->viewHelper,
305  [
306  'value' => 'foo',
307  'property' => 'someProperty',
308  'class' => 'css_class'
309  ]
310  );
311 
312  $formObject = new \stdClass();
313  $formObject->someProperty = null;
314 
315  $this->stubVariableContainer($formObject);
316  $this->stubRequestWithMappingErrors();
317 
318  $result = $this->viewHelper->initializeArgumentsAndRender();
319 
320  $this->assertContains(
321  '<input class="css_class f3-form-error" type="radio" name="fieldPrefix[objectName][someProperty]" value="foo" />',
322  $result
323  );
324  }
325 }