27 $formViewHelper = $this->getAccessibleMock(
28 AbstractFormFieldViewHelper::class,
29 [
'isObjectAccessorMode'],
36 $this->assertFalse($formViewHelper->_call(
'getRespectSubmittedDataValue'));
44 $formViewHelper = $this->getAccessibleMock(
45 AbstractFormFieldViewHelper::class,
46 [
'isObjectAccessorMode'],
53 $formViewHelper->_set(
'respectSubmittedDataValue',
true);
54 $this->assertTrue($formViewHelper->_call(
'getRespectSubmittedDataValue'));
62 $formViewHelper = $this->getAccessibleMock(
63 AbstractFormFieldViewHelper::class,
64 [
'isObjectAccessorMode',
'addAdditionalIdentityPropertiesIfNeeded'],
70 $formViewHelper->_set(
'respectSubmittedDataValue',
false);
72 $mockObject = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\ClassWithTwoGetters(
'testing', 1476108385);
74 $formViewHelper->expects($this->any())->method(
'isObjectAccessorMode')->will($this->returnValue(
true));
75 $this->viewHelperVariableContainer->get(FormViewHelper::class,
'formObject')
76 ->willReturn($mockObject);
77 $this->viewHelperVariableContainer->exists(
78 FormViewHelper::class,
82 $arguments = [
'name' =>
null,
'value' =>
null,
'property' =>
'value.something'];
83 $formViewHelper->_set(
'arguments', $arguments);
84 $expected =
'MyString';
85 $actual = $formViewHelper->_call(
'getValueAttribute');
86 $this->assertSame($expected, $actual);
94 $formViewHelper = $this->getAccessibleMock(
95 AbstractFormFieldViewHelper::class,
96 [
'isObjectAccessorMode'],
103 $formViewHelper->expects($this->any())->method(
'isObjectAccessorMode')->will($this->returnValue(
true));
104 $this->viewHelperVariableContainer->get(
105 FormViewHelper::class,
107 )->willReturn(
'myObjectName');
108 $this->viewHelperVariableContainer->exists(
109 FormViewHelper::class,
112 $this->viewHelperVariableContainer->get(FormViewHelper::class,
'fieldNamePrefix')
113 ->willReturn(
'formPrefix');
115 $arguments = [
'name' =>
'fieldName',
'value' =>
'fieldValue',
'property' =>
'bla'];
116 $formViewHelper->_set(
'arguments', $arguments);
117 $expected =
'formPrefix[myObjectName][bla]';
118 $actual = $formViewHelper->_call(
'getName');
119 $this->assertSame($expected, $actual);
127 $formViewHelper = $this->getAccessibleMock(
128 AbstractFormFieldViewHelper::class,
129 [
'isObjectAccessorMode'],
136 $formViewHelper->expects($this->any())->method(
'isObjectAccessorMode')->will($this->returnValue(
true));
137 $this->viewHelperVariableContainer->get(FormViewHelper::class,
'formObjectName')
138 ->willReturn(
'myObjectName');
139 $this->viewHelperVariableContainer->exists(
140 FormViewHelper::class,
143 $this->viewHelperVariableContainer->get(FormViewHelper::class,
'fieldNamePrefix')
144 ->willReturn(
'formPrefix');
146 $arguments = [
'name' =>
'fieldName',
'value' =>
'fieldValue',
'property' =>
'bla.blubb'];
147 $formViewHelper->_set(
'arguments', $arguments);
148 $expected =
'formPrefix[myObjectName][bla][blubb]';
149 $actual = $formViewHelper->_call(
'getName');
150 $this->assertSame($expected, $actual);
158 $formViewHelper = $this->getAccessibleMock(
159 AbstractFormFieldViewHelper::class,
160 [
'isObjectAccessorMode'],
167 $formViewHelper->expects($this->any())->method(
'isObjectAccessorMode')->will($this->returnValue(
true));
168 $this->viewHelperVariableContainer->get(FormViewHelper::class,
'formObjectName')
170 $this->viewHelperVariableContainer->exists(
171 FormViewHelper::class,
174 $this->viewHelperVariableContainer->get(FormViewHelper::class,
'fieldNamePrefix')
175 ->willReturn(
'formPrefix');
177 $arguments = [
'name' =>
'fieldName',
'value' =>
'fieldValue',
'property' =>
'bla'];
178 $formViewHelper->_set(
'arguments', $arguments);
179 $expected =
'formPrefix[bla]';
180 $actual = $formViewHelper->_call(
'getName');
181 $this->assertSame($expected, $actual);
189 $formViewHelper = $this->getAccessibleMock(
190 AbstractFormFieldViewHelper::class,
191 [
'isObjectAccessorMode'],
198 $formViewHelper->expects($this->any())->method(
'isObjectAccessorMode')->will($this->returnValue(
false));
199 $this->viewHelperVariableContainer->exists(
200 FormViewHelper::class,
203 $this->viewHelperVariableContainer->get(FormViewHelper::class,
'fieldNamePrefix')
204 ->willReturn(
'formPrefix');
206 $arguments = [
'name' =>
'fieldName',
'value' =>
'fieldValue',
'property' =>
'bla'];
207 $formViewHelper->_set(
'arguments', $arguments);
208 $expected =
'formPrefix[fieldName]';
209 $actual = $formViewHelper->_call(
'getName');
210 $this->assertSame($expected, $actual);
218 $formViewHelper = $this->getAccessibleMock(
219 AbstractFormFieldViewHelper::class,
227 $this->viewHelperVariableContainer->exists(FormViewHelper::class,
'formObjectName')
230 $formViewHelper->_set(
'arguments', [
'name' =>
null,
'value' =>
null,
'property' =>
'bla']);
231 $this->assertTrue($formViewHelper->_call(
'isObjectAccessorMode'));
233 $formViewHelper->_set(
'arguments', [
'name' =>
null,
'value' =>
null,
'property' =>
null]);
234 $this->assertFalse($formViewHelper->_call(
'isObjectAccessorMode'));
242 $formFieldViewHelper = $this->getAccessibleMock(
243 AbstractFormFieldViewHelper::class,
244 [
'renderHiddenIdentityField'],
250 $arguments = [
'property' =>
'simple'];
251 $formFieldViewHelper->expects($this->any())->method(
'renderHiddenIdentityField')->will(
252 $this->throwException(
new \Exception(
'Should not be executed!!!', 1476108413))
254 $formFieldViewHelper->_set(
'arguments', $arguments);
255 $formFieldViewHelper->_call(
'addAdditionalIdentityPropertiesIfNeeded');
263 $mockFormObject = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\ClassWithTwoGetters();
265 $property =
'value.something';
266 $objectName =
'myObject';
267 $expectedProperty =
'myObject[value]';
269 $formFieldViewHelper = $this->getAccessibleMock(
270 AbstractFormFieldViewHelper::class,
271 [
'renderHiddenIdentityField',
'isObjectAccessorMode'],
277 $arguments = [
'property' => $property];
278 $formFieldViewHelper->_set(
'arguments', $arguments);
279 $formFieldViewHelper->expects($this->atLeastOnce())->method(
'isObjectAccessorMode')->will(
280 $this->returnValue(
true)
282 $this->viewHelperVariableContainer->exists(FormViewHelper::class,
'formObject')
284 $this->viewHelperVariableContainer->get(FormViewHelper::class,
'formObject')
285 ->willReturn($mockFormObject);
286 $this->viewHelperVariableContainer->get(FormViewHelper::class,
'formObjectName')
287 ->willReturn($objectName);
288 $this->viewHelperVariableContainer->get(
289 FormViewHelper::class,
290 'additionalIdentityProperties'
292 $this->viewHelperVariableContainer->addOrUpdate(
293 FormViewHelper::class,
294 'additionalIdentityProperties',
295 [$expectedProperty =>
null]
298 $formFieldViewHelper->expects($this->once())->method(
'renderHiddenIdentityField')->with(
303 $formFieldViewHelper->_call(
'addAdditionalIdentityPropertiesIfNeeded');
311 $mockFormObject = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\ClassWithTwoGetters();
312 $property =
'value.value.something';
313 $objectName =
'myObject';
314 $expectedProperty1 =
'myObject[value]';
315 $expectedProperty2 =
'myObject[value][value]';
317 $formFieldViewHelper = $this->getAccessibleMock(
318 AbstractFormFieldViewHelper::class,
319 [
'renderHiddenIdentityField',
'isObjectAccessorMode'],
325 $arguments = [
'property' => $property];
326 $formFieldViewHelper->_set(
'arguments', $arguments);
327 $formFieldViewHelper->expects($this->atLeastOnce())->method(
'isObjectAccessorMode')->will(
328 $this->returnValue(
true)
330 $this->viewHelperVariableContainer->exists(FormViewHelper::class,
'formObject')
332 $this->viewHelperVariableContainer->get(FormViewHelper::class,
'formObject')
333 ->willReturn($mockFormObject);
334 $this->viewHelperVariableContainer->get(FormViewHelper::class,
'formObjectName')
335 ->willReturn($objectName);
336 $this->viewHelperVariableContainer->get(
337 FormViewHelper::class,
338 'additionalIdentityProperties'
340 $this->viewHelperVariableContainer->addOrUpdate(
341 FormViewHelper::class,
342 'additionalIdentityProperties',
343 [$expectedProperty1 =>
null]
345 $this->viewHelperVariableContainer->addOrUpdate(
346 FormViewHelper::class,
347 'additionalIdentityProperties',
348 [$expectedProperty2 =>
null]
351 $formFieldViewHelper->expects($this->at(1))->method(
'renderHiddenIdentityField')->with(
355 $formFieldViewHelper->expects($this->at(2))->method(
'renderHiddenIdentityField')->with(
360 $formFieldViewHelper->_call(
'addAdditionalIdentityPropertiesIfNeeded');
368 $formViewHelper = $this->getAccessibleMock(
369 AbstractFormFieldViewHelper::class,
376 $formViewHelper->expects($this->any())->method(
'getName')->will($this->returnValue(
'SomeFieldName'));
377 $this->viewHelperVariableContainer->exists(
378 FormViewHelper::class,
379 'renderedHiddenFields'
381 $this->viewHelperVariableContainer->get(
382 FormViewHelper::class,
383 'renderedHiddenFields'
385 $this->viewHelperVariableContainer->addOrUpdate(
386 FormViewHelper::class,
387 'renderedHiddenFields',
390 $expected =
'<input type="hidden" name="SomeFieldName" value="" />';
391 $actual = $formViewHelper->_call(
'renderHiddenFieldForEmptyValue');
392 $this->assertEquals($expected, $actual);
400 $formViewHelper = $this->getAccessibleMock(
401 AbstractFormFieldViewHelper::class,
408 $formViewHelper->expects($this->any())->method(
'getName')->will($this->returnValue(
'NewFieldName'));
409 $this->viewHelperVariableContainer->exists(
410 FormViewHelper::class,
411 'renderedHiddenFields'
413 $this->viewHelperVariableContainer->get(
414 FormViewHelper::class,
415 'renderedHiddenFields'
416 )->willReturn([
'OldFieldName']);
417 $this->viewHelperVariableContainer->addOrUpdate(
418 FormViewHelper::class,
419 'renderedHiddenFields',
420 [
'OldFieldName',
'NewFieldName']
422 $formViewHelper->_call(
'renderHiddenFieldForEmptyValue');
430 $formViewHelper = $this->getAccessibleMock(
431 AbstractFormFieldViewHelper::class,
438 $formViewHelper->expects($this->any())->method(
'getName')->will($this->returnValue(
'SomeFieldName'));
439 $this->viewHelperVariableContainer->exists(
440 FormViewHelper::class,
441 'renderedHiddenFields'
443 $this->viewHelperVariableContainer->get(
444 FormViewHelper::class,
445 'renderedHiddenFields'
446 )->willReturn([
'SomeFieldName']);
448 $actual = $formViewHelper->_call(
'renderHiddenFieldForEmptyValue');
449 $this->assertEquals($expected, $actual);
457 $formViewHelper = $this->getAccessibleMock(
458 AbstractFormFieldViewHelper::class,
465 $formViewHelper->expects($this->any())->method(
'getName')->will(
466 $this->returnValue(
'SomeFieldName[WithBrackets][]')
468 $this->viewHelperVariableContainer->exists(
469 FormViewHelper::class,
470 'renderedHiddenFields'
472 $this->viewHelperVariableContainer->get(
473 FormViewHelper::class,
474 'renderedHiddenFields'
476 $this->viewHelperVariableContainer->addOrUpdate(
477 FormViewHelper::class,
478 'renderedHiddenFields',
479 [
'SomeFieldName[WithBrackets]']
481 $expected =
'<input type="hidden" name="SomeFieldName[WithBrackets]" value="" />';
482 $actual = $formViewHelper->_call(
'renderHiddenFieldForEmptyValue');
483 $this->assertEquals($expected, $actual);
491 $formViewHelper = $this->getAccessibleMock(
492 AbstractFormFieldViewHelper::class,
499 $formViewHelper->expects($this->any())->method(
'getName')->will(
500 $this->returnValue(
'SomeFieldName[WithBrackets][foo]')
502 $this->viewHelperVariableContainer->exists(
503 FormViewHelper::class,
504 'renderedHiddenFields'
506 $this->viewHelperVariableContainer->get(
507 FormViewHelper::class,
508 'renderedHiddenFields'
510 $this->viewHelperVariableContainer->addOrUpdate(
511 FormViewHelper::class,
512 'renderedHiddenFields',
513 [
'SomeFieldName[WithBrackets][foo]']
515 $expected =
'<input type="hidden" name="SomeFieldName[WithBrackets][foo]" value="" />';
516 $actual = $formViewHelper->_call(
'renderHiddenFieldForEmptyValue');
517 $this->assertEquals($expected, $actual);
525 $formFieldViewHelper = $this->getAccessibleMock(
526 AbstractFormFieldViewHelper::class,
527 [
'renderHiddenIdentityField'],
534 $formFieldViewHelper->_set(
'arguments', [
'property' =>
'key1.key2']);
536 $this->viewHelperVariableContainer->exists(FormViewHelper::class,
'formObject')
538 $this->viewHelperVariableContainer->get(FormViewHelper::class,
'formObject')
539 ->willReturn([
'key1' => [
'key2' =>
'valueX']]);
541 $actual = $formFieldViewHelper->_call(
'getPropertyValue');
542 $this->assertEquals(
'valueX', $actual);