From a60daffb47d0562a67a2908576d5a57546a08296 Mon Sep 17 00:00:00 2001 From: grizlik Date: Fri, 3 Feb 2012 14:21:24 +0400 Subject: [PATCH 1/2] [Form] Fixed incorrect sorting in ChoiceList::getChoicesForValues --- .../Component/Form/Extension/Core/ChoiceList/ChoiceList.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php b/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php index c9d09a4904..b9559074a2 100644 --- a/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php +++ b/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php @@ -200,8 +200,8 @@ class ChoiceList implements ChoiceListInterface $choices = array(); - foreach ($this->values as $i => $value) { - foreach ($values as $j => $givenValue) { + foreach ($values as $j => $givenValue) { + foreach ($this->values as $i => $value) { if ($value === $givenValue) { $choices[] = $this->choices[$i]; unset($values[$j]); From b65a9972fbf4995f3f6857d0e9b26e3cf1e55649 Mon Sep 17 00:00:00 2001 From: grizlik Date: Sat, 4 Feb 2012 14:14:29 +0400 Subject: [PATCH 2/2] [Form] Added test ChoiceList::testGetChoicesForValuesCorrectOrderingOfResult for correct ordering check --- .../Form/Extension/Core/ChoiceList/ChoiceListTest.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/Symfony/Tests/Component/Form/Extension/Core/ChoiceList/ChoiceListTest.php b/tests/Symfony/Tests/Component/Form/Extension/Core/ChoiceList/ChoiceListTest.php index 7774b876c1..e63f609522 100644 --- a/tests/Symfony/Tests/Component/Form/Extension/Core/ChoiceList/ChoiceListTest.php +++ b/tests/Symfony/Tests/Component/Form/Extension/Core/ChoiceList/ChoiceListTest.php @@ -146,6 +146,12 @@ class ChoiceListTest extends \PHPUnit_Framework_TestCase $this->assertSame(array($this->obj2, $this->obj3), $this->list->getChoicesForValues($values)); } + public function testGetChoicesForValuesCorrectOrderingOfResult() + { + $values = array('2', '1'); + $this->assertSame(array($this->obj3, $this->obj2), $this->list->getChoicesForValues($values)); + } + public function testGetChoicesForValuesIgnoresNonExistingValues() { $values = array('1', '2', '5');