Permalink
Browse files

Making input() tests pass when rendering checkboxes

  • Loading branch information...
1 parent 104cef5 commit 82ec578ad0e734cee98a74739313b703a0ccfcea @lorenzo lorenzo committed Feb 23, 2014
Showing with 14 additions and 13 deletions.
  1. +4 −2 src/View/Helper/FormHelper.php
  2. +10 −11 tests/TestCase/View/Helper/FormHelperTest.php
@@ -165,6 +165,7 @@ class FormHelper extends Helper {
'radioContainer' => '{{input}}{{label}}',
'textarea' => '<textarea name="{{name}}"{{attrs}}>{{value}}</textarea>',
'formGroup' => '{{label}}{{input}}',
+ 'checkboxFormGroup' => '{{input}}{{label}}',
'groupContainer' => '<div class="input {{type}}{{required}}">{{content}}</div>',
'groupContainerError' => '<div class="input {{type}}{{required}} error">{{content}}{{error}}</div>'
];
@@ -881,8 +882,9 @@ public function input($fieldName, $options = array()) {
unset($options['error']);
}
+ $groupTemplate = $options['type'] === 'checkbox' ? 'checkboxFormGroup' : 'formGroup';
$input = $this->{$options['type']}($fieldName, $options);
- $result = $this->formatTemplate('formGroup', compact('input', 'label'));
+ $result = $this->formatTemplate($groupTemplate, compact('input', 'label'));
if ($options['type'] !== 'hidden') {
$result = $this->formatTemplate($template, [
@@ -1167,7 +1169,7 @@ public function checkbox($fieldName, $options = []) {
}
$output = $this->hidden($fieldName, $hiddenOptions);
}
- unset($options['hiddenField']);
+ unset($options['hiddenField'], $options['type']);
return $output . $this->widget('checkbox', $options);
}
@@ -2683,30 +2683,29 @@ public function testInputZero() {
* @return void
*/
public function testInputCheckbox() {
- $this->markTestIncomplete('Need to revisit once models work again.');
$result = $this->Form->input('User.active', array('label' => false, 'checked' => true));
$expected = array(
'div' => array('class' => 'input checkbox'),
- 'input' => array('type' => 'hidden', 'name' => 'User[active]', 'value' => '0', 'id' => 'UserActive_'),
- array('input' => array('type' => 'checkbox', 'name' => 'User[active]', 'value' => '1', 'id' => 'UserActive', 'checked' => 'checked')),
+ 'input' => array('type' => 'hidden', 'name' => 'User[active]', 'value' => '0'),
+ array('input' => array('type' => 'checkbox', 'name' => 'User[active]', 'value' => '1', 'id' => 'user-active', 'checked' => 'checked')),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('User.active', array('label' => false, 'checked' => 1));
$expected = array(
'div' => array('class' => 'input checkbox'),
- 'input' => array('type' => 'hidden', 'name' => 'User[active]', 'value' => '0', 'id' => 'UserActive_'),
- array('input' => array('type' => 'checkbox', 'name' => 'User[active]', 'value' => '1', 'id' => 'UserActive', 'checked' => 'checked')),
+ 'input' => array('type' => 'hidden', 'name' => 'User[active]', 'value' => '0'),
+ array('input' => array('type' => 'checkbox', 'name' => 'User[active]', 'value' => '1', 'id' => 'user-active', 'checked' => 'checked')),
'/div'
);
$this->assertTags($result, $expected);
$result = $this->Form->input('User.active', array('label' => false, 'checked' => '1'));
$expected = array(
'div' => array('class' => 'input checkbox'),
- 'input' => array('type' => 'hidden', 'name' => 'User[active]', 'value' => '0', 'id' => 'UserActive_'),
- array('input' => array('type' => 'checkbox', 'name' => 'User[active]', 'value' => '1', 'id' => 'UserActive', 'checked' => 'checked')),
+ 'input' => array('type' => 'hidden', 'name' => 'User[active]', 'value' => '0'),
+ array('input' => array('type' => 'checkbox', 'name' => 'User[active]', 'value' => '1', 'id' => 'user-active', 'checked' => 'checked')),
'/div'
);
$this->assertTags($result, $expected);
@@ -2718,15 +2717,15 @@ public function testInputCheckbox() {
));
$expected = array(
'div' => array('class' => 'input checkbox'),
- 'input' => array('type' => 'hidden', 'name' => 'data[User][disabled]', 'value' => '0', 'id' => 'UserDisabled_'),
+ 'input' => array('type' => 'hidden', 'name' => 'User[disabled]', 'value' => '0'),
array('input' => array(
'type' => 'checkbox',
- 'name' => 'data[User][disabled]',
+ 'name' => 'User[disabled]',
'value' => '1',
- 'id' => 'UserDisabled',
+ 'id' => 'user-disabled',
'data-foo' => 'disabled'
)),
- 'label' => array('for' => 'UserDisabled'),
+ 'label' => array('for' => 'user-disabled'),
'Disabled',
'/label',
'/div'

0 comments on commit 82ec578

Please sign in to comment.