Skip to content
Permalink
Browse files

use actual value in selected/disabled check

  • Loading branch information...
Tietew committed Mar 24, 2015
1 parent 09eb238 commit b90cf78401880c5868b569b623dc8ba65dda7091
Showing with 63 additions and 0 deletions.
  1. +1 −0 src/View/Widget/SelectBoxWidget.php
  2. +62 −0 tests/TestCase/View/Widget/SelectBoxWidgetTest.php
@@ -241,6 +241,7 @@ protected function _renderOptions($options, $disabled, $selected, $escape)
];
if (is_array($val) && isset($optAttrs['text'], $optAttrs['value'])) {
$optAttrs = $val;
$key = $optAttrs['value'];
}
if ($this->_isSelected($key, $selected)) {
$optAttrs['selected'] = true;
@@ -210,6 +210,37 @@ public function testRenderSelected()
$this->assertHtml($expected, $result);
}
/**
* test complex option rendering with a selected value
*
* @return void
*/
public function testRenderComplexSelected()
{
$select = new SelectBoxWidget($this->templates);
$data = [
'id' => 'BirdName',
'name' => 'Birds[name]',
'val' => 'a',
'options' => [
['value' => 'a', 'text' => 'Albatross'],
['value' => 'b', 'text' => 'Budgie', 'data-foo' => 'bar'],
]
];
$result = $select->render($data, $this->context);
$expected = [
'select' => ['name' => 'Birds[name]', 'id' => 'BirdName'],
['option' => ['value' => 'a', 'selected' => 'selected']],
'Albatross',
'/option',
['option' => ['value' => 'b', 'data-foo' => 'bar']],
'Budgie',
'/option',
'/select'
];
$this->assertHtml($expected, $result);
}
/**
* test rendering a multi select
*
@@ -574,6 +605,37 @@ public function testRenderDisabledMultiple()
$this->assertHtml($expected, $result);
}
/**
* test complex option rendering with a disabled element
*
* @return void
*/
public function testRenderComplexDisabled()
{
$select = new SelectBoxWidget($this->templates);
$data = [
'disabled' => ['b'],
'id' => 'BirdName',
'name' => 'Birds[name]',
'options' => [
['value' => 'a', 'text' => 'Albatross'],
['value' => 'b', 'text' => 'Budgie', 'data-foo' => 'bar'],
]
];
$result = $select->render($data, $this->context);
$expected = [
'select' => ['name' => 'Birds[name]', 'id' => 'BirdName'],
['option' => ['value' => 'a']],
'Albatross',
'/option',
['option' => ['value' => 'b', 'data-foo' => 'bar', 'disabled' => 'disabled']],
'Budgie',
'/option',
'/select'
];
$this->assertHtml($expected, $result);
}
/**
* test rendering with an empty value
*

0 comments on commit b90cf78

Please sign in to comment.
You can’t perform that action at this time.