‪TYPO3CMS  9.5
AbstractFormViewHelperTest.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 
17 use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
18 
22 class ‪AbstractFormViewHelperTest extends ViewHelperBaseTestcase
23 {
28  {
29  $object = $this->getAccessibleMock(\‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\ExtendsAbstractEntity::class, ['dummy']);
30  $object->_set('uid', 123);
31  $expectedResult = chr(10) . '<input type="hidden" name="prefix[theName][__identity]" value="123" />' . chr(10);
32  $viewHelper = $this->getAccessibleMock(\‪TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, ['prefixFieldName', 'registerFieldNameForFormTokenGeneration'], [], '', false);
33  $viewHelper->expects($this->any())->method('prefixFieldName')->with('theName')->will($this->returnValue('prefix[theName]'));
34  $actualResult = $viewHelper->_call('renderHiddenIdentityField', $object, 'theName');
35  $this->assertSame($expectedResult, $actualResult);
36  }
37 
42  {
43  $object = $this->getAccessibleMock(\‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\ExtendsAbstractEntity::class, ['dummy']);
44  $object->_set('uid', 123);
45  $object = clone $object;
46  $expectedResult = chr(10) . '<input type="hidden" name="prefix[theName][__identity]" value="123" />' . chr(10);
47  $viewHelper = $this->getAccessibleMock(\‪TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, ['prefixFieldName', 'registerFieldNameForFormTokenGeneration'], [], '', false);
48  $viewHelper->expects($this->any())->method('prefixFieldName')->with('theName')->will($this->returnValue('prefix[theName]'));
49  $actualResult = $viewHelper->_call('renderHiddenIdentityField', $object, 'theName');
50  $this->assertSame($expectedResult, $actualResult);
51  }
52 
57  {
58  $viewHelper = $this->getAccessibleMock(\‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormViewHelper::class, ['dummy'], [], '', false);
59  $this->injectDependenciesIntoViewHelper($viewHelper);
60  $this->assertSame('', $viewHelper->_call('prefixFieldName', null));
61  }
62 
67  {
68  $viewHelper = $this->getAccessibleMock(\‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormViewHelper::class, ['dummy'], [], '', false);
69  $this->injectDependenciesIntoViewHelper($viewHelper);
70  $this->assertSame('', $viewHelper->_call('prefixFieldName', ''));
71  }
72 
77  {
78  $viewHelper = $this->getAccessibleMock(\‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormViewHelper::class, ['dummy'], [], '', false);
79  $this->injectDependenciesIntoViewHelper($viewHelper);
80  $this->viewHelperVariableContainer->exists(\‪TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'fieldNamePrefix')->willReturn(true);
81  $this->viewHelperVariableContainer->get(\‪TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'fieldNamePrefix')->willReturn('');
82  $this->assertSame('someFieldName', $viewHelper->_call('prefixFieldName', 'someFieldName'));
83  }
84 
89  {
90  $viewHelper = $this->getAccessibleMock(\‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormViewHelper::class, ['dummy'], [], '', false);
91  $this->injectDependenciesIntoViewHelper($viewHelper);
92  $this->viewHelperVariableContainer->exists(\‪TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'fieldNamePrefix')->willReturn(true);
93  $this->viewHelperVariableContainer->get(\‪TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'fieldNamePrefix')->willReturn('somePrefix');
94  $this->assertSame('somePrefix[someFieldName]', $viewHelper->_call('prefixFieldName', 'someFieldName'));
95  }
96 
101  {
102  $viewHelper = $this->getAccessibleMock(\‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormViewHelper::class, ['dummy'], [], '', false);
103  $this->injectDependenciesIntoViewHelper($viewHelper);
104  $this->viewHelperVariableContainer->exists(\‪TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'fieldNamePrefix')->willReturn(true);
105  $this->viewHelperVariableContainer->get(\‪TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper::class, 'fieldNamePrefix')->willReturn('somePrefix[foo]');
106  $this->assertSame('somePrefix[foo][someFieldName][bar]', $viewHelper->_call('prefixFieldName', 'someFieldName[bar]'));
107  }
108 }
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\AbstractFormViewHelperTest\renderHiddenIdentityFieldReturnsAHiddenInputFieldContainingTheObjectsUID
‪renderHiddenIdentityFieldReturnsAHiddenInputFieldContainingTheObjectsUID()
Definition: AbstractFormViewHelperTest.php:27
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\AbstractFormViewHelperTest\prefixFieldNameReturnsEmptyStringIfGivenFieldNameIsEmpty
‪prefixFieldNameReturnsEmptyStringIfGivenFieldNameIsEmpty()
Definition: AbstractFormViewHelperTest.php:66
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\AbstractFormViewHelperTest\prefixFieldNameReturnsEmptyStringIfGivenFieldNameIsNULL
‪prefixFieldNameReturnsEmptyStringIfGivenFieldNameIsNULL()
Definition: AbstractFormViewHelperTest.php:56
‪TYPO3
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\AbstractFormViewHelperTest\prefixFieldNameReturnsGivenFieldNameIfFieldNamePrefixIsEmpty
‪prefixFieldNameReturnsGivenFieldNameIfFieldNamePrefixIsEmpty()
Definition: AbstractFormViewHelperTest.php:76
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\AbstractFormViewHelperTest\prefixFieldNamePrefixesGivenFieldNameWithFieldNamePrefix
‪prefixFieldNamePrefixesGivenFieldNameWithFieldNamePrefix()
Definition: AbstractFormViewHelperTest.php:88
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\AbstractFormViewHelperTest\prefixFieldNamePreservesSquareBracketsOfFieldName
‪prefixFieldNamePreservesSquareBracketsOfFieldName()
Definition: AbstractFormViewHelperTest.php:100
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\AbstractFormViewHelperTest
Definition: AbstractFormViewHelperTest.php:23
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form
Definition: AbstractFormFieldViewHelperTest.php:2
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\AbstractFormViewHelperTest\renderHiddenIdentityFieldReturnsAHiddenInputFieldIfObjectIsNewButAClone
‪renderHiddenIdentityFieldReturnsAHiddenInputFieldIfObjectIsNewButAClone()
Definition: AbstractFormViewHelperTest.php:41