Skip to content

Commit a11589f

Browse files
committed
bug #23980 Tests and fix for issue in array model data in EntityType field with multiple=true (stoccc)
This PR was squashed before being merged into the 2.7 branch (closes #23980). Discussion ---------- Tests and fix for issue in array model data in EntityType field with multiple=true | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | License | MIT | Fixed tickets | #23927 Provided some tests and the fix for #23927. Rebased to 2.7, replaces #23930 Commits ------- aaba6b4 Tests and fix for issue in array model data in EntityType field with multiple=true
2 parents a8d5359 + aaba6b4 commit a11589f

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

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

+34
Original file line numberDiff line numberDiff line change
@@ -1482,4 +1482,38 @@ public function testSubmitNullExpandedMultiple()
14821482
$this->assertEquals($collection, $form->getNormData());
14831483
$this->assertSame(array(), $form->getViewData(), 'View data is always an array');
14841484
}
1485+
1486+
public function testSetDataEmptyArraySubmitNullMultiple()
1487+
{
1488+
$emptyArray = array();
1489+
$form = $this->factory->create(static::TESTED_TYPE, null, array(
1490+
'em' => 'default',
1491+
'class' => self::SINGLE_IDENT_CLASS,
1492+
'multiple' => true,
1493+
));
1494+
$form->setData($emptyArray);
1495+
$form->submit(null);
1496+
$this->assertInternalType('array', $form->getData());
1497+
$this->assertEquals(array(), $form->getData());
1498+
$this->assertEquals(array(), $form->getNormData());
1499+
$this->assertSame(array(), $form->getViewData(), 'View data is always an array');
1500+
}
1501+
1502+
public function testSetDataNonEmptyArraySubmitNullMultiple()
1503+
{
1504+
$entity1 = new SingleIntIdEntity(1, 'Foo');
1505+
$this->persist(array($entity1));
1506+
$form = $this->factory->create(static::TESTED_TYPE, null, array(
1507+
'em' => 'default',
1508+
'class' => self::SINGLE_IDENT_CLASS,
1509+
'multiple' => true,
1510+
));
1511+
$existing = array(0 => $entity1);
1512+
$form->setData($existing);
1513+
$form->submit(null);
1514+
$this->assertInternalType('array', $form->getData());
1515+
$this->assertEquals(array(), $form->getData());
1516+
$this->assertEquals(array(), $form->getNormData());
1517+
$this->assertSame(array(), $form->getViewData(), 'View data is always an array');
1518+
}
14851519
}

src/Symfony/Bridge/Doctrine/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"require-dev": {
2323
"symfony/stopwatch": "~2.2",
2424
"symfony/dependency-injection": "~2.2",
25-
"symfony/form": "~2.7.25|^2.8.18",
25+
"symfony/form": "~2.7.34|^2.8.27",
2626
"symfony/http-kernel": "~2.2",
2727
"symfony/property-access": "~2.3",
2828
"symfony/security": "~2.2",

src/Symfony/Component/Form/Extension/Core/EventListener/MergeCollectionListener.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function onSubmit(FormEvent $event)
8080
return;
8181
}
8282

83-
if (!$dataToMergeInto) {
83+
if (null === $dataToMergeInto) {
8484
// No original data was set. Set it if allowed
8585
if ($this->allowAdd) {
8686
$dataToMergeInto = $data;

0 commit comments

Comments
 (0)