Skip to content

Commit

Permalink
Add a test for using an Collection for options.
Browse files Browse the repository at this point in the history
Traversable/Collection instances should work for options.
  • Loading branch information
markstory committed Jan 11, 2014
1 parent 3a14f83 commit aa30d4b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/View/Input/Radio.php
Expand Up @@ -68,7 +68,12 @@ public function render($data) {
'label' => true,
'empty' => false,
];
$options = (array)$data['options'];
if ($data['options'] instanceof Traversable) {
$options = iterator_to_array($data['options']);
} else {
$options = (array)$data['options'];
}

$escape = $data['escape'];
if (!empty($data['empty'])) {
$empty = $data['empty'] === true ? 'empty' : $data['empty'];
Expand Down
8 changes: 8 additions & 0 deletions tests/TestCase/View/Input/RadioTest.php
Expand Up @@ -14,6 +14,7 @@
*/
namespace Cake\Test\TestCase\View\Input;

use Cake\Collection\Collection;
use Cake\TestSuite\TestCase;
use Cake\View\Input\Radio;
use Cake\View\StringTemplate;
Expand Down Expand Up @@ -67,6 +68,13 @@ public function testRenderSimple() {
'/label',
];
$this->assertTags($result, $expected);

$data = [
'name' => 'Crayons[color]',
'options' => new Collection(['r' => 'Red', 'b' => 'Black'])
];
$result = $radio->render($data);
$this->assertTags($result, $expected);
}

/**
Expand Down

0 comments on commit aa30d4b

Please sign in to comment.