[~FEATURE] Fluid (ViewHelpers): Adjusted AbstractFormViewHelper to be able to namespa...
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / ViewHelpers / Form / AbstractFormViewHelperTest_testcase.php
1 <?php
2
3 /* *
4 * This script is part of the TYPO3 project - inspiring people to share! *
5 * *
6 * TYPO3 is free software; you can redistribute it and/or modify it under *
7 * the terms of the GNU General Public License version 2 as published by *
8 * the Free Software Foundation. *
9 * *
10 * This script is distributed in the hope that it will be useful, but *
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
12 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
13 * Public License for more details. *
14 * */
15
16 require_once(dirname(__FILE__) . '/../ViewHelperBaseTestcase.php');
17
18 /**
19 * Test for the Abstract Form view helper
20 *
21 * @version $Id: AbstractFormViewHelperTest.php 2991 2009-08-06 12:09:58Z robert $
22 * @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
23 */
24 require_once(t3lib_extMgm::extPath('extbase', 'Tests/Base_testcase.php'));
25 class Tx_Fluid_ViewHelpers_Form_AbstractFormViewHelperTest_testcase extends Tx_Fluid_ViewHelpers_ViewHelperBaseTestcase {
26
27 /**
28 * @test
29 * @author Bastian Waidelich <bastian@typo3.org>
30 */
31 public function prefixFieldNameReturnsEmptyStringIfGivenFieldNameIsNULL() {
32 $viewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_Form_AbstractFormViewHelper'), array('dummy'), array(), '', FALSE);
33 $this->injectDependenciesIntoViewHelper($viewHelper);
34
35 $this->assertSame('', $viewHelper->_call('prefixFieldName', NULL));
36 }
37
38 /**
39 * @test
40 * @author Bastian Waidelich <bastian@typo3.org>
41 */
42 public function prefixFieldNameReturnsEmptyStringIfGivenFieldNameIsEmpty() {
43 $viewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_Form_AbstractFormViewHelper'), array('dummy'), array(), '', FALSE);
44 $this->injectDependenciesIntoViewHelper($viewHelper);
45
46 $this->assertSame('', $viewHelper->_call('prefixFieldName', ''));
47 }
48
49 /**
50 * @test
51 * @author Bastian Waidelich <bastian@typo3.org>
52 */
53 public function prefixFieldNameReturnsGivenFieldNameIfFieldNamePrefixIsEmpty() {
54 $viewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_Form_AbstractFormViewHelper'), array('dummy'), array(), '', FALSE);
55 $this->injectDependenciesIntoViewHelper($viewHelper);
56 $this->viewHelperVariableContainer->expects($this->once())->method('get')->with('Tx_Fluid_ViewHelpers_FormViewHelper', 'fieldNamePrefix')->will($this->returnValue(''));
57
58 $this->assertSame('someFieldName', $viewHelper->_call('prefixFieldName', 'someFieldName'));
59 }
60
61 /**
62 * @test
63 * @author Bastian Waidelich <bastian@typo3.org>
64 */
65 public function prefixFieldNamePrefixesGivenFieldNameWithFieldNamePrefix() {
66 $viewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_Form_AbstractFormViewHelper'), array('dummy'), array(), '', FALSE);
67 $this->injectDependenciesIntoViewHelper($viewHelper);
68 $this->viewHelperVariableContainer->expects($this->once())->method('get')->with('Tx_Fluid_ViewHelpers_FormViewHelper', 'fieldNamePrefix')->will($this->returnValue('somePrefix'));
69
70 $this->assertSame('somePrefix[someFieldName]', $viewHelper->_call('prefixFieldName', 'someFieldName'));
71 }
72
73 /**
74 * @test
75 * @author Bastian Waidelich <bastian@typo3.org>
76 */
77 public function prefixFieldNamePreservesSquareBracketsOfFieldName() {
78 $viewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_Form_AbstractFormViewHelper'), array('dummy'), array(), '', FALSE);
79 $this->injectDependenciesIntoViewHelper($viewHelper);
80 $this->viewHelperVariableContainer->expects($this->once())->method('get')->with('Tx_Fluid_ViewHelpers_FormViewHelper', 'fieldNamePrefix')->will($this->returnValue('somePrefix[foo]'));
81
82 $this->assertSame('somePrefix[foo][someFieldName][bar]', $viewHelper->_call('prefixFieldName', 'someFieldName[bar]'));
83 }
84 }
85
86 ?>