‪TYPO3CMS  10.4
AbstractFormViewHelperTest.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 
21 use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
22 
26 class ‪AbstractFormViewHelperTest extends ViewHelperBaseTestcase
27 {
32  {
33  $extendsAbstractEntity = new ‪ExtendsAbstractEntity();
34  $extendsAbstractEntity->_setProperty('uid', 123);
35  $expectedResult = chr(10) . '<input type="hidden" name="prefix[theName][__identity]" value="123" />' . chr(10);
36  $viewHelper = $this->getAccessibleMock(FormViewHelper::class, ['prefixFieldName', 'registerFieldNameForFormTokenGeneration'], [], '', false);
37  $viewHelper->expects(self::any())->method('prefixFieldName')->with('theName')->willReturn('prefix[theName]');
38  $actualResult = $viewHelper->_call('renderHiddenIdentityField', $extendsAbstractEntity, 'theName');
39  self::assertSame($expectedResult, $actualResult);
40  }
41 
46  {
47  $extendsAbstractEntity = new ‪ExtendsAbstractEntity();
48  $extendsAbstractEntity->_setProperty('uid', 123);
49  $object = clone $extendsAbstractEntity;
50  $expectedResult = chr(10) . '<input type="hidden" name="prefix[theName][__identity]" value="123" />' . chr(10);
51  $viewHelper = $this->getAccessibleMock(FormViewHelper::class, ['prefixFieldName', 'registerFieldNameForFormTokenGeneration'], [], '', false);
52  $viewHelper->expects(self::any())->method('prefixFieldName')->with('theName')->willReturn('prefix[theName]');
53  $actualResult = $viewHelper->_call('renderHiddenIdentityField', $extendsAbstractEntity, 'theName');
54  self::assertSame($expectedResult, $actualResult);
55  }
56 
61  {
62  $viewHelper = $this->getAccessibleMock(AbstractFormViewHelper::class, ['dummy'], [], '', false);
63  $this->injectDependenciesIntoViewHelper($viewHelper);
64  self::assertSame('', $viewHelper->_call('prefixFieldName', null));
65  }
66 
71  {
72  $viewHelper = $this->getAccessibleMock(AbstractFormViewHelper::class, ['dummy'], [], '', false);
73  $this->injectDependenciesIntoViewHelper($viewHelper);
74  self::assertSame('', $viewHelper->_call('prefixFieldName', ''));
75  }
76 
81  {
82  $viewHelper = $this->getAccessibleMock(AbstractFormViewHelper::class, ['dummy'], [], '', false);
83  $this->injectDependenciesIntoViewHelper($viewHelper);
84  $this->viewHelperVariableContainer->exists(FormViewHelper::class, 'fieldNamePrefix')->willReturn(true);
85  $this->viewHelperVariableContainer->get(FormViewHelper::class, 'fieldNamePrefix')->willReturn('');
86  self::assertSame('someFieldName', $viewHelper->_call('prefixFieldName', 'someFieldName'));
87  }
88 
93  {
94  $viewHelper = $this->getAccessibleMock(AbstractFormViewHelper::class, ['dummy'], [], '', false);
95  $this->injectDependenciesIntoViewHelper($viewHelper);
96  $this->viewHelperVariableContainer->exists(FormViewHelper::class, 'fieldNamePrefix')->willReturn(true);
97  $this->viewHelperVariableContainer->get(FormViewHelper::class, 'fieldNamePrefix')->willReturn('somePrefix');
98  self::assertSame('somePrefix[someFieldName]', $viewHelper->_call('prefixFieldName', 'someFieldName'));
99  }
100 
105  {
106  $viewHelper = $this->getAccessibleMock(AbstractFormViewHelper::class, ['dummy'], [], '', false);
107  $this->injectDependenciesIntoViewHelper($viewHelper);
108  $this->viewHelperVariableContainer->exists(FormViewHelper::class, 'fieldNamePrefix')->willReturn(true);
109  $this->viewHelperVariableContainer->get(FormViewHelper::class, 'fieldNamePrefix')->willReturn('somePrefix[foo]');
110  self::assertSame('somePrefix[foo][someFieldName][bar]', $viewHelper->_call('prefixFieldName', 'someFieldName[bar]'));
111  }
112 }
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\AbstractFormViewHelperTest\renderHiddenIdentityFieldReturnsAHiddenInputFieldContainingTheObjectsUID
‪renderHiddenIdentityFieldReturnsAHiddenInputFieldContainingTheObjectsUID()
Definition: AbstractFormViewHelperTest.php:31
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\AbstractFormViewHelperTest\prefixFieldNameReturnsEmptyStringIfGivenFieldNameIsEmpty
‪prefixFieldNameReturnsEmptyStringIfGivenFieldNameIsEmpty()
Definition: AbstractFormViewHelperTest.php:70
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\ExtendsAbstractEntity
Definition: ExtendsAbstractEntity.php:24
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\AbstractFormViewHelperTest\prefixFieldNameReturnsEmptyStringIfGivenFieldNameIsNULL
‪prefixFieldNameReturnsEmptyStringIfGivenFieldNameIsNULL()
Definition: AbstractFormViewHelperTest.php:60
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\AbstractFormViewHelperTest\prefixFieldNameReturnsGivenFieldNameIfFieldNamePrefixIsEmpty
‪prefixFieldNameReturnsGivenFieldNameIfFieldNamePrefixIsEmpty()
Definition: AbstractFormViewHelperTest.php:80
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\AbstractFormViewHelperTest\prefixFieldNamePrefixesGivenFieldNameWithFieldNamePrefix
‪prefixFieldNamePrefixesGivenFieldNameWithFieldNamePrefix()
Definition: AbstractFormViewHelperTest.php:92
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\AbstractFormViewHelperTest\prefixFieldNamePreservesSquareBracketsOfFieldName
‪prefixFieldNamePreservesSquareBracketsOfFieldName()
Definition: AbstractFormViewHelperTest.php:104
‪TYPO3\CMS\Fluid\ViewHelpers\FormViewHelper
Definition: FormViewHelper.php:61
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\AbstractFormViewHelperTest
Definition: AbstractFormViewHelperTest.php:27
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form
Definition: AbstractFormFieldViewHelperTest.php:16
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\AbstractFormViewHelperTest\renderHiddenIdentityFieldReturnsAHiddenInputFieldIfObjectIsNewButAClone
‪renderHiddenIdentityFieldReturnsAHiddenInputFieldIfObjectIsNewButAClone()
Definition: AbstractFormViewHelperTest.php:45
‪TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormViewHelper
Definition: AbstractFormViewHelper.php:31