30
30
use Symfony \Component \Form \Forms ;
31
31
use Symfony \Component \Form \Test \TypeTestCase ;
32
32
use Symfony \Component \PropertyAccess \PropertyAccess ;
33
+ use Symfony \Bridge \Doctrine \Tests \Fixtures \SingleAssociationToIntIdEntity ;
34
+ use Symfony \Bridge \Doctrine \Tests \Fixtures \SingleIntIdNoToStringEntity ;
33
35
34
36
class EntityTypeTest extends TypeTestCase
35
37
{
36
38
const ITEM_GROUP_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\GroupableEntity ' ;
37
39
const SINGLE_IDENT_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity ' ;
40
+ const SINGLE_IDENT_NO_TO_STRING_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdNoToStringEntity ' ;
38
41
const SINGLE_STRING_IDENT_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\SingleStringIdEntity ' ;
42
+ const SINGLE_ASSOC_I
6D47
DENT_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\SingleAssociationToIntIdEntity ' ;
39
43
const COMPOSITE_IDENT_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIntIdEntity ' ;
40
44
const COMPOSITE_STRING_IDENT_CLASS = 'Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeStringIdEntity ' ;
41
45
@@ -60,7 +64,9 @@ protected function setUp()
60
64
$ classes = array (
61
65
$ this ->em ->getClassMetadata (self ::ITEM_GROUP_CLASS ),
62
66
$ this ->em ->getClassMetadata (self ::SINGLE_IDENT_CLASS ),
67
+ $ this ->em ->getClassMetadata (self ::SINGLE_IDENT_NO_TO_STRING_CLASS ),
63
68
$ this ->em ->getClassMetadata (self ::SINGLE_STRING_IDENT_CLASS ),
69
+ $ this ->em ->getClassMetadata (self ::SINGLE_ASSOC_IDENT_CLASS ),
64
70
$ this ->em ->getClassMetadata (self ::COMPOSITE_IDENT_CLASS ),
65
71
$ this ->em ->getClassMetadata (self ::COMPOSITE_STRING_IDENT_CLASS ),
66
72
);
@@ -304,6 +310,31 @@ public function testSubmitSingleNonExpandedSingleIdentifier()
304
310
$ this ->assertSame ('2 ' , $ field ->getViewData ());
305
311
}
306
312
313
+ public function testSubmitSingleNonExpandedSingleAssocIdentifier ()
314
+ {
315
+ $ innerEntity1 = new SingleIntIdNoToStringEntity (1 , 'InFoo ' );
316
+ $ innerEntity2 = new SingleIntIdNoToStringEntity (2 , 'InBar ' );
317
+
318
+ $ entity1 = new SingleAssociationToIntIdEntity ($ innerEntity1 , 'Foo ' );
319
+ $ entity2 = new SingleAssociationToIntIdEntity ($ innerEntity2 , 'Bar ' );
320
+
321
+ $ this ->persist (array ($ innerEntity1 , $ innerEntity2 , $ entity1 , $ entity2 ));
322
+
323
+ $ field = $ this ->factory ->createNamed ('name ' , 'entity ' , null , array (
324
+ 'multiple ' => false ,
325
+ 'expanded ' => false ,
326
+ 'em ' => 'default ' ,
327
+ 'class ' => self ::SINGLE_ASSOC_IDENT_CLASS ,
328
+ 'choice_label ' => 'name ' ,
329
+ ));
330
+
331
+ $ field ->submit ('2 ' );
332
+
333
+ $ this ->assertTrue ($ field ->isSynchronized ());
334
+ $ this ->assertSame ($ entity2 , $ field ->getData ());
335
+ $ this ->assertSame ('2 ' , $ field ->getViewData ());
336
+ }
337
+
307
338
public function testSubmitSingleNonExpandedCompositeIdentifier ()
308
339
{
309
340
$ entity1 = new CompositeIntIdEntity (10 , 20 , 'Foo ' );
@@ -352,6 +383,35 @@ public function testSubmitMultipleNonExpandedSingleIdentifier()
352
383
$ this ->assertSame (array ('1 ' , '3 ' ), $ field ->getViewData ());
353
384
}
354
385
386
+ public function testSubmitMultipleNonExpandedSingleAssocIdentifier ()
387
+ {
388
+ $ innerEntity1 = new SingleIntIdNoToStringEntity (1 , 'InFoo ' );
389
+ $ innerEntity2 = new SingleIntIdNoToStringEntity (2 , 'InBar ' );
390
+ $ innerEntity3 = new SingleIntIdNoToStringEntity (3 , 'InBaz ' );
391
+
392
+ $ entity1 = new SingleAssociationToIntIdEntity ($ innerEntity1 , 'Foo ' );
393
+ $ entity2 = new SingleAssociationToIntIdEntity ($ innerEntity2 , 'Bar ' );
394
+ $ entity3 = new SingleAssociationToIntIdEntity ($ innerEntity3 , 'Baz ' );
395
+
396
+ $ this ->persist (array ($ innerEntity1 , $ innerEntity2 , $ innerEntity3 , $ entity1 , $ entity2 , $ entity3 ));
397
+
398
+ $ field = $ this ->factory ->createNamed ('name ' , 'entity ' , null , array (
399
+ 'multiple ' => true ,
400
+ 'expanded ' => false ,
401
+ 'em ' => 'default ' ,
402
+ 'class ' => self ::SINGLE_ASSOC_IDENT_CLASS ,
403
+ 'choice_label ' => 'name ' ,
404
+ ));
405
+
406
+ $ field ->submit (array ('1 ' , '3 ' ));
407
+
408
+ $ expected = new ArrayCollection (array ($ entity1 , $ entity3 ));
409
+
410
+ $ this ->assertTrue ($ field ->isSynchronized ());
411
+ $ this ->assertEquals ($ expected , $ field ->getData ());
412
+ $ this ->assertSame (array ('1 ' , '3 ' ), $ field ->getViewData ());
413
+ }
414
+
355
415
public function testSubmitMultipleNonExpandedSingleIdentifierForExistingData ()
356
416
{
357
417
$ entity1 = new SingleIntIdEntity (1 , 'Foo ' );
@@ -636,6 +696,29 @@ public function testDisallowChoicesThatAreNotIncludedChoicesSingleIdentifier()
636
696
$ this ->assertNull ($ field ->getData ());
637
697
}
638
698
699
+ public function testDisallowChoicesThatAreNotIncludedChoicesSingleAssocIdentifier ()
700
+ {
701
+ $ innerEntity1 = new SingleIntIdNoToStringEntity (1 , 'InFoo ' );
702
+ $ innerEntity2 = new SingleIntIdNoToStringEntity (2 , 'InBar ' );
703
+
704
+ $ entity1 = new SingleAssociationToIntIdEntity ($ innerEntity1 , 'Foo ' );
705
+ $ entity2 = new SingleAssociationToIntIdEntity ($ innerEntity2 , 'Bar ' );
706
+
707
+ $ this ->persist (array ($ innerEntity1 , $ innerEntity2 , $ entity1 , $ entity2 ));
708
+
709
+ $ field = $ this ->factory ->createNamed ('name ' , 'entity ' , null , array (
710
+ 'em ' => 'default ' ,
711
+ 'class ' => self ::SINGLE_ASSOC_IDENT_CLASS ,
712
+ 'choices ' => array ($ entity1 , $ entity2 ),
713
+ 'choice_label ' => 'name ' ,
714
+ ));
715
+
716
+ $ field ->submit ('3 ' );
717
+
718
+ $ this ->assertFalse ($ field ->isSynchronized ());
719
+ $ this ->assertNull ($ field ->getData ());
720
+ }
721
+
639
722
public function testDisallowChoicesThatAreNotIncludedChoicesCompositeIdentifier ()
640
723
{
641
724
$ entity1 = new CompositeIntIdEntity (10 , 20 , 'Foo ' );
@@ -681,6 +764,34 @@ public function testDisallowChoicesThatAreNotIncludedQueryBuilderSingleIdentifie
681
764
$ this ->assertNull ($ field ->getData ());
682
765
}
683
766
767
+ public function testDisallowChoicesThatAreNotIncludedQueryBuilderSingleAssocIdentifier ()
768
+ {
769
+ $ innerEntity1 = new SingleIntIdNoToStringEntity (1 , 'InFoo ' );
770
+ $ innerEntity2 = new SingleIntIdNoToStringEntity (2 , 'InBar ' );
771
+ $ innerEntity3 = new SingleIntIdNoToStringEntity (3 , 'InBaz ' );
772
+
773
+ $ entity1 = new SingleAssociationToIntIdEntity ($ innerEntity1 , 'Foo ' );
774
+ $ entity2 = new SingleAssociationToIntIdEntity ($ innerEntity2 , 'Bar ' );
775
+ $ entity3 = new SingleAssociationToIntIdEntity ($ innerEntity3 , 'Baz ' );
776
+
777
+ $ this ->persist (array ($ innerEntity1 , $ innerEntity2 , $ innerEntity3 , $ entity1 , $ entity2 , $ entity3 ));
778
+
779
+ $ repository = $ this ->em ->getRepository (self ::SINGLE_ASSOC_IDENT_CLASS );
780
+
781
+ $ field = $ this ->factory ->createNamed ('name ' , 'entity ' , null , array (
782
+ 'em ' => 'default ' ,
783
+ 'class ' => self ::SINGLE_ASSOC_IDENT_CLASS ,
784
+ 'query_builder ' => $ repository ->createQueryBuilder ('e ' )
785
+ ->where ('e.entity IN (1, 2) ' ),
786
+ 'choice_label ' => 'name ' ,
787
+ ));
788
+
789
+ $ field ->submit ('3 ' );
790
+
791
+ $ this ->assertFalse ($ field ->isSynchronized ());
792
+ $ this ->assertNull ($ field ->getData ());
793
+ }
794
+
684
795
public function testDisallowChoicesThatAreNotIncludedQueryBuilderAsClosureSingleIdentifier ()
685
796
{
686
797
$ entity1 = new SingleIntIdEntity (1 , 'Foo ' );
0 commit comments