Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6b07594

Browse filesBrowse files
committed
[DoctrineBridge] fix tests added in EntityType by #17693 with FQCN
1 parent afe4cbb commit 6b07594
Copy full SHA for 6b07594

File tree

1 file changed

+49
-0
lines changed
Filter options

1 file changed

+49
-0
lines changed

‎src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php
+49Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,55 @@ public function testOverrideChoices()
766766
$this->assertSame('2', $field->getViewData());
767767
}
768768

769+
public function testOverrideChoicesValues()
770+
{
771+
$entity1 = new SingleIntIdEntity(1, 'Foo');
772+
$entity2 = new SingleIntIdEntity(2, 'Bar');
773+
774+
$this->persist(array($entity1, $entity2));
775+
776+
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
777+
'em' => 'default',
778+
'class' => self::SINGLE_IDENT_CLASS,
779+
'choice_label' => 'name',
780+
'choice_value' => 'name',
781+
));
782+
783+
$field->submit('Bar');
784+
785+
$this->assertEquals(array('Foo' => new ChoiceView($entity1, 'Foo', 'Foo'), 'Bar' => new ChoiceView($entity2, 'Bar', 'Bar')), $field->createView()->vars['choices']);
786+
$this->assertTrue($field->isSynchronized(), 'Field should be synchronized.');
787+
$this->assertSame($entity2, $field->getData(), 'Entity should be loaded by custom value.');
788+
$this->assertSame('Bar', $field->getViewData());
789+
}
790+
791+
public function testOverrideChoicesValuesWithCallable()
792+
{
793+
$entity1 = new GroupableEntity(1, 'Foo', 'BazGroup');
794+
$entity2 = new GroupableEntity(2, 'Bar', 'BooGroup');
795+
796+
$this->persist(array($entity1, $entity2));
797+
798+
$field = $this->factory->createNamed('name', 'Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array(
799+
'em' => 'default',
800+
'class' => self::ITEM_GROUP_CLASS,
801+
'choice_label' => 'name',
802+
'choice_value' => function (GroupableEntity $entity) {
803+
return $entity->groupName.'/'.$entity->name;
804+
},
805+
));
806+
807+
$field->submit('BooGroup/Bar');
808+
809+
$this->assertEquals(array(
810+
'BazGroup/Foo' => new ChoiceView($entity1, 'BazGroup/Foo', 'Foo'),
811+
'BooGroup/Bar' => new ChoiceView($entity2, 'BooGroup/Bar', 'Bar'),
812+
), $field->createView()->vars['choices']);
813+
$this->assertTrue($field->isSynchronized(), 'Field should be synchronized.');
814+
$this->assertSame($entity2, $field->getData(), 'Entity should be loaded by custom value.');
815+
$this->assertSame('BooGroup/Bar', $field->getViewData());
816+
}
817+
769818
public function testGroupByChoices()
770819
{
771820
$item1 = new GroupableEntity(1, 'Foo', 'Group1');

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.