/**
  * Test render templateVars
  *
  * @return void
  */
 public function testRenderTemplateVars()
 {
     $templates = ['checkbox' => '<input type="checkbox" name="{{name}}" value="{{value}}" data-var="{{inputVar}}" {{attrs}}>', 'label' => '<label{{attrs}}>{{text}} {{inputVar}}</label>', 'checkboxWrapper' => '<div class="checkbox" data-wrap="{{wrapVar}}">{{input}}{{label}}</div>'];
     $this->templates->add($templates);
     $label = new LabelWidget($this->templates);
     $input = new MultiCheckboxWidget($this->templates, $label);
     $data = ['name' => 'Tags[id]', 'options' => [['value' => '1', 'text' => 'CakePHP', 'templateVars' => ['inputVar' => 'i-var']], '1x' => 'Development'], 'templateVars' => ['inputVar' => 'default', 'wrapVar' => 'val']];
     $result = $input->render($data, $this->context);
     $expected = [['div' => ['class' => 'checkbox', 'data-wrap' => 'val']], ['input' => ['type' => 'checkbox', 'name' => 'Tags[id][]', 'value' => 1, 'id' => 'tags-id-1', 'data-var' => 'i-var']], ['label' => ['for' => 'tags-id-1']], 'CakePHP i-var', '/label', '/div', ['div' => ['class' => 'checkbox', 'data-wrap' => 'val']], ['input' => ['type' => 'checkbox', 'name' => 'Tags[id][]', 'value' => '1x', 'id' => 'tags-id-1x', 'data-var' => 'default']], ['label' => ['for' => 'tags-id-1x']], 'Development default', '/label', '/div'];
     $this->assertHtml($expected, $result);
 }
 /**
  * Test render disabled checkboxes.
  *
  * @return void
  */
 public function testRenderDisabled()
 {
     $label = new LabelWidget($this->templates);
     $input = new MultiCheckboxWidget($this->templates, $label);
     $data = ['name' => 'Tags[id]', 'options' => [1 => 'CakePHP', '1x' => 'Development'], 'disabled' => true];
     $result = $input->render($data, $this->context);
     $expected = [['div' => ['class' => 'checkbox']], ['input' => ['type' => 'checkbox', 'name' => 'Tags[id][]', 'value' => 1, 'id' => 'tags-id-1', 'disabled' => 'disabled']], ['label' => ['for' => 'tags-id-1']], 'CakePHP', '/label', '/div', ['div' => ['class' => 'checkbox']], ['input' => ['type' => 'checkbox', 'name' => 'Tags[id][]', 'value' => '1x', 'id' => 'tags-id-1x', 'disabled' => 'disabled']], ['label' => ['for' => 'tags-id-1x']], 'Development', '/label', '/div'];
     $this->assertHtml($expected, $result);
     $data['disabled'] = 'a string';
     $result = $input->render($data, $this->context);
     $this->assertHtml($expected, $result);
     $data['disabled'] = ['1', '1x'];
     $this->assertHtml($expected, $result);
     $data = ['name' => 'Tags[id]', 'options' => [1 => 'CakePHP', '1x' => 'Development'], 'disabled' => [1]];
     $result = $input->render($data, $this->context);
     $expected = [['div' => ['class' => 'checkbox']], ['input' => ['type' => 'checkbox', 'name' => 'Tags[id][]', 'value' => 1, 'id' => 'tags-id-1', 'disabled' => 'disabled']], ['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->assertHtml($expected, $result);
 }
Пример #3
0
 /**
  * Test render with partial groupings.
  *
  * @return void
  */
 public function testRenderPartialGrouped()
 {
     $label = new LabelWidget($this->templates);
     $input = new MultiCheckboxWidget($this->templates, $label);
     $data = ['name' => 'Tags[id]', 'options' => [1 => 'PHP', 'Group 1' => [2 => 'CakePHP'], 3 => 'Development']];
     $result = $input->render($data, $this->context);
     $expected = [['div' => ['class' => 'checkbox']], ['input' => ['type' => 'checkbox', 'name' => 'Tags[id][]', 'value' => 1, 'id' => 'tags-id-1']], ['label' => ['for' => 'tags-id-1']], 'PHP', '/label', '/div', '<fieldset', '<legend', 'Group 1', '/legend', ['div' => ['class' => 'checkbox']], ['input' => ['type' => 'checkbox', 'name' => 'Tags[id][]', 'value' => 2, 'id' => 'tags-id-2']], ['label' => ['for' => 'tags-id-2']], 'CakePHP', '/label', '/div', '/fieldset', ['div' => ['class' => 'checkbox']], ['input' => ['type' => 'checkbox', 'name' => 'Tags[id][]', 'value' => 3, 'id' => 'tags-id-3']], ['label' => ['for' => 'tags-id-3']], 'Development', '/label', '/div'];
     $this->assertHtml($expected, $result);
 }