Skip to content

Commit

Permalink
merged branch mpiecko/master (PR #5280)
Browse files Browse the repository at this point in the history
Commits
-------

58ebd1b [Form] Fixed error bubbling from DateTime widget - Issue #5270
8ea1607 Update src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php

Discussion
----------

[Form] Fixed error bubbling from DateTime widget - Issue #5270

This is related to #5270

---------------------------------------------------------------------------

by mpiecko at 2012-08-16T19:37:45Z

Travisbot shows something like this in it's log:

    [Composer\Downloader\TransportException] The "http://nodeload.github.com/phingofficial/phing/zipball/2.4.12" file could not be downloaded (HTTP/1.1 500 Internal Server Error)

So is it my PR ot Travis CI who fails ... ? I saw this error in some other PR's ...

---------------------------------------------------------------------------

by stloyd at 2012-08-16T20:40:39Z

It's GitHub =)

---------------------------------------------------------------------------

by mpiecko at 2012-08-17T09:36:31Z

Bad GitHub :)

---------------------------------------------------------------------------

by bschussek at 2012-08-17T11:21:39Z

Could you please add a test to DateTimeTypeTest?

---------------------------------------------------------------------------

by mpiecko at 2012-08-17T12:23:40Z

Sure!

---------------------------------------------------------------------------

by bschussek at 2012-08-30T08:20:08Z

:+1:
  • Loading branch information
fabpot committed Aug 30, 2012
2 parents 548db6d + 58ebd1b commit 03f34a9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
Expand Up @@ -140,8 +140,8 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$dateOptions['format'] = $options['date_format'];
}

$dateOptions['input'] = 'array';
$timeOptions['input'] = 'array';
$dateOptions['input'] = $timeOptions['input'] = 'array';
$dateOptions['error_bubbling'] = $timeOptions['error_bubbling'] = true;

$builder
->addViewTransformer(new DataTransformerChain(array(
Expand Down Expand Up @@ -231,6 +231,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
// Don't modify \DateTime classes by reference, we treat
// them like immutable value objects
'by_reference' => false,
'error_bubbling' => false,
// If initialized with a \DateTime object, FormType initializes
// this option to "\DateTime". Since the internal, normalized
// representation is not \DateTime, but an array, we need to unset
Expand Down
Expand Up @@ -11,6 +11,8 @@

namespace Symfony\Component\Form\Tests\Extension\Core\Type;

use Symfony\Component\Form\FormError;

class DateTimeTypeTest extends LocalizedTestCase
{
public function testSubmit_dateTime()
Expand Down Expand Up @@ -386,4 +388,53 @@ public function testDontPassHtml5TypeIfNotSingleText()
$view = $form->createView();
$this->assertFalse(isset($view->vars['type']));
}

public function testDateTypeChoiceErrorsBubbleUp()
{
$error = new FormError('Invalid!');
$form = $this->factory->create('datetime', null);

$form['date']->addError($error);

$this->assertSame(array(), $form['date']->getErrors());
$this->assertSame(array($error), $form->getErrors());
}

public function testDateTypeSingleTextErrorsBubbleUp()
{
$error = new FormError('Invalid!');
$form = $this->factory->create('datetime', null, array(
'date_widget' => 'single_text'
));

$form['date']->addError($error);

$this->assertSame(array(), $form['date']->getErrors());
$this->assertSame(array($error), $form->getErrors());
}

public function testTimeTypeChoiceErrorsBubbleUp()
{
$error = new FormError('Invalid!');
$form = $this->factory->create('datetime', null);

$form['time']->addError($error);

$this->assertSame(array(), $form['time']->getErrors());
$this->assertSame(array($error), $form->getErrors());
}

public function testTimeTypeSingleTextErrorsBubbleUp()
{
$error = new FormError('Invalid!');
$form = $this->factory->create('datetime', null, array(
'time_widget' => 'single_text'
));

$form['time']->addError($error);

$this->assertSame(array(), $form['time']->getErrors());
$this->assertSame(array($error), $form->getErrors());
}

}

0 comments on commit 03f34a9

Please sign in to comment.