1313
1414require_once __DIR__ .'/../DoctrineOrmTestCase.php ' ;
1515require_once __DIR__ .'/../../Fixtures/SingleIdentEntity.php ' ;
16+ require_once __DIR__ .'/../../Fixtures/SingleStringIdentEntity.php ' ;
1617require_once __DIR__ .'/../../Fixtures/CompositeIdentEntity.php ' ;
18+ require_once __DIR__ .'/../../Fixtures/CompositeStringIdentEntity.php ' ;
1719
1820use Symfony \Component \Form \Exception \UnexpectedTypeException ;
1921use Symfony \Tests \Component \Form \Extension \Core \Type \TypeTestCase ;
2022use Symfony \Tests \Bridge \Doctrine \Form \DoctrineOrmTestCase ;
2123use Symfony \Tests \Bridge \Doctrine \Form \Fixtures \SingleIdentEntity ;
24+ use Symfony \Tests \Bridge \Doctrine \Form \Fixtures \SingleStringIdentEntity ;
2225use Symfony \Tests \Bridge \Doctrine \Form \Fixtures \CompositeIdentEntity ;
26+ use Symfony \Tests \Bridge \Doctrine \Form \Fixtures \CompositeStringIdentEntity ;
2327use Symfony \Bridge \Doctrine \Form \DoctrineOrmExtension ;
2428use Doctrine \ORM \Tools \SchemaTool ;
2529use Doctrine \ORM \EntityManager ;
2832class EntityTypeTest extends TypeTestCase
2933{
3034 const SINGLE_IDENT_CLASS = 'Symfony\Tests\Bridge\Doctrine\Form\Fixtures\SingleIdentEntity ' ;
31-
35+ const SINGLE_STRING_IDENT_CLASS = ' Symfony\Tests\Bridge\Doctrine\Form\Fixtures\SingleStringIdentEntity ' ;
3236 const COMPOSITE_IDENT_CLASS = 'Symfony\Tests\Bridge\Doctrine\Form\Fixtures\CompositeIdentEntity ' ;
37+ const COMPOSITE_STRING_IDENT_CLASS = 'Symfony\Tests\Bridge\Doctrine\Form\Fixtures\CompositeStringIdentEntity ' ;
3338
3439 private $ em ;
3540
@@ -46,7 +51,9 @@ protected function setUp()
4651 $ schemaTool = new SchemaTool ($ this ->em );
4752 $ classes = array (
4853 $ this ->em ->getClassMetadata (self ::SINGLE_IDENT_CLASS ),
54+ $ this ->em ->getClassMetadata (self ::SINGLE_STRING_IDENT_CLASS ),
4955 $ this ->em ->getClassMetadata (self ::COMPOSITE_IDENT_CLASS ),
56+ $ this ->em ->getClassMetadata (self ::COMPOSITE_STRING_IDENT_CLASS ),
5057 );
5158
5259 try {
@@ -558,4 +565,47 @@ public function testDisallowChoicesThatAreNotIncludedQueryBuilderAsClosureCompos
558565 $ this ->assertFalse ($ field ->isSynchronized ());
559566 $ this ->assertNull ($ field ->getData ());
560567 }
561- }
568+
569+ public function testSubmitSingleStringIdentifier ()
570+ {
571+ $ entity1 = new SingleStringIdentEntity ('foo ' , 'Foo ' );
572+
573+ $ this ->persist (array ($ entity1 ));
574+
575+ $ field = $ this ->factory ->createNamed ('entity ' , 'name ' , null , array (
576+ 'multiple ' => false ,
577+ 'expanded ' => false ,
578+ 'em ' => $ this ->em ,
579+ 'class ' => self ::SINGLE_STRING_IDENT_CLASS ,
580+ 'property ' => 'name ' ,
581+ ));
582+
583+ $ field ->bind ('foo ' );
584+
585+ $ this ->assertTrue ($ field ->isSynchronized ());
586+ $ this ->assertEquals ($ entity1 , $ field ->getData ());
587+ $ this ->assertEquals ('foo ' , $ field ->getClientData ());
588+ }
589+
590+ public function testSubmitCompositeStringIdentifier ()
591+ {
592+ $ entity1 = new CompositeStringIdentEntity ('foo1 ' , 'foo2 ' , 'Foo ' );
593+
594+ $ this ->persist (array ($ entity1 ));
595+
596+ $ field = $ this ->factory ->createNamed ('entity ' , 'name ' , null , array (
597+ 'multiple ' => false ,
598+ 'expanded ' => false ,
599+ 'em ' => $ this ->em ,
600+ 'class ' => self ::COMPOSITE_STRING_IDENT_CLASS ,
601+ 'property ' => 'name ' ,
602+ ));
603+
604+ // the collection key is used here
605+ $ field ->bind ('0 ' );
606+
607+ $ this ->assertTrue ($ field ->isSynchronized ());
608+ $ this ->assertEquals ($ entity1 , $ field ->getData ());
609+ $ this ->assertEquals (0 , $ field ->getClientData ());
610+ }
611+ }
0 commit comments