‪TYPO3CMS  10.4
RadioViewHelperTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
20 
25 {
29  protected ‪$viewHelper;
30 
31  protected function ‪setUp(): void
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  self::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  self::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);
89 
90  $result = $this->viewHelper->initializeArgumentsAndRender();
91 
92  self::assertStringContainsString(
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);
116 
117  $result = $this->viewHelper->initializeArgumentsAndRender();
118 
119  self::assertStringContainsString(
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);
143 
144  $result = $this->viewHelper->initializeArgumentsAndRender();
145 
146  self::assertStringContainsString(
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);
170 
171  $result = $this->viewHelper->initializeArgumentsAndRender();
172 
173  self::assertStringContainsString(
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);
197 
198  $result = $this->viewHelper->initializeArgumentsAndRender();
199 
200  self::assertStringContainsString(
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);
234 
235  $result = $this->viewHelper->initializeArgumentsAndRender();
236 
237  self::assertStringContainsString(
238  '<input type="radio" name="fieldPrefix[objectName][someProperty]" value="2" />',
239  $result
240  );
241  }
242 
246  public function ‪renderCallSetsErrorClassAttribute()
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);
262 
263  $result = $this->viewHelper->initializeArgumentsAndRender();
264 
265  self::assertStringContainsString(
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);
289 
290  $result = $this->viewHelper->initializeArgumentsAndRender();
291 
292  self::assertStringContainsString(
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);
317 
318  $result = $this->viewHelper->initializeArgumentsAndRender();
319 
320  self::assertStringContainsString(
321  '<input class="css_class f3-form-error" type="radio" name="fieldPrefix[objectName][someProperty]" value="foo" />',
322  $result
323  );
324  }
325 }
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\RadioViewHelperTest\renderIgnoresBoundPropertyIfCheckedIsSet
‪renderIgnoresBoundPropertyIfCheckedIsSet()
Definition: RadioViewHelperTest.php:73
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\RadioViewHelperTest\renderDoesNotSetsCheckedAttributeIfBoundPropertyIsNull
‪renderDoesNotSetsCheckedAttributeIfBoundPropertyIsNull()
Definition: RadioViewHelperTest.php:181
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\FormFieldViewHelperBaseTestcase\injectDependenciesIntoViewHelper
‪injectDependenciesIntoViewHelper(ViewHelperInterface $viewHelper)
Definition: FormFieldViewHelperBaseTestcase.php:42
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\FormFieldViewHelperBaseTestcase
Definition: FormFieldViewHelperBaseTestcase.php:28
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\RadioViewHelperTest
Definition: RadioViewHelperTest.php:25
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\RadioViewHelperTest\renderSetsCheckedAttributeIfSpecified
‪renderSetsCheckedAttributeIfSpecified()
Definition: RadioViewHelperTest.php:56
‪TYPO3\CMS\Fluid\ViewHelpers\Form\RadioViewHelper
Definition: RadioViewHelper.php:64
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\RadioViewHelperTest\setUp
‪setUp()
Definition: RadioViewHelperTest.php:30
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\RadioViewHelperTest\renderSetsCheckedAttributeIfCheckboxIsBoundToAPropertyOfTypeString
‪renderSetsCheckedAttributeIfCheckboxIsBoundToAPropertyOfTypeString()
Definition: RadioViewHelperTest.php:154
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\RadioViewHelperTest\$viewHelper
‪TYPO3 CMS Fluid ViewHelpers Form RadioViewHelper $viewHelper
Definition: RadioViewHelperTest.php:28
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager
Definition: PersistenceManager.php:29
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\RadioViewHelperTest\renderSetsTagNameAndDefaultAttributes
‪renderSetsTagNameAndDefaultAttributes()
Definition: RadioViewHelperTest.php:40
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form
Definition: AbstractFormFieldViewHelperTest.php:16
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\RadioViewHelperTest\renderCallExtendsClassAttributeWithErrorClass
‪renderCallExtendsClassAttributeWithErrorClass()
Definition: RadioViewHelperTest.php:300
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\RadioViewHelperTest\renderCallSetsStandardErrorClassAttributeIfNonIsSpecified
‪renderCallSetsStandardErrorClassAttributeIfNonIsSpecified()
Definition: RadioViewHelperTest.php:273
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\FormFieldViewHelperBaseTestcase\stubRequestWithMappingErrors
‪stubRequestWithMappingErrors()
Definition: FormFieldViewHelperBaseTestcase.php:65
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\FormFieldViewHelperBaseTestcase\stubVariableContainer
‪stubVariableContainer($formObject)
Definition: FormFieldViewHelperBaseTestcase.php:81
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\RadioViewHelperTest\renderCorrectlySetsCheckedAttributeIfCheckboxIsBoundToAPropertyOfTypeBoolean
‪renderCorrectlySetsCheckedAttributeIfCheckboxIsBoundToAPropertyOfTypeBoolean()
Definition: RadioViewHelperTest.php:100
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\RadioViewHelperTest\renderDoesNotAppendSquareBracketsToNameAttributeIfBoundToAPropertyOfTypeArray
‪renderDoesNotAppendSquareBracketsToNameAttributeIfBoundToAPropertyOfTypeArray()
Definition: RadioViewHelperTest.php:127
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\RadioViewHelperTest\renderSetsCheckedAttributeForListOfObjects
‪renderSetsCheckedAttributeForListOfObjects()
Definition: RadioViewHelperTest.php:208
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\RadioViewHelperTest\renderCallSetsErrorClassAttribute
‪renderCallSetsErrorClassAttribute()
Definition: RadioViewHelperTest.php:245
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\FormFieldViewHelperBaseTestcase\stubRequestWithoutMappingErrors
‪stubRequestWithoutMappingErrors()
Definition: FormFieldViewHelperBaseTestcase.php:51