Skip to content

Commit

Permalink
Making optiongroup elements follow the escape parameter.
Browse files Browse the repository at this point in the history
Tests added.
Fixes #1191
  • Loading branch information
markstory committed Oct 14, 2010
1 parent 3f2109f commit 6529e0e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions cake/libs/view/helpers/form.php
Expand Up @@ -2002,6 +2002,7 @@ function __selectOptions($elements = array(), $selected = null, $parents = array
));

if (!empty($name)) {
$name = $attributes['escape'] ? h($name) : $name;
if ($attributes['style'] === 'checkbox') {
$select[] = sprintf($this->Html->tags['fieldsetstart'], $name);
} else {
Expand Down
41 changes: 41 additions & 0 deletions cake/tests/cases/libs/view/helpers/form.test.php
Expand Up @@ -3115,6 +3115,47 @@ function testSelect() {
$this->assertTags($result, $expected);
}

/**
* test that select() with optiongroups listens to the escape param.
*
* @return void
*/
function testSelectOptionGroupEscaping() {
$options = array(
'>< Key' => array(
1 => 'One',
2 => 'Two'
)
);
$result = $this->Form->select('Model.field', $options, null, array('empty' => false));
$expected = array(
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
'optgroup' => array('label' => '&gt;&lt; Key'),
array('option' => array('value' => '1')), 'One', '/option',
array('option' => array('value' => '2')), 'Two', '/option',
'/optgroup',
'/select'
);
$this->assertTags($result, $expected);

$options = array(
'>< Key' => array(
1 => 'One',
2 => 'Two'
)
);
$result = $this->Form->select('Model.field', $options, null, array('empty' => false, 'escape' => false));
$expected = array(
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
'optgroup' => array('label' => '>< Key'),
array('option' => array('value' => '1')), 'One', '/option',
array('option' => array('value' => '2')), 'Two', '/option',
'/optgroup',
'/select'
);
$this->assertTags($result, $expected);
}

/**
* Tests that FormHelper::select() allows null to be passed in the $attributes parameter
*
Expand Down

0 comments on commit 6529e0e

Please sign in to comment.