Feature #3661 » 3661_tx_fluid_checkbox_and_radio_viewhelpers.patch

Patch for tx_fluid extension - Bastian Waidelich, 2009-08-09 21:50

View differences:

Classes/ViewHelpers/Form/CheckboxViewHelper.php (revision 0)
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
/**
24
 * View Helper which creates a simple checkbox (<input type="checkbox">).
25
 *
26
 * = Examples =
27
 *
28
 * <code title="Example">
29
 * <f:form.checkbox name="myCheckBox" value="someValue" />
30
 * </code>
31
 *
32
 * Output:
33
 * <input type="checkbox" name="myCheckBox" value="someValue" />
34
 *
35
 * <code title="Preselect">
36
 * <f:form.checkbox name="myCheckBox" value="someValue" checked="{object.value} == 5" />
37
 * </code>
38
 *
39
 * Output:
40
 * <input type="checkbox" name="myCheckBox" value="someValue" checked="checked" />
41
 * (depending on $object)
42
 *
43
 * <code title="Bind to object property">
44
 * <f:form.checkbox property="interests" value="TYPO3" />
45
 * </code>
46
 *
47
 * Output:
48
 * <input type="checkbox" name="user[interests][]" value="TYPO3" checked="checked" />
49
 * (depending on property "interests")
50
 *
51
 * @version $Id$
52
 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
53
 * @scope prototype
54
 */
55
class Tx_Fluid_ViewHelpers_Form_CheckboxViewHelper extends Tx_Fluid_ViewHelpers_Form_AbstractFormFieldViewHelper {
56

  
57
	/**
58
	 * @var string
59
	 */
60
	protected $tagName = 'input';
61

  
62
	/**
63
	 * Initialize the arguments.
64
	 *
65
	 * @return void
66
	 * @author Bastian Waidelich <bastian@typo3.org>
67
	 * @api
68
	 */
69
	public function initializeArguments() {
70
		parent::initializeArguments();
71
		$this->registerTagAttribute('disabled', 'string', 'Specifies that the input element should be disabled when the page loads');
72
		$this->registerArgument('errorClass', 'string', 'CSS class to set if there are errors for this view helper', FALSE, 'f3-form-error');
73
		$this->registerArgument('value', 'string', 'Value of input tag. Required for checkboxes', TRUE);
74
		$this->registerUniversalTagAttributes();
75
	}
76

  
77
	/**
78
	 * Renders the checkbox.
79
	 *
80
	 * @param boolean $checked Specifies that the input element should be preselected
81
	 *
82
	 * @return string
83
	 * @author Bastian Waidelich <bastian@typo3.org>
84
	 * @api
85
	 */
86
	public function render($checked = NULL) {
87
		$this->tag->addAttribute('type', 'checkbox');
88

  
89
		$nameAttribute = $this->getName();
90
		$valueAttribute = $this->getValue();
91
		if ($checked === NULL && $this->isObjectAccessorMode()) {
92
			$propertyValue = $this->getPropertyValue();
93
			if (is_bool($propertyValue)) {
94
				$checked = $propertyValue === (boolean)$valueAttribute;
95
			} elseif (is_array($propertyValue)) {
96
				$checked = in_array($valueAttribute, $propertyValue);
97
				$nameAttribute .= '[]';
98
			} else {
99
				throw new Tx_Fluid_Core_ViewHelper_Exception('Checkbox viewhelpers can only be bound to properties of type boolean or array. Property "' . $this->arguments['property'] . '" is of type "' . (is_object($propertyValue) ? get_class($propertyValue) : gettype($propertyValue)) . '".' , 1248261038);
100
			}
101
		}
102

  
103
		$this->tag->addAttribute('name', $nameAttribute);
104
		$this->tag->addAttribute('value', $valueAttribute);
105
		if ($checked) {
106
			$this->tag->addAttribute('checked', 'checked');
107
		}
108

  
109
		$this->setErrorClassAttribute();
110

  
111
		return $this->tag->render();
112
	}
113
}
114

  
115
?>
0 116

  
Classes/ViewHelpers/Form/RadioViewHelper.php (revision 0)
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
/**
24
 * View Helper which creates a simple radio button (<input type="radio">).
25
 *
26
 * = Examples =
27
 *
28
 * <code title="Example">
29
 * <f:form.radio name="myRadioButton" value="someValue" />
30
 * </code>
31
 *
32
 * Output:
33
 * <input type="radio" name="myRadioButton" value="someValue" />
34
 *
35
 * <code title="Preselect">
36
 * <f:form.radio name="myRadioButton" value="someValue" checked="{object.value} == 5" />
37
 * </code>
38
 *
39
 * Output:
40
 * <input type="radio" name="myRadioButton" value="someValue" checked="checked" />
41
 * (depending on $object)
42
 *
43
 * <code title="Bind to object property">
44
 * <f:form.radio property="newsletter" value="1" /> yes
45
 * <f:form.radio property="newsletter" value="0" /> no
46
 * </code>
47
 *
48
 * Output:
49
 * <input type="radio" name="user[newsletter]" value="1" checked="checked" /> yes
50
 * <input type="radio" name="user[newsletter]" value="0" /> no
51
 * (depending on property "newsletter")
52
 *
53
 * @version $Id$
54
 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
55
 * @scope prototype
56
 */
57
class Tx_Fluid_ViewHelpers_Form_RadioViewHelper extends Tx_Fluid_ViewHelpers_Form_AbstractFormFieldViewHelper {
58

  
59
	/**
60
	 * @var string
61
	 */
62
	protected $tagName = 'input';
63

  
64
	/**
65
	 * Initialize the arguments.
66
	 *
67
	 * @return void
68
	 * @author Bastian Waidelich <bastian@typo3.org>
69
	 * @api
70
	 */
71
	public function initializeArguments() {
72
		parent::initializeArguments();
73
		$this->registerTagAttribute('disabled', 'string', 'Specifies that the input element should be disabled when the page loads');
74
		$this->registerArgument('errorClass', 'string', 'CSS class to set if there are errors for this view helper', FALSE, 'f3-form-error');
75
		$this->registerArgument('value', 'string', 'Value of input tag. Required for radio buttons', TRUE);
76
		$this->registerUniversalTagAttributes();
77
	}
78

  
79
	/**
80
	 * Renders the checkbox.
81
	 *
82
	 * @param boolean $checked Specifies that the input element should be preselected
83
	 *
84
	 * @return string
85
	 * @author Bastian Waidelich <bastian@typo3.org>
86
	 * @api
87
	 */
88
	public function render($checked = NULL) {
89
		$this->tag->addAttribute('type', 'radio');
90

  
91
		$nameAttribute = $this->getName();
92
		$valueAttribute = $this->getValue();
93
		if ($checked === NULL && $this->isObjectAccessorMode()) {
94
			$propertyValue = $this->getPropertyValue();
95
			// no type-safe comparisation by intention
96
			$checked = $propertyValue == $valueAttribute;
97
		}
98

  
99
		$this->tag->addAttribute('name', $nameAttribute);
100
		$this->tag->addAttribute('value', $valueAttribute);
101
		if ($checked) {
102
			$this->tag->addAttribute('checked', 'checked');
103
		}
104

  
105
		$this->setErrorClassAttribute();
106

  
107
		return $this->tag->render();
108
	}
109
}
110

  
111
?>
0 112

  
Tests/ViewHelpers/Form/CheckboxViewHelperTest_testcase.php (revision 0)
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 "Checkbox" Form view helper
20
 *
21
 * @version $Id$
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_CheckboxViewHelperTest_testcase extends Tx_Fluid_ViewHelpers_ViewHelperBaseTestcase {
26

  
27
	/**
28
	 * var Tx_Fluid_ViewHelpers_Form_CheckboxViewHelper
29
	 */
30
	protected $viewHelper;
31

  
32
	public function setUp() {
33
		parent::setUp();
34
		$this->viewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_Form_CheckboxViewHelper'), array('setErrorClassAttribute', 'getName', 'getValue', 'isObjectAccessorMode', 'getPropertyValue'));
35
		$this->injectDependenciesIntoViewHelper($this->viewHelper);
36
		$this->viewHelper->initializeArguments();
37
	}
38

  
39
	/**
40
	 * @test
41
	 * @author Bastian Waidelich <bastian@typo3.org>
42
	 */
43
	public function renderCorrectlySetsTagNameAndDefaultAttributes() {
44
		$mockTagBuilder = $this->getMock('Tx_Fluid_Core_ViewHelper_TagBuilder', array('setTagName', 'addAttribute'));
45
		$mockTagBuilder->expects($this->once())->method('setTagName')->with('input');
46
		$mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'checkbox');
47
		$mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'foo');
48
		$mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', 'bar');
49

  
50
		$this->viewHelper->expects($this->any())->method('getName')->will($this->returnValue('foo'));
51
		$this->viewHelper->expects($this->any())->method('getValue')->will($this->returnValue('bar'));
52
		$this->viewHelper->injectTagBuilder($mockTagBuilder);
53

  
54
		$this->viewHelper->initialize();
55
		$this->viewHelper->render();
56
	}
57

  
58
	/**
59
	 * @test
60
	 * @author Bastian Waidelich <bastian@typo3.org>
61
	 */
62
	public function renderSetsCheckedAttributeIfSpecified() {
63
		$mockTagBuilder = $this->getMock('Tx_Fluid_Core_ViewHelper_TagBuilder', array('setTagName', 'addAttribute'));
64
		$mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'checkbox');
65
		$mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'foo');
66
		$mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', 'bar');
67
		$mockTagBuilder->expects($this->at(4))->method('addAttribute')->with('checked', 'checked');
68

  
69
		$this->viewHelper->expects($this->any())->method('getName')->will($this->returnValue('foo'));
70
		$this->viewHelper->expects($this->any())->method('getValue')->will($this->returnValue('bar'));
71
		$this->viewHelper->injectTagBuilder($mockTagBuilder);
72

  
73
		$this->viewHelper->initialize();
74
		$this->viewHelper->render(TRUE);
75
	}
76

  
77
	/**
78
	 * @test
79
	 * @author Bastian Waidelich <bastian@typo3.org>
80
	 */
81
	public function renderIgnoresBoundPropertyIfCheckedIsSet() {
82
		$mockTagBuilder = $this->getMock('Tx_Fluid_Core_ViewHelper_TagBuilder', array('setTagName', 'addAttribute'));
83
		$mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'checkbox');
84
		$mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'foo');
85
		$mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', 'bar');
86

  
87
		$this->viewHelper->expects($this->any())->method('getName')->will($this->returnValue('foo'));
88
		$this->viewHelper->expects($this->any())->method('getValue')->will($this->returnValue('bar'));
89
		$this->viewHelper->expects($this->never())->method('isObjectAccessorMode')->will($this->returnValue(TRUE));
90
		$this->viewHelper->expects($this->never())->method('getPropertyValue')->will($this->returnValue(TRUE));
91
		$this->viewHelper->injectTagBuilder($mockTagBuilder);
92

  
93
		$this->viewHelper->initialize();
94
		$this->viewHelper->render(TRUE);
95
		$this->viewHelper->render(FALSE);
96
	}
97

  
98
	/**
99
	 * @test
100
	 * @author Bastian Waidelich <bastian@typo3.org>
101
	 */
102
	public function renderCorrectlySetsCheckedAttributeIfCheckboxIsBoundToAPropertyOfTypeBoolean() {
103
		$mockTagBuilder = $this->getMock('Tx_Fluid_Core_ViewHelper_TagBuilder', array('setTagName', 'addAttribute'));
104
		$mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'checkbox');
105
		$mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'foo');
106
		$mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', 'bar');
107
		$mockTagBuilder->expects($this->at(4))->method('addAttribute')->with('checked', 'checked');
108

  
109
		$this->viewHelper->expects($this->any())->method('getName')->will($this->returnValue('foo'));
110
		$this->viewHelper->expects($this->any())->method('getValue')->will($this->returnValue('bar'));
111
		$this->viewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(TRUE));
112
		$this->viewHelper->expects($this->any())->method('getPropertyValue')->will($this->returnValue(TRUE));
113
		$this->viewHelper->injectTagBuilder($mockTagBuilder);
114

  
115
		$this->viewHelper->initialize();
116
		$this->viewHelper->render();
117
	}
118

  
119
	/**
120
	 * @test
121
	 * @author Bastian Waidelich <bastian@typo3.org>
122
	 */
123
	public function renderAppendsSquareBracketsToNameAttributeIfBoundToAPropertyOfTypeArray() {
124
		$mockTagBuilder = $this->getMock('Tx_Fluid_Core_ViewHelper_TagBuilder', array('setTagName', 'addAttribute'));
125
		$mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'checkbox');
126
		$mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'foo[]');
127
		$mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', 'bar');
128

  
129
		$this->viewHelper->expects($this->any())->method('getName')->will($this->returnValue('foo'));
130
		$this->viewHelper->expects($this->any())->method('getValue')->will($this->returnValue('bar'));
131
		$this->viewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(TRUE));
132
		$this->viewHelper->expects($this->any())->method('getPropertyValue')->will($this->returnValue(array()));
133
		$this->viewHelper->injectTagBuilder($mockTagBuilder);
134

  
135
		$this->viewHelper->initialize();
136
		$this->viewHelper->render();
137
	}
138

  
139
	/**
140
	 * @test
141
	 * @author Bastian Waidelich <bastian@typo3.org>
142
	 */
143
	public function renderCorrectlySetsCheckedAttributeIfCheckboxIsBoundToAPropertyOfTypeArray() {
144
		$mockTagBuilder = $this->getMock('Tx_Fluid_Core_ViewHelper_TagBuilder', array('setTagName', 'addAttribute'));
145
		$mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'checkbox');
146
		$mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'foo[]');
147
		$mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', 'bar');
148
		$mockTagBuilder->expects($this->at(4))->method('addAttribute')->with('checked', 'checked');
149

  
150
		$this->viewHelper->expects($this->any())->method('getName')->will($this->returnValue('foo'));
151
		$this->viewHelper->expects($this->any())->method('getValue')->will($this->returnValue('bar'));
152
		$this->viewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(TRUE));
153
		$this->viewHelper->expects($this->any())->method('getPropertyValue')->will($this->returnValue(array('foo', 'bar', 'baz')));
154
		$this->viewHelper->injectTagBuilder($mockTagBuilder);
155

  
156
		$this->viewHelper->initialize();
157
		$this->viewHelper->render();
158
	}
159

  
160
	/**
161
	 * @test
162
	 * @expectedException Tx_Fluid_Core_ViewHelper_Exception
163
	 * @author Bastian Waidelich <bastian@typo3.org>
164
	 */
165
	public function bindingObjectsToACheckboxThatAreNotOfTypeBooleanOrArrayThrowsException() {
166
		$mockTagBuilder = $this->getMock('Tx_Fluid_Core_ViewHelper_TagBuilder', array('setTagName', 'addAttribute'));
167

  
168
		$this->viewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(TRUE));
169
		$this->viewHelper->expects($this->any())->method('getPropertyValue')->will($this->returnValue(new stdClass()));
170
		$this->viewHelper->injectTagBuilder($mockTagBuilder);
171

  
172
		$this->viewHelper->initialize();
173
		$this->viewHelper->render();
174
	}
175

  
176
	/**
177
	 * @test
178
	 * @author Bastian Waidelich <bastian@typo3.org>
179
	 */
180
	public function renderCallsSetErrorClassAttribute() {
181
		$this->viewHelper->expects($this->once())->method('setErrorClassAttribute');
182
		$this->viewHelper->render();
183
	}
184
}
185

  
186
?>
0 187

  
Tests/ViewHelpers/Form/RadioViewHelperTest_testcase.php (revision 0)
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 "Radio" Form view helper
20
 *
21
 * @version $Id$
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_RadioViewHelperTest_testcase extends Tx_Fluid_ViewHelpers_ViewHelperBaseTestcase {
26

  
27
	/**
28
	 * var Tx_Fluid_ViewHelpers_Form_RadioViewHelper
29
	 */
30
	protected $viewHelper;
31

  
32
	public function setUp() {
33
		parent::setUp();
34
		$this->viewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_Form_RadioViewHelper'), array('setErrorClassAttribute', 'getName', 'getValue', 'isObjectAccessorMode', 'getPropertyValue'));
35
		$this->injectDependenciesIntoViewHelper($this->viewHelper);
36
		$this->viewHelper->initializeArguments();
37
	}
38

  
39
	/**
40
	 * @test
41
	 * @author Bastian Waidelich <bastian@typo3.org>
42
	 */
43
	public function renderCorrectlySetsTagNameAndDefaultAttributes() {
44
		$mockTagBuilder = $this->getMock('Tx_Fluid_Core_ViewHelper_TagBuilder', array('setTagName', 'addAttribute'));
45
		$mockTagBuilder->expects($this->once())->method('setTagName')->with('input');
46
		$mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'radio');
47
		$mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'foo');
48
		$mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', 'bar');
49

  
50
		$this->viewHelper->expects($this->any())->method('getName')->will($this->returnValue('foo'));
51
		$this->viewHelper->expects($this->any())->method('getValue')->will($this->returnValue('bar'));
52
		$this->viewHelper->injectTagBuilder($mockTagBuilder);
53

  
54
		$this->viewHelper->initialize();
55
		$this->viewHelper->render();
56
	}
57

  
58
	/**
59
	 * @test
60
	 * @author Bastian Waidelich <bastian@typo3.org>
61
	 */
62
	public function renderSetsCheckedAttributeIfSpecified() {
63
		$mockTagBuilder = $this->getMock('Tx_Fluid_Core_ViewHelper_TagBuilder', array('setTagName', 'addAttribute'));
64
		$mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'radio');
65
		$mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'foo');
66
		$mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', 'bar');
67
		$mockTagBuilder->expects($this->at(4))->method('addAttribute')->with('checked', 'checked');
68

  
69
		$this->viewHelper->expects($this->any())->method('getName')->will($this->returnValue('foo'));
70
		$this->viewHelper->expects($this->any())->method('getValue')->will($this->returnValue('bar'));
71
		$this->viewHelper->injectTagBuilder($mockTagBuilder);
72

  
73
		$this->viewHelper->initialize();
74
		$this->viewHelper->render(TRUE);
75
	}
76

  
77
	/**
78
	 * @test
79
	 * @author Bastian Waidelich <bastian@typo3.org>
80
	 */
81
	public function renderIgnoresBoundPropertyIfCheckedIsSet() {
82
		$mockTagBuilder = $this->getMock('Tx_Fluid_Core_ViewHelper_TagBuilder', array('setTagName', 'addAttribute'));
83
		$mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'radio');
84
		$mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'foo');
85
		$mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', 'bar');
86

  
87
		$this->viewHelper->expects($this->any())->method('getName')->will($this->returnValue('foo'));
88
		$this->viewHelper->expects($this->any())->method('getValue')->will($this->returnValue('bar'));
89
		$this->viewHelper->expects($this->never())->method('isObjectAccessorMode')->will($this->returnValue(TRUE));
90
		$this->viewHelper->expects($this->never())->method('getPropertyValue')->will($this->returnValue(TRUE));
91
		$this->viewHelper->injectTagBuilder($mockTagBuilder);
92

  
93
		$this->viewHelper->initialize();
94
		$this->viewHelper->render(TRUE);
95
		$this->viewHelper->render(FALSE);
96
	}
97

  
98
	/**
99
	 * @test
100
	 * @author Bastian Waidelich <bastian@typo3.org>
101
	 */
102
	public function renderCorrectlySetsCheckedAttributeIfCheckboxIsBoundToAPropertyOfTypeBoolean() {
103
		$mockTagBuilder = $this->getMock('Tx_Fluid_Core_ViewHelper_TagBuilder', array('setTagName', 'addAttribute'));
104
		$mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'radio');
105
		$mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'foo');
106
		$mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', 'bar');
107
		$mockTagBuilder->expects($this->at(4))->method('addAttribute')->with('checked', 'checked');
108

  
109
		$this->viewHelper->expects($this->any())->method('getName')->will($this->returnValue('foo'));
110
		$this->viewHelper->expects($this->any())->method('getValue')->will($this->returnValue('bar'));
111
		$this->viewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(TRUE));
112
		$this->viewHelper->expects($this->any())->method('getPropertyValue')->will($this->returnValue(TRUE));
113
		$this->viewHelper->injectTagBuilder($mockTagBuilder);
114

  
115
		$this->viewHelper->initialize();
116
		$this->viewHelper->render();
117
	}
118

  
119
	/**
120
	 * @test
121
	 * @author Bastian Waidelich <bastian@typo3.org>
122
	 */
123
	public function renderDoesNotAppendSquareBracketsToNameAttributeIfBoundToAPropertyOfTypeArray() {
124
		$mockTagBuilder = $this->getMock('Tx_Fluid_Core_ViewHelper_TagBuilder', array('setTagName', 'addAttribute'));
125
		$mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'radio');
126
		$mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'foo');
127
		$mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', 'bar');
128

  
129
		$this->viewHelper->expects($this->any())->method('getName')->will($this->returnValue('foo'));
130
		$this->viewHelper->expects($this->any())->method('getValue')->will($this->returnValue('bar'));
131
		$this->viewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(TRUE));
132
		$this->viewHelper->expects($this->any())->method('getPropertyValue')->will($this->returnValue(array()));
133
		$this->viewHelper->injectTagBuilder($mockTagBuilder);
134

  
135
		$this->viewHelper->initialize();
136
		$this->viewHelper->render();
137
	}
138

  
139
	/**
140
	 * @test
141
	 * @author Bastian Waidelich <bastian@typo3.org>
142
	 */
143
	public function renderCorrectlySetsCheckedAttributeIfCheckboxIsBoundToAPropertyOfTypeString() {
144
		$mockTagBuilder = $this->getMock('Tx_Fluid_Core_ViewHelper_TagBuilder', array('setTagName', 'addAttribute'));
145
		$mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('type', 'radio');
146
		$mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('name', 'foo');
147
		$mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('value', 'bar');
148
		$mockTagBuilder->expects($this->at(4))->method('addAttribute')->with('checked', 'checked');
149

  
150
		$this->viewHelper->expects($this->any())->method('getName')->will($this->returnValue('foo'));
151
		$this->viewHelper->expects($this->any())->method('getValue')->will($this->returnValue('bar'));
152
		$this->viewHelper->expects($this->any())->method('isObjectAccessorMode')->will($this->returnValue(TRUE));
153
		$this->viewHelper->expects($this->any())->method('getPropertyValue')->will($this->returnValue('bar'));
154
		$this->viewHelper->injectTagBuilder($mockTagBuilder);
155

  
156
		$this->viewHelper->initialize();
157
		$this->viewHelper->render();
158
	}
159

  
160
	/**
161
	 * @test
162
	 * @author Bastian Waidelich <bastian@typo3.org>
163
	 */
164
	public function renderCallsSetErrorClassAttribute() {
165
		$this->viewHelper->expects($this->once())->method('setErrorClassAttribute');
166
		$this->viewHelper->render();
167
	}
168
}
169

  
170
?>
0 171

  
(2-2/3)