[Form] Adding an exception for an invalid widget option in DateType

This commit is contained in:
Ryan Weaver 2011-04-23 19:42:40 -05:00
parent 81deedfc1b
commit 78b2062c5e
2 changed files with 14 additions and 1 deletions

View File

@ -14,6 +14,7 @@ namespace Symfony\Component\Form\Extension\Core\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\Exception\FormException;
use Symfony\Component\Form\Extension\Core\ChoiceList\PaddedChoiceList;
use Symfony\Component\Form\Extension\Core\ChoiceList\MonthChoiceList;
use Symfony\Component\Form\FormView;
@ -36,7 +37,7 @@ class DateType extends AbstractType
if ($options['widget'] === 'text') {
$builder->appendClientTransformer(new DateTimeToLocalizedStringTransformer($options['data_timezone'], $options['user_timezone'], $options['format'], \IntlDateFormatter::NONE));
} else {
} elseif ($options['widget'] == 'choice') {
// Only pass a subset of the options to children
$yearOptions = array(
'choice_list' => new PaddedChoiceList(
@ -58,6 +59,8 @@ class DateType extends AbstractType
->add('month', 'choice', $monthOptions)
->add('day', 'choice', $dayOptions)
->appendClientTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['user_timezone'], array('year', 'month', 'day')));
} else {
throw new FormException('The "widget" option must be set to either "text" or "choice".');
}
if ($options['input'] === 'string') {

View File

@ -25,6 +25,16 @@ class DateTypeTest extends LocalizedTestCase
\Locale::setDefault('de_AT');
}
/**
* @expectedException Symfony\Component\Form\Exception\FormException
*/
public function testInvalidWidgetOption()
{
$form = $this->factory->create('date', 'name', array(
'widget' => 'fake_widget',
));
}
public function testSubmitFromInputDateTime()
{
$form = $this->factory->create('date', null, array(