Skip to content
Permalink
Browse files

MultiCheckboxWidget should use checkboxWrapper, not radioWrapper.

  • Loading branch information...
chinpei215 committed Jun 28, 2018
1 parent c0d6f8f commit 0dc1d7a799b272ae4df016bb8764a5470343b9d5
Showing with 72 additions and 1 deletion.
  1. +1 −1 src/View/Widget/MultiCheckboxWidget.php
  2. +71 −0 tests/TestCase/View/Widget/MultiCheckboxWidgetTest.php
@@ -191,7 +191,7 @@ protected function _renderInput($checkbox, $context)
)
]);
if ($checkbox['label'] === false && strpos($this->_templates->get('radioWrapper'), '{{input}}') === false) {
if ($checkbox['label'] === false && strpos($this->_templates->get('checkboxWrapper'), '{{input}}') === false) {
$label = $input;
} else {
$labelAttrs = [
@@ -369,6 +369,77 @@ public function testRenderTemplateVars()
$this->assertHtml($expected, $result);
}
/**
* Test label = false with checkboxWrapper option.
*
* @return void
*/
public function testNoLabelWithCheckboxWrapperOption()
{
$data = [
'label' => false,
'name' => 'test',
'options' => [
1 => 'A',
2 => 'B',
],
];
$label = new LabelWidget($this->templates);
$input = new MultiCheckboxWidget($this->templates, $label);
$result = $input->render($data, $this->context);
$expected = [
['div' => ['class' => 'checkbox']],
['input' => [
'type' => 'checkbox',
'name' => 'test[]',
'value' => 1,
'id' => 'test-1',
]],
['label' => ['for' => 'test-1']],
'A',
'/label',
'/div',
['div' => ['class' => 'checkbox']],
['input' => [
'type' => 'checkbox',
'name' => 'test[]',
'value' => '2',
'id' => 'test-2',
]],
['label' => ['for' => 'test-2']],
'B',
'/label',
'/div',
];
$this->assertHtml($expected, $result);
$templates = [
'checkboxWrapper' => '<div class="checkbox">{{label}}</div>',
];
$this->templates->add($templates);
$result = $input->render($data, $this->context);
$expected = [
['div' => ['class' => 'checkbox']],
['input' => [
'type' => 'checkbox',
'name' => 'test[]',
'value' => 1,
'id' => 'test-1',
]],
'/div',
['div' => ['class' => 'checkbox']],
['input' => [
'type' => 'checkbox',
'name' => 'test[]',
'value' => '2',
'id' => 'test-2',
]],
'/div',
];
$this->assertHtml($expected, $result);
}
/**
* Test render with groupings.
*

0 comments on commit 0dc1d7a

Please sign in to comment.
You can’t perform that action at this time.