Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Form] Use !isset for checks cause this doesn't falsely include 0 #41000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ public function reverseTransform($value)
empty($value['year']) ? $this->referenceDate->format('Y') : $value['year'],
empty($value['month']) ? $this->referenceDate->format('m') : $value['month'],
empty($value['day']) ? $this->referenceDate->format('d') : $value['day'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please ensure we have a test case using 0 for year+month+day?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added it as test for DateType.

empty($value['hour']) ? $this->referenceDate->format('H') : $value['hour'],
empty($value['minute']) ? $this->referenceDate->format('i') : $value['minute'],
empty($value['second']) ? $this->referenceDate->format('s') : $value['second']
$value['hour'] ?? $this->referenceDate->format('H'),
$value['minute'] ?? $this->referenceDate->format('i'),
$value['second'] ?? $this->referenceDate->format('s')
),
new \DateTimeZone($this->outputTimezone)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,32 @@ public function testSubmitFromSingleTextRaw()
$this->assertEquals('02.06.2010', $form->getViewData());
}

public function testArrayDateWithReferenceDoesUseReferenceTimeOnZero()
{
// we test against "de_DE", so we need the full implementation
IntlTestHelper::requireFullIntl($this, false);

\Locale::setDefault('de_DE');

$input = [
'day' => '0',
'month' => '0',
'year' => '0',
];

$form = $this->factory->create(static::TESTED_TYPE, $input, [
'format' => \IntlDateFormatter::MEDIUM,
'html5' => false,
'model_timezone' => 'UTC',
'view_timezone' => 'Europe/Berlin',
'input' => 'array',
'widget' => 'single_text',
]);

$this->assertSame($input, $form->getData());
$this->assertEquals('01.01.1970', $form->getViewData());
}

public function testSubmitFromText()
{
$form = $this->factory->create(static::TESTED_TYPE, null, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,28 @@ public function testSubmitNullUsesDefaultEmptyData($emptyData = [], $expectedDat
$this->assertSame($expectedData, $form->getData());
}

public function testArrayTimeWithReferenceDoesNotUseReferenceTimeOnZero()
{
$form = $this->factory->create(static::TESTED_TYPE, null, [
'model_timezone' => 'UTC',
'view_timezone' => 'Europe/Berlin',
'reference_date' => new \DateTimeImmutable('01-01-2021 12:34:56', new \DateTimeZone('UTC')),
'input' => 'array',
]);

$input = [
'hour' => '0',
'minute' => '0',
];
$form->submit($input);

$this->assertEquals([
'hour' => '23',
'minute' => '0',
], $form->getData());
$this->assertSame($input, $form->getViewData());
}

/**
* @dataProvider provideEmptyData
*/
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.