Przeglądaj źródła

[Form] Throwing exception for invalid "input" type of DateType

Also fixed typo in test of previous commit
Ryan Weaver 14 lat temu
rodzic
commit
af8aad9c34

+ 2 - 0
src/Symfony/Component/Form/Extension/Core/Type/DateType.php

@@ -75,6 +75,8 @@ class DateType extends AbstractType
             $builder->appendNormTransformer(new ReversedTransformer(
             $builder->appendNormTransformer(new ReversedTransformer(
                 new DateTimeToArrayTransformer($options['data_timezone'], $options['data_timezone'], array('year', 'month', 'day'))
                 new DateTimeToArrayTransformer($options['data_timezone'], $options['data_timezone'], array('year', 'month', 'day'))
             ));
             ));
+        } else if ($options['input'] !== 'datetime') {
+            throw new FormException('The "input" option must be "datetime", "string", "timestamp" or "array".');
         }
         }
 
 
         $builder
         $builder

+ 11 - 1
tests/Symfony/Tests/Component/Form/Extension/Core/Type/DateTypeTest.php

@@ -30,11 +30,21 @@ class DateTypeTest extends LocalizedTestCase
      */
      */
     public function testInvalidWidgetOption()
     public function testInvalidWidgetOption()
     {
     {
-        $form = $this->factory->create('date', 'name', array(
+        $form = $this->factory->create('date', null, array(
             'widget' => 'fake_widget',
             'widget' => 'fake_widget',
         ));
         ));
     }
     }
 
 
+    /**
+     * @expectedException Symfony\Component\Form\Exception\FormException
+     */
+    public function testInvalidInputOption()
+    {
+        $form = $this->factory->create('date', null, array(
+            'input' => 'fake_input',
+        ));
+    }
+
     public function testSubmitFromInputDateTime()
     public function testSubmitFromInputDateTime()
     {
     {
         $form = $this->factory->create('date', null, array(
         $form = $this->factory->create('date', null, array(