From d380486756289c0165817a79c398e9736c37f770 Mon Sep 17 00:00:00 2001 From: Eric Clemmons Date: Thu, 26 May 2011 18:54:21 -0700 Subject: [PATCH] Added test for grouped entity choice list Refs #889 --- .../Form/ChoiceList/EntityChoiceListTest.php | 55 ++++++++++++++++++- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/tests/Symfony/Tests/Bridge/Doctrine/Form/ChoiceList/EntityChoiceListTest.php b/tests/Symfony/Tests/Bridge/Doctrine/Form/ChoiceList/EntityChoiceListTest.php index b17d916e7e42..777266130c0d 100644 --- a/tests/Symfony/Tests/Bridge/Doctrine/Form/ChoiceList/EntityChoiceListTest.php +++ b/tests/Symfony/Tests/Bridge/Doctrine/Form/ChoiceList/EntityChoiceListTest.php @@ -40,9 +40,9 @@ public function testChoicesMustBeManaged() { $entity1 = new SingleIdentEntity(1, 'Foo'); $entity2 = new SingleIdentEntity(2, 'Bar'); - + // no persist here! - + $choiceList = new EntityChoiceList( $this->em, self::SINGLE_IDENT_CLASS, @@ -53,8 +53,57 @@ public function testChoicesMustBeManaged() $entity2, ) ); - + // triggers loading -> exception $choiceList->getChoices(); } + + public function testFlattenedChoicesAreManaged() + { + $entity1 = new SingleIdentEntity(1, 'Foo'); + $entity2 = new SingleIdentEntity(2, 'Bar'); + + // Persist for managed state + $this->em->persist($entity1); + $this->em->persist($entity2); + + $choiceList = new EntityChoiceList( + $this->em, + self::SINGLE_IDENT_CLASS, + 'name', + null, + array( + $entity1, + $entity2, + ) + ); + + $this->assertSame(array(1 => 'Foo', 2 => 'Bar'), $choiceList->getChoices()); + } + + public function testNestedChoicesAreManaged() + { + $entity1 = new SingleIdentEntity(1, 'Foo'); + $entity2 = new SingleIdentEntity(2, 'Bar'); + + // Oh yea, we're persistin' with fire now! + $this->em->persist($entity1); + $this->em->persist($entity2); + + $choiceList = new EntityChoiceList( + $this->em, + self::SINGLE_IDENT_CLASS, + 'name', + null, + array( + 'group1' => array($entity1), + 'group2' => array($entity2), + ) + ); + + $this->assertSame(array( + 'group1' => array(1 => 'Foo'), + 'group2' => array(2 => 'Bar') + ), $choiceList->getChoices()); + } } \ No newline at end of file