Permalink
Browse files

Add support for checking checkboxes.

  • Loading branch information...
1 parent 72b9481 commit 770bc7c471ab367168bb29462c89cc2ff1ee59f6 @markstory markstory committed Jan 15, 2014
Showing with 45 additions and 2 deletions.
  1. +1 −1 src/View/Input/MultiCheckbox.php
  2. +44 −1 tests/TestCase/View/Input/MultiCheckboxTest.php
@@ -56,7 +56,7 @@ public function render($data) {
$checkbox['escape'] = $data['escape'];
if ($this->_isSelected($key, $data['val'])) {
- $checkbox['selected'] = true;
+ $checkbox['checked'] = true;
}
if ($this->_isDisabled($key, $data['disabled'])) {
$checkbox['disabled'] = true;
@@ -100,7 +100,50 @@ public function testRenderComplex() {
* @return void
*/
public function testRenderSelected() {
- $this->markTestIncomplete();
+ $input = new MultiCheckbox($this->templates);
+ $data = [
+ 'name' => 'Tags[id]',
+ 'options' => [
+ 1 => 'CakePHP',
+ '1x' => 'Development',
+ ],
+ 'val' => [1]
+ ];
+ $result = $input->render($data);
+ $expected = [
+ ['div' => ['class' => 'checkbox']],
+ ['input' => [
+ 'type' => 'checkbox',
+ 'name' => 'Tags[id][]',
+ 'value' => 1,
+ 'id' => 'tags-id-1',
+ 'checked' => 'checked'
+ ]],
+ ['label' => ['for' => 'tags-id-1']],
+ 'CakePHP',
+ '/label',
+ '/div',
+ ['div' => ['class' => 'checkbox']],
+ ['input' => [
+ 'type' => 'checkbox',
+ 'name' => 'Tags[id][]',
+ 'value' => '1x',
+ 'id' => 'tags-id-1x',
+ ]],
+ ['label' => ['for' => 'tags-id-1x']],
+ 'Development',
+ '/label',
+ '/div',
+ ];
+ $this->assertTags($result, $expected);
+
+ $data['val'] = 1;
+ $result = $input->render($data);
+ $this->assertTags($result, $expected);
+
+ $data['val'] = '1';
+ $result = $input->render($data);
+ $this->assertTags($result, $expected);
}
/**

0 comments on commit 770bc7c

Please sign in to comment.