TYPO3 CMS  TYPO3_6-2
AbstractFormViewHelperTest.php
Go to the documentation of this file.
1 <?php
3 
4 /* *
5  * This script is backported from the FLOW3 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  * *
12  * This script is distributed in the hope that it will be useful, but *
13  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
14  * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
15  * General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU Lesser General Public *
18  * License along with the script. *
19  * If not, see http://www.gnu.org/licenses/lgpl.html *
20  * *
21  * The TYPO3 project - inspiring people to share! *
22  * */
23 
28 
33  $className = $this->getUniqueId('Object');
34  $fullClassName = '\\TYPO3\\CMS\\Fluid\\ViewHelpers\\Form\\' . $className;
35  eval('namespace TYPO3\\CMS\\Fluid\\ViewHelpers\\Form; class ' . $className . ' extends \\TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity {
36  }');
37  $object = $this->getAccessibleMock($fullClassName, array('dummy'));
38  $object->_set('uid', 123);
39  $expectedResult = chr(10) . '<input type="hidden" name="prefix[theName][__identity]" value="123" />' . chr(10);
40  $viewHelper = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\ViewHelpers\\FormViewHelper', array('prefixFieldName', 'registerFieldNameForFormTokenGeneration'), array(), '', FALSE);
41  $viewHelper->expects($this->any())->method('prefixFieldName')->with('theName')->will($this->returnValue('prefix[theName]'));
42  $actualResult = $viewHelper->_call('renderHiddenIdentityField', $object, 'theName');
43  $this->assertSame($expectedResult, $actualResult);
44  }
45 
50  $className = $this->getUniqueId('Object');
51  eval('class ' . $className . ' extends TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity {
52  }');
53  $object = $this->getAccessibleMock($className, array('dummy'));
54  $object->_set('uid', 123);
55  $object = clone $object;
56  $expectedResult = chr(10) . '<input type="hidden" name="prefix[theName][__identity]" value="123" />' . chr(10);
57  $viewHelper = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\ViewHelpers\\FormViewHelper', array('prefixFieldName', 'registerFieldNameForFormTokenGeneration'), array(), '', FALSE);
58  $viewHelper->expects($this->any())->method('prefixFieldName')->with('theName')->will($this->returnValue('prefix[theName]'));
59  $actualResult = $viewHelper->_call('renderHiddenIdentityField', $object, 'theName');
60  $this->assertSame($expectedResult, $actualResult);
61  }
62 
67  $viewHelper = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\ViewHelpers\\Form\\AbstractFormViewHelper', array('dummy'), array(), '', FALSE);
68  $this->injectDependenciesIntoViewHelper($viewHelper);
69  $this->assertSame('', $viewHelper->_call('prefixFieldName', NULL));
70  }
71 
76  $viewHelper = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\ViewHelpers\\Form\\AbstractFormViewHelper', array('dummy'), array(), '', FALSE);
77  $this->injectDependenciesIntoViewHelper($viewHelper);
78  $this->assertSame('', $viewHelper->_call('prefixFieldName', ''));
79  }
80 
85  $viewHelper = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\ViewHelpers\\Form\\AbstractFormViewHelper', array('dummy'), array(), '', FALSE);
86  $this->injectDependenciesIntoViewHelper($viewHelper);
87  $this->viewHelperVariableContainer->expects($this->any())->method('exists')->with('TYPO3\\CMS\\Fluid\\ViewHelpers\\FormViewHelper', 'fieldNamePrefix')->will($this->returnValue(TRUE));
88  $this->viewHelperVariableContainer->expects($this->once())->method('get')->with('TYPO3\\CMS\\Fluid\\ViewHelpers\\FormViewHelper', 'fieldNamePrefix')->will($this->returnValue(''));
89  $this->assertSame('someFieldName', $viewHelper->_call('prefixFieldName', 'someFieldName'));
90  }
91 
96  $viewHelper = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\ViewHelpers\\Form\\AbstractFormViewHelper', array('dummy'), array(), '', FALSE);
97  $this->injectDependenciesIntoViewHelper($viewHelper);
98  $this->viewHelperVariableContainer->expects($this->any())->method('exists')->with('TYPO3\\CMS\\Fluid\\ViewHelpers\\FormViewHelper', 'fieldNamePrefix')->will($this->returnValue(TRUE));
99  $this->viewHelperVariableContainer->expects($this->once())->method('get')->with('TYPO3\\CMS\\Fluid\\ViewHelpers\\FormViewHelper', 'fieldNamePrefix')->will($this->returnValue('somePrefix'));
100  $this->assertSame('somePrefix[someFieldName]', $viewHelper->_call('prefixFieldName', 'someFieldName'));
101  }
102 
107  $viewHelper = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\ViewHelpers\\Form\\AbstractFormViewHelper', array('dummy'), array(), '', FALSE);
108  $this->injectDependenciesIntoViewHelper($viewHelper);
109  $this->viewHelperVariableContainer->expects($this->any())->method('exists')->with('TYPO3\\CMS\\Fluid\\ViewHelpers\\FormViewHelper', 'fieldNamePrefix')->will($this->returnValue(TRUE));
110  $this->viewHelperVariableContainer->expects($this->once())->method('get')->with('TYPO3\\CMS\\Fluid\\ViewHelpers\\FormViewHelper', 'fieldNamePrefix')->will($this->returnValue('somePrefix[foo]'));
111  $this->assertSame('somePrefix[foo][someFieldName][bar]', $viewHelper->_call('prefixFieldName', 'someFieldName[bar]'));
112  }
113 }
injectDependenciesIntoViewHelper(\TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper $viewHelper)
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)