Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge 225b20e into 4419eef
Browse files Browse the repository at this point in the history
  • Loading branch information
Erikvv committed Aug 16, 2018
2 parents 4419eef + 225b20e commit 4ee03f7
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/View/Helper/FormSelect.php
Expand Up @@ -285,7 +285,7 @@ protected function validateMultiValue($value, array $attributes)
}

if (! is_array($value)) {
return (array) $value;
return [$value];
}

if (! isset($attributes['multiple']) || ! $attributes['multiple']) {
Expand Down
25 changes: 25 additions & 0 deletions test/TestAsset/Identifier.php
@@ -0,0 +1,25 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Form\TestAsset;

class Identifier
{
private $id;

public function __construct($id)
{
$this->id = $id;
}

public function __toString()
{
return (string) $this->id;
}
}
28 changes: 28 additions & 0 deletions test/View/Helper/FormSelectTest.php
Expand Up @@ -12,6 +12,7 @@
use Zend\Form\Element;
use Zend\Form\Element\Select as SelectElement;
use Zend\Form\View\Helper\FormSelect as FormSelectHelper;
use ZendTest\Form\TestAsset\Identifier;

class FormSelectTest extends CommonTestCase
{
Expand Down Expand Up @@ -414,4 +415,31 @@ public function testRenderElementWithNoNameRaisesException()
$this->expectException('Zend\Form\Exception\DomainException');
$this->helper->render($element);
}

public function getElementWithObjectIdentifiers()
{
$element = new SelectElement('foo');
$options = [
[
'label' => 'This is the first label',
'value' => new Identifier(42),
],
[
'label' => 'This is the second label',
'value' => new Identifier(43),
],
];
$element->setValueOptions($options);
return $element;
}

public function testRenderElementWithObjectIdentifiers()
{
$element = $this->getElementWithObjectIdentifiers();
$element->setValue(new Identifier(42));

$markup = $this->helper->render($element);
$this->assertRegexp('#option .*?value="42" selected="selected"#', $markup);
$this->assertNotRegexp('#option .*?value="43" selected="selected"#', $markup);
}
}

0 comments on commit 4ee03f7

Please sign in to comment.