TYPO3 CMS  TYPO3_7-6
AbstractFormFieldViewHelperTest.php
Go to the documentation of this file.
1 <?php
3 
4 /* *
5  * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6  * *
7  * It is free software; you can redistribute it and/or modify it under *
8  * the terms of the GNU Lesser General Public License, either version 3 *
9  * of the License, or (at your option) any later version. *
10  * *
11  * The TYPO3 project - inspiring people to share! *
12  * */
13 
18 {
23  {
24  $formViewHelper = $this->getAccessibleMock(
25  \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper::class, ['isObjectAccessorMode'], [], '',
26  false
27  );
28  $this->injectDependenciesIntoViewHelper($formViewHelper);
29 
30  $this->assertFalse($formViewHelper->_call('getRespectSubmittedDataValue'));
31  }
32 
37  {
38  $formViewHelper = $this->getAccessibleMock(
39  \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper::class, ['isObjectAccessorMode'], [], '',
40  false
41  );
42  $this->injectDependenciesIntoViewHelper($formViewHelper);
43 
44  $formViewHelper->_set('respectSubmittedDataValue', true);
45  $this->assertTrue($formViewHelper->_call('getRespectSubmittedDataValue'));
46  }
47 
52  {
53  $formViewHelper = $this->getAccessibleMock(
54  \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper::class,
55  ['isObjectAccessorMode', 'addAdditionalIdentityPropertiesIfNeeded'], [], '', false
56  );
57  $this->injectDependenciesIntoViewHelper($formViewHelper);
58  $formViewHelper->_set('respectSubmittedDataValue', false);
59 
60  $mockObject = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\ClassWithTwoGetters();
61 
62  $formViewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(true));
63  $this->viewHelperVariableContainer->expects($this->atLeastOnce())->method('get')->with(
64  \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'formObject'
65  )->will($this->returnValue($mockObject));
66  $this->viewHelperVariableContainer->expects($this->atLeastOnce())->method('exists')->with(
67  \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'formObject'
68  )->will($this->returnValue(true));
69 
70  $arguments = ['name' => null, 'value' => null, 'property' => 'value.something'];
71  $formViewHelper->_set('arguments', $arguments);
72  $expected = 'MyString';
73  $actual = $formViewHelper->_call('getValueAttribute');
74  $this->assertSame($expected, $actual);
75  }
76 
81  {
82  $mockPersistenceManager = $this->getMock(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface::class);
83  $mockPersistenceManager->expects($this->any())->method('getIdentifierByObject')->will(
84  $this->returnValue('6f487e40-4483-11de-8a39-0800200c9a66')
85  );
86 
87  $object = $this->getMock(\TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\EmptyClass::class);
88  $object->expects($this->any())->method('FLOW3_Persistence_isNew')->will($this->returnValue(false));
89 
90  $formViewHelper = $this->getAccessibleMock(
91  \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper::class, ['dummy'], [], '', false
92  );
93  $this->injectDependenciesIntoViewHelper($formViewHelper);
94  $formViewHelper->_set('persistenceManager', $mockPersistenceManager);
95 
96  $arguments = ['name' => 'foo', 'value' => $object, 'property' => null];
97  $formViewHelper->_set('arguments', $arguments);
98  $formViewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(false));
99 
100  $this->assertSame('foo[__identity]', $formViewHelper->_call('getName'));
101  $this->assertSame('6f487e40-4483-11de-8a39-0800200c9a66', $formViewHelper->_call('getValue'));
102  }
103 
108  {
109  $formViewHelper = $this->getAccessibleMock(
110  \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper::class, ['isObjectAccessorMode'], [], '',
111  false
112  );
113  $this->injectDependenciesIntoViewHelper($formViewHelper);
114 
115  $formViewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(true));
116  $this->viewHelperVariableContainer->expects($this->at(0))->method('get')->with(
117  \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'formObjectName'
118  )->will($this->returnValue('myObjectName'));
119  $this->viewHelperVariableContainer->expects($this->at(1))->method('exists')->with(
120  \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'fieldNamePrefix'
121  )->will($this->returnValue(true));
122  $this->viewHelperVariableContainer->expects($this->at(2))->method('get')->with(
123  \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'fieldNamePrefix'
124  )->will($this->returnValue('formPrefix'));
125 
126  $arguments = ['name' => 'fieldName', 'value' => 'fieldValue', 'property' => 'bla'];
127  $formViewHelper->_set('arguments', $arguments);
128  $expected = 'formPrefix[myObjectName][bla]';
129  $actual = $formViewHelper->_call('getName');
130  $this->assertSame($expected, $actual);
131  }
132 
137  {
138  $formViewHelper = $this->getAccessibleMock(
139  \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper::class, ['isObjectAccessorMode'], [], '',
140  false
141  );
142  $this->injectDependenciesIntoViewHelper($formViewHelper);
143 
144  $formViewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(true));
145  $this->viewHelperVariableContainer->expects($this->at(0))->method('get')->with(
146  \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'formObjectName'
147  )->will($this->returnValue('myObjectName'));
148  $this->viewHelperVariableContainer->expects($this->at(1))->method('exists')->with(
149  \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'fieldNamePrefix'
150  )->will($this->returnValue(true));
151  $this->viewHelperVariableContainer->expects($this->at(2))->method('get')->with(
152  \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'fieldNamePrefix'
153  )->will($this->returnValue('formPrefix'));
154 
155  $arguments = ['name' => 'fieldName', 'value' => 'fieldValue', 'property' => 'bla.blubb'];
156  $formViewHelper->_set('arguments', $arguments);
157  $expected = 'formPrefix[myObjectName][bla][blubb]';
158  $actual = $formViewHelper->_call('getName');
159  $this->assertSame($expected, $actual);
160  }
161 
166  ) {
167  $formViewHelper = $this->getAccessibleMock(
168  \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper::class, ['isObjectAccessorMode'], [], '',
169  false
170  );
171  $this->injectDependenciesIntoViewHelper($formViewHelper);
172 
173  $formViewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(true));
174  $this->viewHelperVariableContainer->expects($this->at(0))->method('get')->with(
175  \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'formObjectName'
176  )->will($this->returnValue(null));
177  $this->viewHelperVariableContainer->expects($this->at(1))->method('exists')->with(
178  \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'fieldNamePrefix'
179  )->will($this->returnValue(true));
180  $this->viewHelperVariableContainer->expects($this->at(2))->method('get')->with(
181  \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'fieldNamePrefix'
182  )->will($this->returnValue('formPrefix'));
183 
184  $arguments = ['name' => 'fieldName', 'value' => 'fieldValue', 'property' => 'bla'];
185  $formViewHelper->_set('arguments', $arguments);
186  $expected = 'formPrefix[bla]';
187  $actual = $formViewHelper->_call('getName');
188  $this->assertSame($expected, $actual);
189  }
190 
195  {
196  $formViewHelper = $this->getAccessibleMock(
197  \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper::class, ['isObjectAccessorMode'], [], '',
198  false
199  );
200  $this->injectDependenciesIntoViewHelper($formViewHelper);
201 
202  $formViewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(false));
203  $this->viewHelperVariableContainer->expects($this->at(0))->method('exists')->with(
204  \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'fieldNamePrefix'
205  )->will($this->returnValue(true));
206  $this->viewHelperVariableContainer->expects($this->at(1))->method('get')->with(
207  \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'fieldNamePrefix'
208  )->will($this->returnValue('formPrefix'));
209 
210  $arguments = ['name' => 'fieldName', 'value' => 'fieldValue', 'property' => 'bla'];
211  $formViewHelper->_set('arguments', $arguments);
212  $expected = 'formPrefix[fieldName]';
213  $actual = $formViewHelper->_call('getName');
214  $this->assertSame($expected, $actual);
215  }
216 
221  {
222  $formViewHelper = $this->getAccessibleMock(
223  \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper::class,
224  ['isObjectAccessorMode', 'addAdditionalIdentityPropertiesIfNeeded'], [], '', false
225  );
226  $this->injectDependenciesIntoViewHelper($formViewHelper);
227 
228  $mockObject = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\ClassWithTwoGetters();
229 
230  $formViewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(true));
231  $formViewHelper->expects($this->once())->method('addAdditionalIdentityPropertiesIfNeeded');
232  $this->viewHelperVariableContainer->expects($this->atLeastOnce())->method('get')->with(
233  \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'formObject'
234  )->will($this->returnValue($mockObject));
235  $this->viewHelperVariableContainer->expects($this->atLeastOnce())->method('exists')->with(
236  \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'formObject'
237  )->will($this->returnValue(true));
238 
239  $arguments = ['name' => null, 'value' => null, 'property' => 'value.something'];
240  $formViewHelper->_set('arguments', $arguments);
241  $expected = 'MyString';
242  $actual = $formViewHelper->_call('getValue');
243  $this->assertSame($expected, $actual);
244  }
245 
250  {
251  $formViewHelper = $this->getAccessibleMock(
252  \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper::class, ['isObjectAccessorMode'], [], '',
253  false
254  );
255  $this->injectDependenciesIntoViewHelper($formViewHelper);
256  $formViewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(false));
257 
258  $mockArguments = [];
259  $formViewHelper->_set('arguments', $mockArguments);
260 
261  $this->assertNull($formViewHelper->_call('getValue'));
262  }
263 
268  {
269  $formViewHelper = $this->getAccessibleMock(
270  \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper::class, ['isObjectAccessorMode'], [], '',
271  false
272  );
273  $formViewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(false));
274  $this->injectDependenciesIntoViewHelper($formViewHelper);
275 
276  $mockArguments = ['value' => 'someValue'];
277  $formViewHelper->_set('arguments', $mockArguments);
278 
279  $this->assertEquals('someValue', $formViewHelper->_call('getValue'));
280  }
281 
286  {
287  $mockObject = $this->getMock('stdClass');
288 
289  $mockPersistenceManager = $this->getMock(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface::class);
290  $mockPersistenceManager->expects($this->atLeastOnce())->method('getIdentifierByObject')->with(
291  $mockObject
292  )->will($this->returnValue('6f487e40-4483-11de-8a39-0800200c9a66'));
293 
294  $formViewHelper = $this->getAccessibleMock(
295  \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper::class, ['isObjectAccessorMode'], [], '',
296  false
297  );
298  $formViewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(false));
299  $this->injectDependenciesIntoViewHelper($formViewHelper);
300  $formViewHelper->_set('persistenceManager', $mockPersistenceManager);
301 
302  $mockArguments = ['value' => $mockObject];
303  $formViewHelper->_set('arguments', $mockArguments);
304 
305  $this->assertSame('6f487e40-4483-11de-8a39-0800200c9a66', $formViewHelper->_call('getValue'));
306  }
307 
312  {
313  $mockObject = $this->getMock('stdClass');
314 
315  $mockPersistenceManager = $this->getMock(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface::class);
316  $mockPersistenceManager->expects($this->any())->method('getIdentifierByObject')->will(
317  $this->returnValue('6f487e40-4483-11de-8a39-0800200c9a66')
318  );
319 
320  $formViewHelper = $this->getAccessibleMock(
321  \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper::class, ['isObjectAccessorMode'], [], '',
322  false
323  );
324  $formViewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(false));
325  $this->injectDependenciesIntoViewHelper($formViewHelper);
326  $formViewHelper->_set('persistenceManager', $mockPersistenceManager);
327 
328  $mockArguments = ['value' => $mockObject];
329  $formViewHelper->_set('arguments', $mockArguments);
330 
331  $this->assertSame($mockObject, $formViewHelper->_call('getValue', false));
332  }
333 
338  {
339  $formViewHelper = $this->getAccessibleMock(
340  \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper::class, ['dummy'], [], '', false
341  );
342  $this->injectDependenciesIntoViewHelper($formViewHelper);
343 
344  $this->viewHelperVariableContainer->expects($this->once())->method('exists')->with(
345  \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'formObjectName'
346  )->will($this->returnValue(true));
347 
348  $formViewHelper->_set('arguments', ['name' => null, 'value' => null, 'property' => 'bla']);
349  $this->assertTrue($formViewHelper->_call('isObjectAccessorMode'));
350 
351  $formViewHelper->_set('arguments', ['name' => null, 'value' => null, 'property' => null]);
352  $this->assertFalse($formViewHelper->_call('isObjectAccessorMode'));
353  }
354 
359  {
360  $formFieldViewHelper = $this->getAccessibleMock(
361  \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper::class, ['renderHiddenIdentityField'], [], '',
362  false
363  );
364  $this->injectDependenciesIntoViewHelper($formFieldViewHelper);
365  $arguments = ['property' => 'simple'];
366  $formFieldViewHelper->expects($this->any())->method('renderHiddenIdentityField')->will(
367  $this->throwException(new \Exception('Should not be executed!!!'))
368  );
369  $formFieldViewHelper->_set('arguments', $arguments);
370  $formFieldViewHelper->_call('addAdditionalIdentityPropertiesIfNeeded');
371  }
372 
377  {
378  $mockFormObject = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\ClassWithTwoGetters();
379  $property = 'value.something';
380  $objectName = 'myObject';
381  $expectedProperty = 'myObject[value]';
382 
383  $formFieldViewHelper = $this->getAccessibleMock(
384  \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper::class,
385  ['renderHiddenIdentityField', 'isObjectAccessorMode'], [], '', false
386  );
387  $this->injectDependenciesIntoViewHelper($formFieldViewHelper);
388  $arguments = ['property' => $property];
389  $formFieldViewHelper->_set('arguments', $arguments);
390  $formFieldViewHelper->expects($this->atLeastOnce())->method('isObjectAccessorMode')->will(
391  $this->returnValue(true)
392  );
393  $this->viewHelperVariableContainer->expects($this->at(0))->method('exists')->with(
394  \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'formObject'
395  )->will($this->returnValue(true));
396  $this->viewHelperVariableContainer->expects($this->at(1))->method('get')->with(
397  \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'formObject'
398  )->will($this->returnValue($mockFormObject));
399  $this->viewHelperVariableContainer->expects($this->at(2))->method('get')->with(
400  \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'formObjectName'
401  )->will($this->returnValue($objectName));
402 
403  $formFieldViewHelper->expects($this->once())->method('renderHiddenIdentityField')->with(
404  $mockFormObject, $expectedProperty
405  );
406 
407  $formFieldViewHelper->_call('addAdditionalIdentityPropertiesIfNeeded');
408  }
409 
414  ) {
415  $mockFormObject = new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\ClassWithTwoGetters();
416  $property = 'value.value.something';
417  $objectName = 'myObject';
418  $expectedProperty1 = 'myObject[value]';
419  $expectedProperty2 = 'myObject[value][value]';
420 
421  $formFieldViewHelper = $this->getAccessibleMock(
422  \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper::class,
423  ['renderHiddenIdentityField', 'isObjectAccessorMode'], [], '', false
424  );
425  $this->injectDependenciesIntoViewHelper($formFieldViewHelper);
426  $arguments = ['property' => $property];
427  $formFieldViewHelper->_set('arguments', $arguments);
428  $formFieldViewHelper->expects($this->atLeastOnce())->method('isObjectAccessorMode')->will(
429  $this->returnValue(true)
430  );
431  $this->viewHelperVariableContainer->expects($this->at(0))->method('exists')->with(
432  \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'formObject'
433  )->will($this->returnValue(true));
434  $this->viewHelperVariableContainer->expects($this->at(1))->method('get')->with(
435  \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'formObject'
436  )->will($this->returnValue($mockFormObject));
437  $this->viewHelperVariableContainer->expects($this->at(2))->method('get')->with(
438  \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'formObjectName'
439  )->will($this->returnValue($objectName));
440 
441  $formFieldViewHelper->expects($this->at(1))->method('renderHiddenIdentityField')->with(
442  $mockFormObject, $expectedProperty1
443  );
444  $formFieldViewHelper->expects($this->at(2))->method('renderHiddenIdentityField')->with(
445  $mockFormObject, $expectedProperty2
446  );
447 
448  $formFieldViewHelper->_call('addAdditionalIdentityPropertiesIfNeeded');
449  }
450 
455  {
456  $formViewHelper = $this->getAccessibleMock(
457  \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper::class, ['getName'], [], '', false
458  );
459  $this->injectDependenciesIntoViewHelper($formViewHelper);
460  $formViewHelper->expects($this->any())->method('getName')->will($this->returnValue('SomeFieldName'));
461  $this->viewHelperVariableContainer->expects($this->at(0))->method('exists')->with(
462  \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'renderedHiddenFields'
463  )->will($this->returnValue(true));
464  $this->viewHelperVariableContainer->expects($this->at(1))->method('get')->with(
465  \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'renderedHiddenFields'
466  )->will($this->returnValue([]));
467  $expected = '<input type="hidden" name="SomeFieldName" value="" />';
468  $actual = $formViewHelper->_call('renderHiddenFieldForEmptyValue');
469  $this->assertEquals($expected, $actual);
470  }
471 
476  {
477  $formViewHelper = $this->getAccessibleMock(
478  \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper::class, ['getName'], [], '', false
479  );
480  $this->injectDependenciesIntoViewHelper($formViewHelper);
481  $formViewHelper->expects($this->any())->method('getName')->will($this->returnValue('NewFieldName'));
482  $this->viewHelperVariableContainer->expects($this->at(0))->method('exists')->with(
483  \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'renderedHiddenFields'
484  )->will($this->returnValue(true));
485  $this->viewHelperVariableContainer->expects($this->at(1))->method('get')->with(
486  \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'renderedHiddenFields'
487  )->will($this->returnValue(['OldFieldName']));
488  $this->viewHelperVariableContainer->expects($this->at(2))->method('addOrUpdate')->with(
489  \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'renderedHiddenFields', ['OldFieldName', 'NewFieldName']
490  );
491  $formViewHelper->_call('renderHiddenFieldForEmptyValue');
492  }
493 
498  {
499  $formViewHelper = $this->getAccessibleMock(
500  \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper::class, ['getName'], [], '', false
501  );
502  $this->injectDependenciesIntoViewHelper($formViewHelper);
503  $formViewHelper->expects($this->any())->method('getName')->will($this->returnValue('SomeFieldName'));
504  $this->viewHelperVariableContainer->expects($this->at(0))->method('exists')->with(
505  \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'renderedHiddenFields'
506  )->will($this->returnValue(true));
507  $this->viewHelperVariableContainer->expects($this->at(1))->method('get')->with(
508  \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'renderedHiddenFields'
509  )->will($this->returnValue(['SomeFieldName']));
510  $this->viewHelperVariableContainer->expects($this->never())->method('addOrUpdate');
511  $expected = '';
512  $actual = $formViewHelper->_call('renderHiddenFieldForEmptyValue');
513  $this->assertEquals($expected, $actual);
514  }
515 
520  {
521  $formViewHelper = $this->getAccessibleMock(
522  \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper::class, ['getName'], [], '', false
523  );
524  $this->injectDependenciesIntoViewHelper($formViewHelper);
525  $formViewHelper->expects($this->any())->method('getName')->will(
526  $this->returnValue('SomeFieldName[WithBrackets][]')
527  );
528  $this->viewHelperVariableContainer->expects($this->at(0))->method('exists')->with(
529  \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'renderedHiddenFields'
530  )->will($this->returnValue(true));
531  $this->viewHelperVariableContainer->expects($this->at(1))->method('get')->with(
532  \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'renderedHiddenFields'
533  )->will($this->returnValue([]));
534  $this->viewHelperVariableContainer->expects($this->at(2))->method('addOrUpdate')->with(
535  \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'renderedHiddenFields', ['SomeFieldName[WithBrackets]']
536  );
537  $expected = '<input type="hidden" name="SomeFieldName[WithBrackets]" value="" />';
538  $actual = $formViewHelper->_call('renderHiddenFieldForEmptyValue');
539  $this->assertEquals($expected, $actual);
540  }
541 
546  {
547  $formViewHelper = $this->getAccessibleMock(
548  \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper::class, ['getName'], [], '', false
549  );
550  $this->injectDependenciesIntoViewHelper($formViewHelper);
551  $formViewHelper->expects($this->any())->method('getName')->will(
552  $this->returnValue('SomeFieldName[WithBrackets][foo]')
553  );
554  $this->viewHelperVariableContainer->expects($this->at(0))->method('exists')->with(
555  \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'renderedHiddenFields'
556  )->will($this->returnValue(true));
557  $this->viewHelperVariableContainer->expects($this->at(1))->method('get')->with(
558  \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'renderedHiddenFields'
559  )->will($this->returnValue([]));
560  $this->viewHelperVariableContainer->expects($this->at(2))->method('addOrUpdate')->with(
561  \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'renderedHiddenFields',
562  ['SomeFieldName[WithBrackets][foo]']
563  );
564  $expected = '<input type="hidden" name="SomeFieldName[WithBrackets][foo]" value="" />';
565  $actual = $formViewHelper->_call('renderHiddenFieldForEmptyValue');
566  $this->assertEquals($expected, $actual);
567  }
568 
573  {
574  $formFieldViewHelper = $this->getAccessibleMock(
575  \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper::class,
576  ['renderHiddenIdentityField'],
577  [],
578  '',
579  false
580  );
581 
582  $this->injectDependenciesIntoViewHelper($formFieldViewHelper);
583  $formFieldViewHelper->_set('arguments', ['property' => 'key1.key2']);
584 
585  $this->viewHelperVariableContainer->expects($this->at(0))->method('exists')->with(
586  \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'formObject'
587  )->will($this->returnValue(true));
588  $this->viewHelperVariableContainer->expects($this->at(1))->method('get')->with(
589  \TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'formObject'
590  )->will($this->returnValue(['key1' => ['key2' => 'valueX']]));
591 
592  $actual = $formFieldViewHelper->_call('getPropertyValue');
593  $this->assertEquals('valueX', $actual);
594  }
595 }
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)
injectDependenciesIntoViewHelper(\TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper $viewHelper)