Skip to content

Commit

Permalink
[Form] Fix a BC break in the entity
Browse files Browse the repository at this point in the history
  • Loading branch information
jakzal committed Jul 14, 2015
1 parent 095bfd6 commit 03642b8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static function createChoiceLabel($choice)
*/
public static function createChoiceName($choice, $key, $value)
{
return (string) $value;
return str_replace('-', '_', (string) $value);
}

/**
Expand Down
25 changes: 25 additions & 0 deletions src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,31 @@ public function testSubmitMultipleExpanded()
$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');
Expand Down

0 comments on commit 03642b8

Please sign in to comment.