-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Fixed DateType format option for single text widget #21063
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,22 @@ public function testSubmitFromSingleTextDateTimeWithDefaultFormat() | |
$this->assertEquals('2010-06-02', $form->getViewData()); | ||
} | ||
|
||
public function testSubmitFromSingleTextDateTimeWithCustomFormat() | ||
{ | ||
$form = $this->factory->create('date', null, array( | ||
'model_timezone' => 'UTC', | ||
'view_timezone' => 'UTC', | ||
'widget' => 'single_text', | ||
'input' => 'datetime', | ||
'format' => 'yyyy', | ||
)); | ||
|
||
$form->submit('2010'); | ||
|
||
$this->assertDateTimeEquals(new \DateTime('2010-01-01 UTC'), $form->getData()); | ||
$this->assertEquals('2010', $form->getViewData()); | ||
} | ||
|
||
public function testSubmitFromSingleTextDateTime() | ||
{ | ||
// we test against "de_AT", so we need the full implementation | ||
|
@@ -337,6 +353,7 @@ public function testThrowExceptionIfFormatIsNoPattern() | |
|
||
/** | ||
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException | ||
* @expectedExceptionMessage The "format" option should contain the letters "y", "M" and "d". Its current value is "yy". | ||
*/ | ||
public function testThrowExceptionIfFormatDoesNotContainYearMonthAndDay() | ||
{ | ||
|
@@ -346,6 +363,18 @@ public function testThrowExceptionIfFormatDoesNotContainYearMonthAndDay() | |
)); | ||
} | ||
|
||
/** | ||
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException | ||
* @expectedExceptionMessage The "format" option should contain the letters "y", "M" or "d". Its current value is "wrong". | ||
*/ | ||
public function testThrowExceptionIfFormatDoesNotContainYearMonthOrDay() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would include the fact that this is testing the specific behaviour for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done in ad8f189 |
||
{ | ||
$this->factory->create('date', null, array( | ||
'widget' => 'single_text', | ||
'format' => 'wrong', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You will now have to change the name of the method. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't change it on purpose as this is about |
||
)); | ||
} | ||
|
||
/** | ||
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xabbuh The expected value for day and month is tested here with first of each. For the year I'd say that the default is the current but I can add a test for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not convinced that this really is a bug fix. IMO being able to omit parts of a date is a new feature and you should then also be able to configure the values of the omitted parts.