Permalink
Browse files

[Form] Removed separator characters between choice or text fields in …

…DateType
  • Loading branch information...
1 parent 6808a0d commit 5386e998f81a5234b86a7cfe9104d376f6a79476 @webmozart webmozart committed Dec 6, 2012
Showing with 29 additions and 11 deletions.
  1. +2 −0 CHANGELOG.md
  2. +6 −1 Extension/Core/Type/DateType.php
  3. +21 −10 Tests/Extension/Core/Type/DateTypeTest.php
View
@@ -7,6 +7,8 @@ CHANGELOG
* TrimListener now removes unicode whitespaces
* deprecated getParent(), setParent() and hasParent() in FormBuilderInterface
* FormInterface::add() now accepts a FormInterface instance OR a field's name, type and options
+ * removed special characters between the choice or text fields of DateType unless
+ the option "format" is set to a custom value
2.1.0
-----
@@ -137,13 +137,18 @@ public function finishView(FormView $view, FormInterface $form, array $options)
if ($form->getConfig()->hasAttribute('formatter')) {
$pattern = $form->getConfig()->getAttribute('formatter')->getPattern();
+ // remove special characters unless the format was explicitly specified
+ if (!is_string($options['format'])) {
+ $pattern = preg_replace('/[^yMd]+/', '', $pattern);
+ }
+
// set right order with respect to locale (e.g.: de_DE=dd.MM.yy; en_US=M/d/yy)
// lookup various formats at http://userguide.icu-project.org/formatparse/datetime
if (preg_match('/^([yMd]+).+([yMd]+).+([yMd]+)$/', $pattern)) {
$pattern = preg_replace(array('/y+/', '/M+/', '/d+/'), array('{{ year }}', '{{ month }}', '{{ day }}'), $pattern);
} else {
// default fallback
- $pattern = '{{ year }}-{{ month }}-{{ day }}';
+ $pattern = '{{ year }}{{ month }}{{ day }}';
}
$view->vars['date_pattern'] = $pattern;
@@ -24,21 +24,21 @@ protected function setUp()
}
/**
- * @expectedException Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
+ * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
*/
public function testInvalidWidgetOption()
{
- $form = $this->factory->create('date', null, array(
+ $this->factory->create('date', null, array(
'widget' => 'fake_widget',
));
}
/**
- * @expectedException Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
+ * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
*/
public function testInvalidInputOption()
{
- $form = $this->factory->create('date', null, array(
+ $this->factory->create('date', null, array(
'input' => 'fake_input',
));
}
@@ -271,7 +271,7 @@ public function testSubmitFromInputRawDifferentPattern()
* This test is to check that the strings '0', '1', '2', '3' are no accepted
* as valid IntlDateFormatter constants for FULL, LONG, MEDIUM or SHORT respectively.
*
- * @expectedException Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
+ * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
*/
public function testThrowExceptionIfFormatIsNoPattern()
{
@@ -283,7 +283,7 @@ public function testThrowExceptionIfFormatIsNoPattern()
}
/**
- * @expectedException Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
+ * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
*/
public function testThrowExceptionIfFormatDoesNotContainYearMonthAndDay()
{
@@ -294,7 +294,7 @@ public function testThrowExceptionIfFormatDoesNotContainYearMonthAndDay()
}
/**
- * @expectedException Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
+ * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
*/
public function testThrowExceptionIfFormatIsNoConstant()
{
@@ -304,7 +304,7 @@ public function testThrowExceptionIfFormatIsNoConstant()
}
/**
- * @expectedException Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
+ * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
*/
public function testThrowExceptionIfFormatIsInvalid()
{
@@ -510,7 +510,7 @@ public function testPassDatePatternToView()
$form = $this->factory->create('date');
$view = $form->createView();
- $this->assertSame('{{ day }}.{{ month }}.{{ year }}', $view->vars['date_pattern']);
+ $this->assertSame('{{ day }}{{ month }}{{ year }}', $view->vars['date_pattern']);
}
public function testPassDatePatternToViewDifferentFormat()
@@ -521,12 +521,23 @@ public function testPassDatePatternToViewDifferentFormat()
$view = $form->createView();
- $this->assertSame('{{ day }}. {{ month }} {{ year }}', $view->vars['date_pattern']);
+ $this->assertSame('{{ day }}{{ month }}{{ year }}', $view->vars['date_pattern']);
}
public function testPassDatePatternToViewDifferentPattern()
{
$form = $this->factory->create('date', null, array(
+ 'format' => 'MMyyyydd'
+ ));
+
+ $view = $form->createView();
+
+ $this->assertSame('{{ month }}{{ year }}{{ day }}', $view->vars['date_pattern']);
+ }
+
+ public function testPassDatePatternToViewDifferentPatternWithSeparators()
+ {
+ $form = $this->factory->create('date', null, array(
'format' => 'MM*yyyy*dd'
));

0 comments on commit 5386e99

Please sign in to comment.