Browse Source

Added test for grouped entity choice list
Refs #889

Eric Clemmons 14 years ago
parent
commit
d380486756

+ 52 - 3
tests/Symfony/Tests/Bridge/Doctrine/Form/ChoiceList/EntityChoiceListTest.php

@@ -40,9 +40,9 @@ class EntityChoiceListTest extends DoctrineOrmTestCase
     {
         $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 @@ class EntityChoiceListTest extends DoctrineOrmTestCase
                 $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());
+    }
 }