|
15 | 15 | use Symfony\Component\EventDispatcher\EventDispatcher;
|
16 | 16 | use Symfony\Component\Form\Exception\AlreadySubmittedException;
|
17 | 17 | use Symfony\Component\Form\Extension\Core\DataMapper\DataMapper;
|
| 18 | +use Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper; |
| 19 | +use Symfony\Component\Form\Extension\Core\Type\DateType; |
18 | 20 | use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
19 | 21 | use Symfony\Component\Form\Extension\Core\Type\TextType;
|
20 | 22 | use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationRequestHandler;
|
|
36 | 38 | use Symfony\Component\Form\Tests\Fixtures\Map;
|
37 | 39 | use Symfony\Component\HttpFoundation\File\UploadedFile;
|
38 | 40 | use Symfony\Component\HttpFoundation\Request;
|
| 41 | +use Symfony\Component\PropertyAccess\PropertyAccess; |
39 | 42 |
|
40 | 43 | class CompoundFormTest extends TestCase
|
41 | 44 | {
|
@@ -1086,6 +1089,30 @@ public function testFileUpload()
|
1086 | 1089 | $this->assertNull($this->form->get('bar')->getData());
|
1087 | 1090 | }
|
1088 | 1091 |
|
| 1092 | + public function testMapDateTimeObjectsWithEmptyArrayData() |
| 1093 | + { |
| 1094 | + $propertyAccessor = PropertyAccess::createPropertyAccessorBuilder() |
| 1095 | + ->enableExceptionOnInvalidIndex() |
| 1096 | + ->getPropertyAccessor(); |
| 1097 | + $form = $this->factory->createBuilder() |
| 1098 | + ->setDataMapper(new PropertyPathMapper($propertyAccessor)) |
| 1099 | + ->add('date', DateType::class, [ |
| 1100 | + 'auto_initialize' => false, |
| 1101 | + 'format' => 'dd/MM/yyyy', |
| 1102 | + 'html5' => false, |
| 1103 | + 'model_timezone' => 'UTC', |
| 1104 | + 'view_timezone' => 'UTC', |
| 1105 | + 'widget' => 'single_text', |
| 1106 | + ]) |
| 1107 | + ->getForm(); |
| 1108 | + |
| 1109 | + $form->submit([ |
| 1110 | + 'date' => '04/08/2022', |
| 1111 | + ]); |
| 1112 | + |
| 1113 | + $this->assertEquals(['date' => new \DateTime('2022-08-04', new \DateTimeZone('UTC'))], $form->getData()); |
| 1114 | + } |
| 1115 | + |
1089 | 1116 | private function createForm(string $name = 'name', bool $compound = true): FormInterface
|
1090 | 1117 | {
|
1091 | 1118 | $builder = $this->getBuilder($name);
|
|
0 commit comments