mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Stringify values to avoid trap of in_array() type juggling
This commit is contained in:
parent
beff1176b0
commit
3978f87c58
2 changed files with 55 additions and 1 deletions
|
@ -4979,6 +4979,60 @@ class FormHelperTest extends CakeTestCase {
|
|||
$this->assertTags($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that select() with numeric label of optiongroup.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSelectOptionGroupWithNumericLabel() {
|
||||
$options = array(
|
||||
1 => array(
|
||||
1 => '1Foo',
|
||||
2 => '2Bar',
|
||||
3 => '3Baz',
|
||||
4 => '1',
|
||||
5 => '2',
|
||||
6 => '3',
|
||||
7 => 1,
|
||||
8 => 2,
|
||||
9 => 3,
|
||||
),
|
||||
2 => array(
|
||||
11 => '1Foo',
|
||||
12 => '2Bar',
|
||||
13 => '3Baz',
|
||||
14 => '1',
|
||||
15 => '2',
|
||||
16 => '3',
|
||||
17 => 1,
|
||||
18 => 2,
|
||||
19 => 3,
|
||||
),
|
||||
);
|
||||
$result = $this->Form->select('Model.field', $options, array('empty' => false));
|
||||
$expected = array(
|
||||
'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
|
||||
array('optgroup' => array('label' => '1')),
|
||||
array('option' => array('value' => '1')), '1Foo', '/option',
|
||||
array('option' => array('value' => '2')), '2Bar', '/option',
|
||||
array('option' => array('value' => '3')), '3Baz', '/option',
|
||||
array('option' => array('value' => '6')), '3', '/option',
|
||||
array('option' => array('value' => '9')), '3', '/option',
|
||||
'/optgroup',
|
||||
array('optgroup' => array('label' => '2')),
|
||||
array('option' => array('value' => '11')), '1Foo', '/option',
|
||||
array('option' => array('value' => '12')), '2Bar', '/option',
|
||||
array('option' => array('value' => '13')), '3Baz', '/option',
|
||||
array('option' => array('value' => '14')), '1', '/option',
|
||||
array('option' => array('value' => '16')), '3', '/option',
|
||||
array('option' => array('value' => '17')), '1', '/option',
|
||||
array('option' => array('value' => '19')), '3', '/option',
|
||||
'/optgroup',
|
||||
'/select'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that select() with optiongroups listens to the escape param.
|
||||
*
|
||||
|
|
|
@ -2832,7 +2832,7 @@ class FormHelper extends AppHelper {
|
|||
} else {
|
||||
$select[] = $this->Html->useTag('optiongroupend');
|
||||
}
|
||||
$parents[] = $name;
|
||||
$parents[] = (string)$name;
|
||||
}
|
||||
$select = array_merge($select, $this->_selectOptions(
|
||||
$title, $parents, $showParents, $attributes
|
||||
|
|
Loading…
Reference in a new issue