Permalink
Browse files

Add a test for using an Collection for options.

Traversable/Collection instances should work for options.
  • Loading branch information...
1 parent 3a14f83 commit aa30d4b196d30ebaa6149480e96467aac6a5237c @markstory markstory committed Jan 11, 2014
Showing with 14 additions and 1 deletion.
  1. +6 −1 src/View/Input/Radio.php
  2. +8 −0 tests/TestCase/View/Input/RadioTest.php
View
@@ -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'];
@@ -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;
@@ -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);
}
/**

0 comments on commit aa30d4b

Please sign in to comment.