From 55b3f75cb5e1755306e47ea4f77f9cca68a99f45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20BOURREAU?= Date: Tue, 2 Jan 2024 15:12:51 +0000 Subject: [PATCH] add failed test for partial data submitting with collections --- .../Tests/AbstractRequestHandlerTestCase.php | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/Symfony/Component/Form/Tests/AbstractRequestHandlerTestCase.php b/src/Symfony/Component/Form/Tests/AbstractRequestHandlerTestCase.php index d9ca3ef109401..c36c0ce454d7f 100644 --- a/src/Symfony/Component/Form/Tests/AbstractRequestHandlerTestCase.php +++ b/src/Symfony/Component/Form/Tests/AbstractRequestHandlerTestCase.php @@ -355,6 +355,53 @@ public function testMergeZeroIndexedCollection() $this->assertNotNull($itemsForm->get('0')->get('file')); } + public function testMergePartialDataFromCollection() + { + $form = $this->createForm('root', 'POST', true); + $form->add('items', CollectionType::class, [ + 'entry_type' => ItemFileType::class, + 'allow_add' => true, + ]); + + $file = $this->getUploadedFile(); + $file2 = $this->getUploadedFile(); + + $this->setRequestData('POST', [ + 'root' => [ + 'items' => [ + 1 => [ + 'item' => 'test', + ], + ], + ], + ], [ + 'root' => [ + 'items' => [ + 0 => [ + 'file' => $file, + ], + 1 => [ + 'file' => $file2, + ], + ], + ], + ]); + + $this->requestHandler->handleRequest($form, $this->request); + + $itemsForm = $form->get('items'); + $data = $itemsForm->getData(); + $this->assertTrue($form->isSubmitted()); + $this->assertTrue($form->isValid()); + + $this->assertCount(2, $data); + $this->assertArrayHasKey(0, $data); + $this->assertArrayHasKey(1, $data); + + $this->assertEquals('test', $itemsForm->get('1')->get('item')->getData()); + $this->assertNotNull($itemsForm->get('0')->get('file')); + } + /** * @dataProvider methodExceptGetProvider */