TYPO3 API  SVNRelease
AbstractFormViewHelperTest.php
Go to the documentation of this file.
00001 <?php
00002 
00003 /*                                                                        *
00004  * This script belongs to the FLOW3 package "Fluid".                      *
00005  *                                                                        *
00006  * It is free software; you can redistribute it and/or modify it under    *
00007  * the terms of the GNU Lesser General Public License as published by the *
00008  * Free Software Foundation, either version 3 of the License, or (at your *
00009  * option) any later version.                                             *
00010  *                                                                        *
00011  * This script is distributed in the hope that it will be useful, but     *
00012  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
00013  * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser       *
00014  * General Public License for more details.                               *
00015  *                                                                        *
00016  * You should have received a copy of the GNU Lesser General Public       *
00017  * License along with the script.                                         *
00018  * If not, see http://www.gnu.org/licenses/lgpl.html                      *
00019  *                                                                        *
00020  * The TYPO3 project - inspiring people to share!                         *
00021  *                                                                        */
00022 
00023 require_once(dirname(__FILE__) . '/../ViewHelperBaseTestcase.php');
00024 
00025 /**
00026  * Test for the Abstract Form view helper
00027  *
00028  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
00029  */
00030 class Tx_Fluid_Tests_Unit_ViewHelpers_Form_AbstractFormViewHelperTest extends Tx_Fluid_ViewHelpers_ViewHelperBaseTestcase {
00031 
00032     /**
00033      * @test
00034      * @author Robert Lemke <robert@typo3.org>
00035      */
00036     public function renderHiddenIdentityFieldReturnsAHiddenInputFieldContainingTheObjectsUID() { $this->markTestIncomplete("Works differently in v4. Thus, this test does not work"); return;
00037         $className = 'Object' . uniqid();
00038         $fullClassName = 'F3\\Fluid\\ViewHelpers\\Form\\' . $className;
00039         eval('namespace F3\\Fluid\\ViewHelpers\\Form; class ' . $className . ' implements \\F3\\FLOW3\\Persistence\\Aspect\\PersistenceMagicInterface {
00040             public function FLOW3_Persistence_isClone() { return FALSE; }
00041             public function FLOW3_AOP_Proxy_getProperty($name) {}
00042             public function FLOW3_AOP_Proxy_getProxyTargetClassName() {}
00043             public function __clone() {}
00044         }');
00045         $object = $this->getMock($fullClassName);
00046 
00047         $mockPersistenceManager = $this->getMock('Tx_Extbase_Persistence_ManagerInterface');
00048         $mockPersistenceManager->expects($this->once())->method('getIdentifierByObject')->with($object)->will($this->returnValue('123'));
00049 
00050         $expectedResult = chr(10) . '<input type="hidden" name="prefix[theName][__identity]" value="123" />' . chr(10);
00051 
00052         $viewHelper = $this->getAccessibleMock('Tx_Fluid_ViewHelpers_FormViewHelper', array('prefixFieldName', 'registerFieldNameForFormTokenGeneration'), array(), '', FALSE);
00053         $viewHelper->expects($this->any())->method('prefixFieldName')->with('theName')->will($this->returnValue('prefix[theName]'));
00054         $viewHelper->_set('persistenceManager', $mockPersistenceManager);
00055 
00056         $actualResult = $viewHelper->_call('renderHiddenIdentityField', $object, 'theName');
00057         $this->assertSame($expectedResult, $actualResult);
00058     }
00059 
00060     /**
00061      * @test
00062      * @author Robert Lemke <robert@typo3.org>
00063      */
00064     public function renderHiddenIdentityFieldReturnsAHiddenInputFieldIfObjectIsNewButAClone() { $this->markTestIncomplete("Works differently in v4. Thus, this test does not work"); return;
00065         $className = 'Object' . uniqid();
00066         $fullClassName = 'F3\\Fluid\\ViewHelpers\\Form\\' . $className;
00067         eval('namespace F3\\Fluid\\ViewHelpers\\Form; class ' . $className . ' implements \\F3\\FLOW3\\Persistence\\Aspect\\PersistenceMagicInterface {
00068             public function FLOW3_Persistence_isClone() { return TRUE; }
00069             public function FLOW3_AOP_Proxy_getProperty($name) {}
00070             public function FLOW3_AOP_Proxy_getProxyTargetClassName() {}
00071             public function __clone() {}
00072         }');
00073         $object = $this->getMock($fullClassName);
00074 
00075         $mockPersistenceManager = $this->getMock('Tx_Extbase_Persistence_ManagerInterface');
00076         $mockPersistenceManager->expects($this->once())->method('getIdentifierByObject')->with($object)->will($this->returnValue('123'));
00077 
00078         $expectedResult = chr(10) . '<input type="hidden" name="prefix[theName][__identity]" value="123" />' . chr(10);
00079 
00080         $viewHelper = $this->getAccessibleMock('Tx_Fluid_ViewHelpers_FormViewHelper', array('prefixFieldName', 'registerFieldNameForFormTokenGeneration'), array(), '', FALSE);
00081         $viewHelper->expects($this->any())->method('prefixFieldName')->with('theName')->will($this->returnValue('prefix[theName]'));
00082         $viewHelper->_set('persistenceManager', $mockPersistenceManager);
00083 
00084         $actualResult = $viewHelper->_call('renderHiddenIdentityField', $object, 'theName');
00085         $this->assertSame($expectedResult, $actualResult);
00086     }
00087 
00088     /**
00089      * @test
00090      * @author Bastian Waidelich <bastian@typo3.org>
00091      */
00092     public function renderHiddenIdentityFieldReturnsACommentIfTheObjectIsWithoutIdentity() { $this->markTestIncomplete("Works differently in v4. Thus, this test does not work"); return;
00093         $className = 'Object' . uniqid();
00094         $fullClassName = 'F3\\Fluid\\ViewHelpers\\Form\\' . $className;
00095         eval('namespace F3\\Fluid\\ViewHelpers\\Form; class ' . $className . ' implements \\F3\\FLOW3\\Persistence\\Aspect\\PersistenceMagicInterface {
00096             public function FLOW3_Persistence_isClone() { return FALSE; }
00097             public function FLOW3_AOP_Proxy_getProperty($name) {}
00098             public function FLOW3_AOP_Proxy_getProxyTargetClassName() {}
00099             public function __clone() {}
00100         }');
00101         $object = $this->getMock($fullClassName);
00102 
00103         $mockPersistenceManager = $this->getMock('Tx_Extbase_Persistence_ManagerInterface');
00104         $mockPersistenceManager->expects($this->once())->method('getIdentifierByObject')->with($object)->will($this->returnValue(NULL));
00105 
00106         $expectedResult = chr(10) . '<!-- Object of type ' . get_class($object) . ' is without identity -->' . chr(10);
00107 
00108         $viewHelper = $this->getAccessibleMock('Tx_Fluid_ViewHelpers_FormViewHelper', array('prefixFieldName', 'registerFieldNameForFormTokenGeneration'), array(), '', FALSE);
00109         $viewHelper->_set('persistenceManager', $mockPersistenceManager);
00110 
00111         $actualResult = $viewHelper->_call('renderHiddenIdentityField', $object, 'theName');
00112         $this->assertSame($expectedResult, $actualResult);
00113     }
00114 
00115     /**
00116      * @test
00117      * @author Bastian Waidelich <bastian@typo3.org>
00118      */
00119     public function prefixFieldNameReturnsEmptyStringIfGivenFieldNameIsNULL() {
00120         $viewHelper = $this->getAccessibleMock('Tx_Fluid_ViewHelpers_Form_AbstractFormViewHelper', array('dummy'), array(), '', FALSE);
00121         $this->injectDependenciesIntoViewHelper($viewHelper);
00122 
00123         $this->assertSame('', $viewHelper->_call('prefixFieldName', NULL));
00124     }
00125 
00126     /**
00127      * @test
00128      * @author Bastian Waidelich <bastian@typo3.org>
00129      */
00130     public function prefixFieldNameReturnsEmptyStringIfGivenFieldNameIsEmpty() {
00131         $viewHelper = $this->getAccessibleMock('Tx_Fluid_ViewHelpers_Form_AbstractFormViewHelper', array('dummy'), array(), '', FALSE);
00132         $this->injectDependenciesIntoViewHelper($viewHelper);
00133 
00134         $this->assertSame('', $viewHelper->_call('prefixFieldName', ''));
00135     }
00136 
00137     /**
00138      * @test
00139      * @author Bastian Waidelich <bastian@typo3.org>
00140      */
00141     public function prefixFieldNameReturnsGivenFieldNameIfFieldNamePrefixIsEmpty() {
00142         $viewHelper = $this->getAccessibleMock('Tx_Fluid_ViewHelpers_Form_AbstractFormViewHelper', array('dummy'), array(), '', FALSE);
00143         $this->injectDependenciesIntoViewHelper($viewHelper);
00144         $this->viewHelperVariableContainer->expects($this->any())->method('exists')->with('Tx_Fluid_ViewHelpers_FormViewHelper', 'fieldNamePrefix')->will($this->returnValue(TRUE));
00145         $this->viewHelperVariableContainer->expects($this->once())->method('get')->with('Tx_Fluid_ViewHelpers_FormViewHelper', 'fieldNamePrefix')->will($this->returnValue(''));
00146 
00147         $this->assertSame('someFieldName', $viewHelper->_call('prefixFieldName', 'someFieldName'));
00148     }
00149 
00150     /**
00151      * @test
00152      * @author Bastian Waidelich <bastian@typo3.org>
00153      */
00154     public function prefixFieldNamePrefixesGivenFieldNameWithFieldNamePrefix() {
00155         $viewHelper = $this->getAccessibleMock('Tx_Fluid_ViewHelpers_Form_AbstractFormViewHelper', array('dummy'), array(), '', FALSE);
00156         $this->injectDependenciesIntoViewHelper($viewHelper);
00157         $this->viewHelperVariableContainer->expects($this->any())->method('exists')->with('Tx_Fluid_ViewHelpers_FormViewHelper', 'fieldNamePrefix')->will($this->returnValue(TRUE));
00158         $this->viewHelperVariableContainer->expects($this->once())->method('get')->with('Tx_Fluid_ViewHelpers_FormViewHelper', 'fieldNamePrefix')->will($this->returnValue('somePrefix'));
00159 
00160         $this->assertSame('somePrefix[someFieldName]', $viewHelper->_call('prefixFieldName', 'someFieldName'));
00161     }
00162 
00163     /**
00164      * @test
00165      * @author Bastian Waidelich <bastian@typo3.org>
00166      */
00167     public function prefixFieldNamePreservesSquareBracketsOfFieldName() {
00168         $viewHelper = $this->getAccessibleMock('Tx_Fluid_ViewHelpers_Form_AbstractFormViewHelper', array('dummy'), array(), '', FALSE);
00169         $this->injectDependenciesIntoViewHelper($viewHelper);
00170         $this->viewHelperVariableContainer->expects($this->any())->method('exists')->with('Tx_Fluid_ViewHelpers_FormViewHelper', 'fieldNamePrefix')->will($this->returnValue(TRUE));
00171         $this->viewHelperVariableContainer->expects($this->once())->method('get')->with('Tx_Fluid_ViewHelpers_FormViewHelper', 'fieldNamePrefix')->will($this->returnValue('somePrefix[foo]'));
00172 
00173         $this->assertSame('somePrefix[foo][someFieldName][bar]', $viewHelper->_call('prefixFieldName', 'someFieldName[bar]'));
00174     }
00175 }
00176 
00177 ?>