Skip to content
Permalink
Browse files

Fixed SelectBox raising exception with null options

  • Loading branch information...
alaxos committed Sep 18, 2014
1 parent d1aebab commit 032b26c32282a2bc2b99e3048858e1a1a053fba1
Showing with 38 additions and 1 deletion.
  1. +1 −1 src/View/Widget/SelectBox.php
  2. +37 −0 tests/TestCase/View/Widget/SelectBoxTest.php
@@ -164,7 +164,7 @@ protected function _renderContent($data) {
if (!empty($data['empty'])) {
$value = $data['empty'] === true ? '' : $data['empty'];
$options = ['' => $value] + $options;
$options = ['' => $value] + (array)$options;
}
if (empty($options)) {
return [];
@@ -661,4 +661,41 @@ public function testRenderEscapingOption() {
$this->assertHtml($expected, $result);
}
/**
* test render with null options
*
* @return void
*/
public function testRenderNullOptions() {
$select = new SelectBox($this->templates);
$data = [
'id' => 'BirdName',
'name' => 'Birds[name]',
'options' => null
];
$result = $select->render($data, $this->context);
$expected = [
'select' => ['name' => 'Birds[name]', 'id' => 'BirdName'],
'/select'
];
$this->assertHtml($expected, $result);
$data['empty'] = true;
$result = $select->render($data, $this->context);
$expected = [
'select' => ['name' => 'Birds[name]', 'id' => 'BirdName'],
['option' => ['value' => '']], '/option',
'/select'
];
$this->assertHtml($expected, $result);
$data['empty'] = 'empty';
$result = $select->render($data, $this->context);
$expected = [
'select' => ['name' => 'Birds[name]', 'id' => 'BirdName'],
['option' => ['value' => '']], 'empty', '/option',
'/select'
];
$this->assertHtml($expected, $result);
}
}

0 comments on commit 032b26c

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