22
33namespace Doctrine \Bundle \MongoDBBundle \Tests \Form \Type ;
44
5+ use Doctrine \Bundle \MongoDBBundle \Tests \Fixtures \Form \Category ;
6+ use Doctrine \Bundle \MongoDBBundle \Tests \Fixtures \Form \Document ;
57use Doctrine \Bundle \MongoDBBundle \Tests \TestCase ;
68use Doctrine \Bundle \MongoDBBundle \Form \DoctrineMongoDBExtension ;
79use Symfony \Component \Form \Test \TypeTestCase ;
@@ -28,6 +30,21 @@ public function setUp()
2830 parent ::setUp ();
2931 }
3032
33+ protected function tearDown ()
34+ {
35+ $ documentClasses = array (
36+ 'Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Form\Document ' ,
37+ 'Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Form\Category ' ,
38+ );
39+
40+ foreach ($ documentClasses as $ class ) {
41+ $ this ->dm ->getDocumentCollection ($ class )->drop ();
42+ }
43+
44+ parent ::tearDown ();
45+ }
46+
47+
3148 public function testDocumentManagerOptionSetsEmOption ()
3249 {
3350 $ field = $ this ->factory ->createNamed ('name ' , 'document ' , null , array (
@@ -49,6 +66,38 @@ public function testSettingDocumentManagerAndEmOptionShouldThrowException()
4966 ));
5067 }
5168
69+ public function testManyToManyReferences ()
70+ {
71+ $ categoryOne = new Category ('one ' );
72+ $ this ->dm ->persist ($ categoryOne );
73+ $ categoryTwo = new Category ('two ' );
74+ $ this ->dm ->persist ($ categoryTwo );
75+
76+ $ document = new Document (new \MongoId (), 'document ' );
77+ $ document ->categories [] = $ categoryOne ;
78+ $ this ->dm ->persist ($ document );
79+
80+ $ this ->dm ->flush ();
81+
82+ $ form = $ this ->factory ->create ('form ' , $ document )
83+ ->add (
84+ 'categories ' , 'document ' , array (
85+ 'class ' => 'Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Form\Category ' ,
86+ 'multiple ' => true ,
87+ 'expanded ' => true ,
88+ 'document_manager ' => 'default '
89+ )
90+ );
91+
92+ $ view = $ form ->createView ();
93+ $ categoryView = $ view ['categories ' ];
94+ $ this ->assertInstanceOf ('Symfony\Component\Form\FormView ' , $ categoryView );
95+
96+ $ this ->assertCount (2 , $ categoryView ->children );
97+ $ this ->assertTrue ($ categoryView ->children [0 ]->vars ['checked ' ]);
98+ $ this ->assertFalse ($ categoryView ->children [1 ]->vars ['checked ' ]);
99+ }
100+
52101 protected function createRegistryMock ($ name , $ dm )
53102 {
54103 $ registry = $ this ->getMock ('Doctrine\Common\Persistence\ManagerRegistry ' );
0 commit comments