From 03642b8ffeaf68b25a61308a7ee9f60e3993bdba Mon Sep 17 00:00:00 2001 From: Jakub Zalas Date: Tue, 14 Jul 2015 19:21:52 +0100 Subject: [PATCH] [Form] Fix a BC break in the entity --- .../Doctrine/Form/Type/DoctrineType.php | 2 +- .../Tests/Form/Type/EntityTypeTest.php | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php b/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php index 2c5012dedf..f84d4965bf 100644 --- a/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php +++ b/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php @@ -87,7 +87,7 @@ abstract class DoctrineType extends AbstractType */ public static function createChoiceName($choice, $key, $value) { - return (string) $value; + return str_replace('-', '_', (string) $value); } /** diff --git a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php index e22db0093c..b9680b45e5 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php @@ -495,6 +495,31 @@ class EntityTypeTest extends TypeTestCase $this->assertSame('3', $field['3']->getViewData()); } + public function testSubmitMultipleExpandedWithNegativeIntegerId() + { + $entity1 = new SingleIntIdEntity(-1, 'Foo'); + $entity2 = new SingleIntIdEntity(2, 'Bar'); + + $this->persist(array($entity1, $entity2)); + + $field = $this->factory->createNamed('name', 'entity', null, array( + 'multiple' => true, + 'expanded' => true, + 'em' => 'default', + 'class' => self::SINGLE_IDENT_CLASS, + 'choice_label' => 'name', + )); + + $field->submit(array('-1')); + + $expected = new ArrayCollection(array($entity1)); + + $this->assertTrue($field->isSynchronized()); + $this->assertEquals($expected, $field->getData()); + $this->assertTrue($field['_1']->getData()); + $this->assertFalse($field['2']->getData()); + } + public function testOverrideChoices() { $entity1 = new SingleIntIdEntity(1, 'Foo');