Skip to content

Commit 51f75b4

Browse files
Merge branch '4.4' into 5.2
* 4.4: [Form] Use !isset for checks cause this doesn't falsely include 0 [Mailer] Fix typo in README sync ./phpunit in all branches
2 parents e2590a5 + 1791ca1 commit 51f75b4

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

Extension/Core/DataTransformer/DateTimeToArrayTransformer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ public function reverseTransform($value)
170170
empty($value['year']) ? $this->referenceDate->format('Y') : $value['year'],
171171
empty($value['month']) ? $this->referenceDate->format('m') : $value['month'],
172172
empty($value['day']) ? $this->referenceDate->format('d') : $value['day'],
173-
empty($value['hour']) ? $this->referenceDate->format('H') : $value['hour'],
174-
empty($value['minute']) ? $this->referenceDate->format('i') : $value['minute'],
175-
empty($value['second']) ? $this->referenceDate->format('s') : $value['second']
173+
$value['hour'] ?? $this->referenceDate->format('H'),
174+
$value['minute'] ?? $this->referenceDate->format('i'),
175+
$value['second'] ?? $this->referenceDate->format('s')
176176
),
177177
new \DateTimeZone($this->outputTimezone)
178178
);

Tests/Extension/Core/Type/DateTypeTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,32 @@ public function testSubmitFromSingleTextRaw()
204204
$this->assertEquals('02.06.2010', $form->getViewData());
205205
}
206206

207+
public function testArrayDateWithReferenceDoesUseReferenceTimeOnZero()
208+
{
209+
// we test against "de_DE", so we need the full implementation
210+
IntlTestHelper::requireFullIntl($this, false);
211+
212+
\Locale::setDefault('de_DE');
213+
214+
$input = [
215+
'day' => '0',
216+
'month' => '0',
217+
'year' => '0',
218+
];
219+
220+
$form = $this->factory->create(static::TESTED_TYPE, $input, [
221+
'format' => \IntlDateFormatter::MEDIUM,
222+
'html5' => false,
223+
'model_timezone' => 'UTC',
224+
'view_timezone' => 'Europe/Berlin',
225+
'input' => 'array',
226+
'widget' => 'single_text',
227+
]);
228+
229+
$this->assertSame($input, $form->getData());
230+
$this->assertEquals('01.01.1970', $form->getViewData());
231+
}
232+
207233
public function testSubmitFromText()
208234
{
209235
$form = $this->factory->create(static::TESTED_TYPE, null, [

Tests/Extension/Core/Type/TimeTypeTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,28 @@ public function testSubmitNullUsesDefaultEmptyData($emptyData = [], $expectedDat
978978
$this->assertSame($expectedData, $form->getData());
979979
}
980980

981+
public function testArrayTimeWithReferenceDoesNotUseReferenceTimeOnZero()
982+
{
983+
$form = $this->factory->create(static::TESTED_TYPE, null, [
984+
'model_timezone' => 'UTC',
985+
'view_timezone' => 'Europe/Berlin',
986+
'reference_date' => new \DateTimeImmutable('01-01-2021 12:34:56', new \DateTimeZone('UTC')),
987+
'input' => 'array',
988+
]);
989+
990+
$input = [
991+
'hour' => '0',
992+
'minute' => '0',
993+
];
994+
$form->submit($input);
995+
996+
$this->assertEquals([
997+
'hour' => '23',
998+
'minute' => '0',
999+
], $form->getData());
1000+
$this->assertSame($input, $form->getViewData());
1001+
}
1002+
9811003
/**
9821004
* @dataProvider provideEmptyData
9831005
*/

0 commit comments

Comments
 (0)