Making optiongroup elements follow the escape parameter.

Tests added.
Fixes #1191
This commit is contained in:
mark_story 2010-10-13 21:59:53 -04:00
parent 3f2109f3c3
commit 6529e0e2b4
2 changed files with 42 additions and 0 deletions

View file

@ -2002,6 +2002,7 @@ class FormHelper extends AppHelper {
)); ));
if (!empty($name)) { if (!empty($name)) {
$name = $attributes['escape'] ? h($name) : $name;
if ($attributes['style'] === 'checkbox') { if ($attributes['style'] === 'checkbox') {
$select[] = sprintf($this->Html->tags['fieldsetstart'], $name); $select[] = sprintf($this->Html->tags['fieldsetstart'], $name);
} else { } else {

View file

@ -3115,6 +3115,47 @@ class FormHelperTest extends CakeTestCase {
$this->assertTags($result, $expected); $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 * Tests that FormHelper::select() allows null to be passed in the $attributes parameter
* *