Skip to content

Commit

Permalink
Add tests for escaping name + value.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Jan 15, 2014
1 parent 642db5e commit d8944c6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/View/Input/MultiCheckbox.php
Expand Up @@ -32,6 +32,16 @@ public function __construct($templates) {
/**
* Render multi-checkbox widget.
*
* Data supports the following options.
*
* - `name` The name attribute of the inputs to create.
* `[]` will be appended to the name.
* - `options` An array of options to create checkboxes out of.
* - `val` Either a string/integer or array of values that should be
* checked.
* - `disabled` Either a boolean or an array of checkboxes to disable.
* - `escape` Set to false to disable HTML escaping.
*
* @param array $data
* @return string
*/
Expand Down Expand Up @@ -78,7 +88,7 @@ public function render($data) {
protected function _renderInput($checkbox) {
$input = $this->_templates->format('checkbox', [
'name' => $checkbox['name'] . '[]',
'value' => $checkbox['value'],
'value' => $checkbox['escape'] ? h($checkbox['value']) : $checkbox['value'],
'attrs' => $this->_templates->formatAttributes(
$checkbox,
['name', 'value', 'text']
Expand Down
23 changes: 22 additions & 1 deletion tests/TestCase/View/Input/MultiCheckboxTest.php
Expand Up @@ -82,7 +82,28 @@ public function testRenderSimple() {
* @return void
*/
public function testRenderEscaping() {
$this->markTestIncomplete();
$input = new MultiCheckbox($this->templates);
$data = [
'name' => 'Tags[id]',
'options' => [
'>' => '>>',
]
];
$result = $input->render($data);
$expected = [
['div' => ['class' => 'checkbox']],
['input' => [
'type' => 'checkbox',
'name' => 'Tags[id][]',
'value' => '>',
'id' => 'tags-id',
]],
['label' => ['for' => 'tags-id']],
'>>',
'/label',
'/div',
];
$this->assertTags($result, $expected);
}

/**
Expand Down

0 comments on commit d8944c6

Please sign in to comment.