Feature #3661 » 3661.patch

Bastian Waidelich, 2009-07-31 12:18

View differences:

Classes/ViewHelpers/Form/CheckboxViewHelper.php (revision 0)
1
<?php
2
declare(ENCODING = 'utf-8');
3
namespace F3\Fluid\ViewHelpers\Form;
4

  
5
/*                                                                        *
6
 * This script belongs to the FLOW3 package "Fluid".                      *
7
 *                                                                        *
8
 * It is free software; you can redistribute it and/or modify it under    *
9
 * the terms of the GNU Lesser General Public License as published by the *
10
 * Free Software Foundation, either version 3 of the License, or (at your *
11
 * option) any later version.                                             *
12
 *                                                                        *
13
 * This script is distributed in the hope that it will be useful, but     *
14
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
15
 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser       *
16
 * General Public License for more details.                               *
17
 *                                                                        *
18
 * You should have received a copy of the GNU Lesser General Public       *
19
 * License along with the script.                                         *
20
 * If not, see http://www.gnu.org/licenses/lgpl.html                      *
21
 *                                                                        *
22
 * The TYPO3 project - inspiring people to share!                         *
23
 *                                                                        */
24

  
25
/**
26
 * View Helper which creates a simple checkbox (<input type="checkbox">).
27
 *
28
 * = Examples =
29
 *
30
 * <code title="Example">
31
 * <f:form.checkbox name="myCheckBox" value="someValue" />
32
 * </code>
33
 *
34
 * Output:
35
 * <input type="checkbox" name="myCheckBox" value="someValue" />
36
 *
37
 * <code title="Preselect">
38
 * <f:form.checkbox name="myCheckBox" value="someValue" checked="{object.value} == 5" />
39
 * </code>
40
 *
41
 * Output:
42
 * <input type="checkbox" name="myCheckBox" value="someValue" checked="checked" />
43
 * (depending on $object)
44
 *
45
 * <code title="Bind to object property">
46
 * <f:form.checkbox property="interests" value="TYPO3" />
47
 * </code>
48
 *
49
 * Output:
50
 * <input type="checkbox" name="user[interests][]" value="TYPO3" checked="checked" />
51
 * (depending on property "interests")
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 CheckboxViewHelper extends \F3\Fluid\ViewHelpers\Form\AbstractFormViewHelper {
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 checkboxes', 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', 'checkbox');
90

  
91
		$nameAttribute = $this->getName();
92
		$valueAttribute = $this->getValue();
93
		if ($checked === NULL && $this->isObjectAccessorMode()) {
94
			$propertyValue = $this->getPropertyValue();
95
			if (is_bool($propertyValue)) {
96
				$checked = $propertyValue === (boolean)$valueAttribute;
97
			} elseif (is_array($propertyValue)) {
98
				$checked = in_array($valueAttribute, $propertyValue);
99
				$nameAttribute .= '[]';
100
			} else {
101
				throw new \F3\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);
102
			}
103
		}
104

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

  
111
		$this->setErrorClassAttribute();
112

  
113
		return $this->tag->render();
114
	}
115
}
116

  
117
?>
0 118

  
Classes/ViewHelpers/Form/RadioViewHelper.php (revision 0)
1
<?php
2
declare(ENCODING = 'utf-8');
3
namespace F3\Fluid\ViewHelpers\Form;
4

  
5
/*                                                                        *
6
 * This script belongs to the FLOW3 package "Fluid".                      *
7
 *                                                                        *
8
 * It is free software; you can redistribute it and/or modify it under    *
9
 * the terms of the GNU Lesser General Public License as published by the *
10
 * Free Software Foundation, either version 3 of the License, or (at your *
11
 * option) any later version.                                             *
12
 *                                                                        *
13
 * This script is distributed in the hope that it will be useful, but     *
14
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
15
 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser       *
16
 * General Public License for more details.                               *
17
 *                                                                        *
18
 * You should have received a copy of the GNU Lesser General Public       *
19
 * License along with the script.                                         *
20
 * If not, see http://www.gnu.org/licenses/lgpl.html                      *
21
 *                                                                        *
22
 * The TYPO3 project - inspiring people to share!                         *
23
 *                                                                        */
24

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

  
61
	/**
62
	 * @var string
63
	 */
64
	protected $tagName = 'input';
65

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

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

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

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

  
107
		$this->setErrorClassAttribute();
108

  
109
		return $this->tag->render();
110
	}
111
}
112

  
113
?>
0 114

  
Tests/ViewHelpers/Form/CheckboxViewHelperTest.php (revision 0)
1
<?php
2
declare(ENCODING = 'utf-8');
3
namespace F3\Fluid\ViewHelpers\Form;
4

  
5
/*                                                                        *
6
 * This script is part of the TYPO3 project - inspiring people to share!  *
7
 *                                                                        *
8
 * TYPO3 is free software; you can redistribute it and/or modify it under *
9
 * the terms of the GNU General Public License version 2 as published by  *
10
 * the Free Software Foundation.                                          *
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 General      *
15
 * Public License for more details.                                       *
16
 *                                                                        */
17

  
18
require_once(__DIR__ . '/../ViewHelperBaseTestcase.php');
19

  
20
/**
21
 * Test for the "Checkbox" Form view helper
22
 *
23
 * @version $Id$
24
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
25
 */
26
class CheckboxViewHelperTest extends \F3\Fluid\ViewHelpers\ViewHelperBaseTestcase {
27

  
28
	/**
29
	 * var \F3\Fluid\ViewHelpers\Form\CheckboxViewHelper
30
	 */
31
	protected $viewHelper;
32

  
33
	public function setUp() {
34
		parent::setUp();
35
		$this->viewHelper = $this->getMock($this->buildAccessibleProxy('F3\Fluid\ViewHelpers\Form\CheckboxViewHelper'), array('setErrorClassAttribute', 'getName', 'getValue', 'isObjectAccessorMode', 'getPropertyValue'));
36
		$this->injectDependenciesIntoViewHelper($this->viewHelper);
37
		$this->viewHelper->initializeArguments();
38
	}
39

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  
161
	/**
162
	 * @test
163
	 * @expectedException \F3\Fluid\Core\ViewHelper\Exception
164
	 * @author Bastian Waidelich <bastian@typo3.org>
165
	 */
166
	public function bindingObjectsToACheckboxThatAreNotOfTypeBooleanOrArrayThrowsException() {
167
		$mockTagBuilder = $this->getMock('F3\Fluid\Core\ViewHelper\TagBuilder', array('setTagName', 'addAttribute'));
168

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

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

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

  
187
?>
0 188

  
Tests/ViewHelpers/Form/RadioViewHelperTest.php (revision 0)
1
<?php
2
declare(ENCODING = 'utf-8');
3
namespace F3\Fluid\ViewHelpers\Form;
4

  
5
/*                                                                        *
6
 * This script is part of the TYPO3 project - inspiring people to share!  *
7
 *                                                                        *
8
 * TYPO3 is free software; you can redistribute it and/or modify it under *
9
 * the terms of the GNU General Public License version 2 as published by  *
10
 * the Free Software Foundation.                                          *
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 General      *
15
 * Public License for more details.                                       *
16
 *                                                                        */
17

  
18
require_once(__DIR__ . '/../ViewHelperBaseTestcase.php');
19

  
20
/**
21
 * Test for the "Radio" Form view helper
22
 *
23
 * @version $Id$
24
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
25
 */
26
class RadioViewHelperTest extends \F3\Fluid\ViewHelpers\ViewHelperBaseTestcase {
27

  
28
	/**
29
	 * var \F3\Fluid\ViewHelpers\Form\RadioViewHelper
30
	 */
31
	protected $viewHelper;
32

  
33
	public function setUp() {
34
		parent::setUp();
35
		$this->viewHelper = $this->getMock($this->buildAccessibleProxy('F3\Fluid\ViewHelpers\Form\RadioViewHelper'), array('setErrorClassAttribute', 'getName', 'getValue', 'isObjectAccessorMode', 'getPropertyValue'));
36
		$this->injectDependenciesIntoViewHelper($this->viewHelper);
37
		$this->viewHelper->initializeArguments();
38
	}
39

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  
171
?>
0 172

  
(1-1/3)