merged branch grizlik/master (PR #3261)
Commits -------b65a997
[Form] Added test ChoiceList::testGetChoicesForValuesCorrectOrderingOfResult for correct ordering checka60daff
[Form] Fixed incorrect sorting in ChoiceList::getChoicesForValues Discussion ---------- [Form] Fixed incorrect sorting in ChoiceList::getChoicesForValues ChoiceList::getChoicesForValues return collection with sorting, that not corresponding to the sorting for input keys --------------------------------------------------------------------------- by bschussek at 2012-02-03T21:40:49Z Can you adapt the test cases to fail for this case please? (probably by use of assertSame instead of assertEquals in one of the existing tests) --------------------------------------------------------------------------- by grizlik at 2012-02-04T08:41:44Z I need to create a new test or modify an existing one? --------------------------------------------------------------------------- by bschussek at 2012-02-04T09:58:04Z Something like this in ChoiceListTest: public function testGetChoicesForValuesReverseOrderedValues() { $values = array('2', '1'); $this->assertSame(array($this->obj3, $this->obj2), $this->list->getChoicesForValues($values)); }
This commit is contained in:
commit
9855886dc5
@ -200,8 +200,8 @@ class ChoiceList implements ChoiceListInterface
|
|||||||
|
|
||||||
$choices = array();
|
$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) {
|
if ($value === $givenValue) {
|
||||||
$choices[] = $this->choices[$i];
|
$choices[] = $this->choices[$i];
|
||||||
unset($values[$j]);
|
unset($values[$j]);
|
||||||
|
@ -146,6 +146,12 @@ class ChoiceListTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertSame(array($this->obj2, $this->obj3), $this->list->getChoicesForValues($values));
|
$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()
|
public function testGetChoicesForValuesIgnoresNonExistingValues()
|
||||||
{
|
{
|
||||||
$values = array('1', '2', '5');
|
$values = array('1', '2', '5');
|
||||||
|
Reference in New Issue
Block a user