[+BUGFIX] Fix unit tests
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / Unit / ViewHelpers / Form / RadioViewHelperTest.php
1 <?php
2
3 /* *
4 * This script belongs to the FLOW3 package "Fluid". *
5 * *
6 * It is free software; you can redistribute it and/or modify it under *
7 * the terms of the GNU Lesser General Public License as published by the *
8 * Free Software Foundation, either version 3 of the License, or (at your *
9 * option) any later version. *
10 * *
11 * This script is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
13 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
14 * General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with the script. *
18 * If not, see http://www.gnu.org/licenses/lgpl.html *
19 * *
20 * The TYPO3 project - inspiring people to share! *
21 * */
22
23 require_once(dirname(__FILE__) . '/../ViewHelperBaseTestcase.php');
24
25 /**
26 * Test for the "Radio" Form view helper
27 *
28 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
29 */
30 class Tx_Fluid_Tests_Unit_ViewHelpers_Form_RadioViewHelperTest extends Tx_Fluid_ViewHelpers_ViewHelperBaseTestcase {
31
32 /**
33 * var Tx_Fluid_ViewHelpers_Form_RadioViewHelper
34 */
35 protected $viewHelper;
36
37 public function setUp() {
38 parent::setUp();
39 $this->viewHelper = $this->getAccessibleMock('Tx_Fluid_ViewHelpers_Form_RadioViewHelper', array('setErrorClassAttribute', 'getName', 'getValue', 'isObjectAccessorMode', 'getPropertyValue', 'registerFieldNameForFormTokenGeneration'));
40 $this->injectDependenciesIntoViewHelper($this->viewHelper);
41 $this->viewHelper->initializeArguments();
42 }
43
44 /**
45 * @test
46 * @author Bastian Waidelich <bastian@typo3.org>
47 */
48 public function renderCorrectlySetsTagNameAndDefaultAttributes() {
49 $mockTagBuilder = $this->getMock('Tx_Fluid_Core_ViewHelper_TagBuilder', array('setTagName', 'addAttribute'));
50 $mockTagBuilder->expects($this->once())->method('setTagName')->with('input');
51 $mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'radio');
52 $mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'foo');
53 $this->viewHelper->expects($this->once())->method('registerFieldNameForFormTokenGeneration')->with('foo');
54 $mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', 'bar');
55
56 $this->viewHelper->expects($this->any())->method('getName')->will($this->returnValue('foo'));
57 $this->viewHelper->expects($this->any())->method('getValue')->will($this->returnValue('bar'));
58 $this->viewHelper->injectTagBuilder($mockTagBuilder);
59
60 $this->viewHelper->initialize();
61 $this->viewHelper->render();
62 }
63
64 /**
65 * @test
66 * @author Bastian Waidelich <bastian@typo3.org>
67 */
68 public function renderSetsCheckedAttributeIfSpecified() {
69 $mockTagBuilder = $this->getMock('Tx_Fluid_Core_ViewHelper_TagBuilder', array('setTagName', 'addAttribute'));
70 $mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'radio');
71 $mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'foo');
72 $this->viewHelper->expects($this->once())->method('registerFieldNameForFormTokenGeneration')->with('foo');
73 $mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', 'bar');
74 $mockTagBuilder->expects($this->at(4))->method('addAttribute')->with('checked', 'checked');
75
76 $this->viewHelper->expects($this->any())->method('getName')->will($this->returnValue('foo'));
77 $this->viewHelper->expects($this->any())->method('getValue')->will($this->returnValue('bar'));
78 $this->viewHelper->injectTagBuilder($mockTagBuilder);
79
80 $this->viewHelper->initialize();
81 $this->viewHelper->render(TRUE);
82 }
83
84 /**
85 * @test
86 * @author Bastian Waidelich <bastian@typo3.org>
87 */
88 public function renderIgnoresBoundPropertyIfCheckedIsSet() {
89 $mockTagBuilder = $this->getMock('Tx_Fluid_Core_ViewHelper_TagBuilder', array('setTagName', 'addAttribute'));
90 $mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'radio');
91 $mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'foo');
92 $mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', 'bar');
93
94 $this->viewHelper->expects($this->any())->method('getName')->will($this->returnValue('foo'));
95 $this->viewHelper->expects($this->any())->method('getValue')->will($this->returnValue('bar'));
96 $this->viewHelper->expects($this->never())->method('isObjectAccessorMode')->will($this->returnValue(TRUE));
97 $this->viewHelper->expects($this->never())->method('getPropertyValue')->will($this->returnValue(TRUE));
98 $this->viewHelper->injectTagBuilder($mockTagBuilder);
99
100 $this->viewHelper->initialize();
101 $this->viewHelper->render(TRUE);
102 $this->viewHelper->render(FALSE);
103 }
104
105 /**
106 * @test
107 * @author Bastian Waidelich <bastian@typo3.org>
108 */
109 public function renderCorrectlySetsCheckedAttributeIfCheckboxIsBoundToAPropertyOfTypeBoolean() {
110 $mockTagBuilder = $this->getMock('Tx_Fluid_Core_ViewHelper_TagBuilder', array('setTagName', 'addAttribute'));
111 $mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'radio');
112 $mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'foo');
113 $this->viewHelper->expects($this->once())->method('registerFieldNameForFormTokenGeneration')->with('foo');
114 $mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', 'bar');
115 $mockTagBuilder->expects($this->at(4))->method('addAttribute')->with('checked', 'checked');
116
117 $this->viewHelper->expects($this->any())->method('getName')->will($this->returnValue('foo'));
118 $this->viewHelper->expects($this->any())->method('getValue')->will($this->returnValue('bar'));
119 $this->viewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(TRUE));
120 $this->viewHelper->expects($this->any())->method('getPropertyValue')->will($this->returnValue(TRUE));
121 $this->viewHelper->injectTagBuilder($mockTagBuilder);
122
123 $this->viewHelper->initialize();
124 $this->viewHelper->render();
125 }
126
127 /**
128 * @test
129 * @author Bastian Waidelich <bastian@typo3.org>
130 */
131 public function renderDoesNotAppendSquareBracketsToNameAttributeIfBoundToAPropertyOfTypeArray() {
132 $mockTagBuilder = $this->getMock('Tx_Fluid_Core_ViewHelper_TagBuilder', array('setTagName', 'addAttribute'));
133 $mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'radio');
134 $mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'foo');
135 $this->viewHelper->expects($this->once())->method('registerFieldNameForFormTokenGeneration')->with('foo');
136 $mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', 'bar');
137
138 $this->viewHelper->expects($this->any())->method('getName')->will($this->returnValue('foo'));
139 $this->viewHelper->expects($this->any())->method('getValue')->will($this->returnValue('bar'));
140 $this->viewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(TRUE));
141 $this->viewHelper->expects($this->any())->method('getPropertyValue')->will($this->returnValue(array()));
142 $this->viewHelper->injectTagBuilder($mockTagBuilder);
143
144 $this->viewHelper->initialize();
145 $this->viewHelper->render();
146 }
147
148 /**
149 * @test
150 * @author Bastian Waidelich <bastian@typo3.org>
151 */
152 public function renderCorrectlySetsCheckedAttributeIfCheckboxIsBoundToAPropertyOfTypeString() {
153 $mockTagBuilder = $this->getMock('Tx_Fluid_Core_ViewHelper_TagBuilder', array('setTagName', 'addAttribute'));
154 $mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'radio');
155 $mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'foo');
156 $this->viewHelper->expects($this->once())->method('registerFieldNameForFormTokenGeneration')->with('foo');
157 $mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', 'bar');
158 $mockTagBuilder->expects($this->at(4))->method('addAttribute')->with('checked', 'checked');
159
160 $this->viewHelper->expects($this->any())->method('getName')->will($this->returnValue('foo'));
161 $this->viewHelper->expects($this->any())->method('getValue')->will($this->returnValue('bar'));
162 $this->viewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(TRUE));
163 $this->viewHelper->expects($this->any())->method('getPropertyValue')->will($this->returnValue('bar'));
164 $this->viewHelper->injectTagBuilder($mockTagBuilder);
165
166 $this->viewHelper->initialize();
167 $this->viewHelper->render();
168 }
169
170 /**
171 * @test
172 * @author Bastian Waidelich <bastian@typo3.org>
173 */
174 public function renderCallsSetErrorClassAttribute() {
175 $this->viewHelper->expects($this->once())->method('setErrorClassAttribute');
176 $this->viewHelper->render();
177 }
178 }
179
180 ?>