|
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 | {
|
@@ -1076,6 +1079,30 @@ public function testFileUpload()
|
1076 | 1079 | $this->assertNull($this->form->get('bar')->getData());
|
1077 | 1080 | }
|
1078 | 1081 |
|
| 1082 | + public function testMapDateTimeObjectsWithEmptyArrayData() |
| 1083 | + { |
| 1084 | + $propertyAccessor = PropertyAccess::createPropertyAccessorBuilder() |
| 1085 | + ->enableExceptionOnInvalidIndex() |
| 1086 | + ->getPropertyAccessor(); |
| 1087 | + $form = $this->factory->createBuilder() |
| 1088 | + ->setDataMapper(new PropertyPathMapper($propertyAccessor)) |
| 1089 | + ->add('date', DateType::class, [ |
| 1090 | + 'auto_initialize' => false, |
| 1091 | + 'format' => 'dd/MM/yyyy', |
| 1092 | + 'html5' => false, |
| 1093 | + 'model_timezone' => 'UTC', |
| 1094 | + 'view_timezone' => 'UTC', |
| 1095 | + 'widget' => 'single_text', |
| 1096 | + ]) |
| 1097 | + ->getForm(); |
| 1098 | + |
| 1099 | + $form->submit([ |
| 1100 | + 'date' => '04/08/2022', |
| 1101 | + ]); |
| 1102 | + |
| 1103 | + $this->assertEquals(['date' => new \DateTime('2022-08-04', new \DateTimeZone('UTC'))], $form->getData()); |
| 1104 | + } |
| 1105 | + |
1079 | 1106 | private function createForm(string $name = 'name', bool $compound = true): FormInterface
|
1080 | 1107 | {
|
1081 | 1108 | $builder = $this->getBuilder($name);
|
|
0 commit comments