Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add a test for using an Collection for options.

Traversable/Collection instances should work for options.
  • Loading branch information...
commit aa30d4b196d30ebaa6149480e96467aac6a5237c 1 parent 3a14f83
@markstory markstory authored
View
7 src/View/Input/Radio.php
@@ -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'];
View
8 tests/TestCase/View/Input/RadioTest.php
@@ -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);
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.