Skip to content

Commit

Permalink
move checkbox template & test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
steefaan committed Jun 15, 2015
1 parent c4aaa07 commit efd5f9a
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/View/Helper/FormHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class FormHelper extends Helper
'inputContainer' => '<div class="form-group{{required}}">{{content}}{{help}}</div>',
'inputContainerError' => '<div class="form-group{{required}} has-error">{{content}}{{error}}{{help}}</div>',
'checkboxWrapper' => '<div class="checkbox"><label>{{input}}{{label}}</label></div>',
'multipleCheckboxWrapper' => '<div class="checkbox">{{label}}</div>',
'radioInlineFormGroup' => '{{label}}<div class="radio-inline-wrapper">{{input}}</div>',
'radioNestingLabel' => '<div class="radio">{{hidden}}<label{{attrs}}>{{input}}{{text}}</label></div>',
'staticControl' => '<p class="form-control-static">{{content}}</p>'
Expand Down Expand Up @@ -184,7 +185,9 @@ public function input($fieldName, array $options = [])
break;
case 'select':
if (isset($options['multiple']) && $options['multiple'] === 'checkbox') {
$this->templates(['checkboxWrapper' => '<div class="checkbox">{{label}}</div>']);
$this->templater()->add([
'checkboxWrapper' => $this->templater()->get('multipleCheckboxWrapper')
]);
$options['type'] = 'multicheckbox';
}
break;
Expand Down
129 changes: 125 additions & 4 deletions tests/TestCase/View/Helper/FormHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,14 +430,20 @@ public function testBasicRadioInput()
{
$this->Form->create($this->article);

$result = $this->Form->input('published', ['type' => 'radio', 'options' => ['Yes', 'No']]);
$result = $this->Form->input('published', [
'type' => 'radio',
'options' => ['Yes', 'No']
]);
$expected = [
['div' => ['class' => 'form-group']],
'input' => [
['label' => true],
'Published',
'/label',
['input' => [
'type' => 'hidden',
'name' => 'published',
'value' => '',
],
]],
['div' => ['class' => 'radio']],
['label' => ['for' => 'published-0']],
['input' => [
Expand All @@ -460,6 +466,7 @@ public function testBasicRadioInput()
'No',
'/label',
'/div',
'/div'
];
$this->assertHtml($expected, $result);
}
Expand All @@ -474,6 +481,67 @@ public function testInlineRadioInput()
'options' => ['Yes', 'No']
]);
$expected = [
['div' => ['class' => 'form-group']],
['label' => true],
'Published',
'/label',
['div' => ['class' => 'radio-inline-wrapper']],
['input' => [
'type' => 'hidden',
'name' => 'published',
'value' => ''
]],
['label' => [
'class' => 'radio-inline',
'for' => 'published-0'
]],
['input' => [
'type' => 'radio',
'name' => 'published',
'value' => 0,
'id' => 'published-0'
]],
'Yes',
'/label',
['label' => [
'class' => 'radio-inline',
'for' => 'published-1'
]],
['input' => [
'type' => 'radio',
'name' => 'published',
'value' => 1,
'id' => 'published-1'
]],
'No',
'/label',
'/div',
'/div'
];
$this->assertHtml($expected, $result);
}

public function testRadioInputHorizontal()
{
$this->Form->create($this->article, [
'align' => [
'sm' => [
'left' => 5,
'middle' => 7
]
]
]);

$result = $this->Form->input('published', [
'type' => 'radio',
'options' => ['Yes', 'No']
]);
$expected = [
['div' => ['class' => 'form-group']],
['label' => ['class' => 'control-label col-sm-5']],
'Published',
'/label',
['div' => ['class' => 'col-sm-7']],
'input' => [
'type' => 'hidden',
'name' => 'published',
Expand All @@ -500,14 +568,67 @@ public function testInlineRadioInput()
]],
'No',
'/label',
'/div',
'/div',
'/div'
];
$this->assertHtml($expected, $result);
}

public function testInlineRadioInputHorizontal()
{
$this->Form->create($this->article, [
'align' => [
'sm' => [
'left' => 5,
'middle' => 7
]
]
]);

$result = $this->Form->input('published', [
'label' => ['class' => 'radio-inline'],
'inline' => true,
'type' => 'radio',
'options' => ['Yes', 'No']
]);
$expected = [
['div' => ['class' => 'form-group']],
['label' => ['class' => 'control-label col-sm-5']],
'Published',
'/label',
['div' => ['class' => 'col-sm-7']],
'input' => [
'type' => 'hidden',
'name' => 'published',
'value' => '',
],
['label' => [
'class' => 'radio-inline',
'for' => 'published-0'
]],
['input' => [
'type' => 'radio',
'name' => 'published',
'value' => 0,
'id' => 'published-0',
]],
'Yes',
'/label',
['label' => [
'class' => 'radio-inline',
'for' => 'published-1'
]],
['input' => [
'type' => 'radio',
'name' => 'published',
'value' => 1,
'id' => 'published-1',
]],
'No',
'/label',
'/div',
'/div'
];
$this->assertHtml($expected, $result);
}

Expand Down

0 comments on commit efd5f9a

Please sign in to comment.