[Form] ArrayChoiceList can now deal with a null in choices
This commit is contained in:
parent
15c37c2442
commit
68292bb52b
@ -141,7 +141,7 @@ class ArrayChoiceList implements ChoiceListInterface
|
|||||||
$choices = array();
|
$choices = array();
|
||||||
|
|
||||||
foreach ($values as $i => $givenValue) {
|
foreach ($values as $i => $givenValue) {
|
||||||
if (isset($this->choices[$givenValue])) {
|
if (array_key_exists($givenValue, $this->choices)) {
|
||||||
$choices[$i] = $this->choices[$givenValue];
|
$choices[$i] = $this->choices[$givenValue];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,4 +130,11 @@ class ArrayChoiceListTest extends AbstractChoiceListTest
|
|||||||
$this->assertSame(array(2 => 'value2'), $choiceList->getValuesForChoices(array(2 => $obj2)));
|
$this->assertSame(array(2 => 'value2'), $choiceList->getValuesForChoices(array(2 => $obj2)));
|
||||||
$this->assertSame(array(2 => 'value2'), $choiceList->getValuesForChoices(array(2 => (object) array('value' => 'value2'))));
|
$this->assertSame(array(2 => 'value2'), $choiceList->getValuesForChoices(array(2 => (object) array('value' => 'value2'))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetChoicesForValuesWithContainingNull()
|
||||||
|
{
|
||||||
|
$choiceList = new ArrayChoiceList(array('Null' => null));
|
||||||
|
|
||||||
|
$this->assertSame(array(0 => null), $choiceList->getChoicesForValues(array('0')));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user