Skip to content
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

[Form] BC break in validation #37262

Closed
craue opened this issue Jun 13, 2020 · 2 comments
Closed

[Form] BC break in validation #37262

craue opened this issue Jun 13, 2020 · 2 comments

Comments

@craue
Copy link
Contributor

craue commented Jun 13, 2020

This test passes with 3.4.40 but fails with 3.4.41 due to changes in #36865. (It also fails with 3.4.42.)

(I put it into DateTypeTest with some boilerplate code for the validator to easily switch between versions since the validator tests were moved between 3.4.41 and 3.4.42.)

I'm not sure if only DateType is affected. Just noticed this behavioral change on it.

/ping @xabbuh

diff --git Tests/Extension/Core/Type/DateTypeTest.php Tests/Extension/Core/Type/DateTypeTest.php
index cb2c2d0..a568c78 100644
--- Tests/Extension/Core/Type/DateTypeTest.php
+++ Tests/Extension/Core/Type/DateTypeTest.php
@@ -16,6 +16,12 @@
 use Symfony\Component\Form\FormInterface;
 use Symfony\Component\Intl\Util\IntlTestHelper;
 
+use Symfony\Component\Form\Extension\Validator\ValidatorExtension;
+use Symfony\Component\Form\Forms;
+use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory;
+use Symfony\Component\Validator\Mapping\Loader\StaticMethodLoader;
+use Symfony\Component\Validator\Validation;
+
 class DateTypeTest extends BaseTypeTest
 {
     const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\DateType';
@@ -220,6 +226,33 @@
         $this->assertEquals($text, $form->getViewData());
     }
 
+    public function testSubmitFormChoiceInvalid()
+    {
+        $this->validator = Validation::createValidatorBuilder()
+            ->setMetadataFactory(new LazyLoadingMetadataFactory(new StaticMethodLoader()))
+            ->getValidator();
+
+        $this->factory = Forms::createFormFactoryBuilder()
+            ->addExtension(new ValidatorExtension($this->validator))
+            ->getFormFactory();
+
+        $form = $this->factory->create(static::TESTED_TYPE, null, [
+            'widget' => 'choice',
+            'years' => [2021],
+        ]);
+
+        $form->submit([
+            'day' => '13',
+            'month' => '6',
+            'year' => '2020',
+        ]);
+
+        $this->assertTrue($form->isSubmitted());
+        $this->assertFalse($form->isValid());
+        $this->assertCount(1, $form->getErrors());
+        $this->assertSame('This value is not valid.', $form->getErrors()->current()->getMessage());
+    }
+
     public function testSubmitFromChoiceEmpty()
     {
         $form = $this->factory->create(static::TESTED_TYPE, null, [
@xabbuh
Copy link
Member

xabbuh commented Jun 18, 2020

@craue Thank you for reporting this bug. 👍 Can you confirm that #37345 solves it?

@craue
Copy link
Contributor Author

craue commented Jun 18, 2020

It does, @xabbuh. Thanks.

fabpot added a commit that referenced this issue Jun 20, 2020
This PR was merged into the 3.4 branch.

Discussion
----------

[Form] collect all transformation failures

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #37262
| License       | MIT
| Doc PR        |

Commits
-------

a9987ce collect all transformation failures
@fabpot fabpot closed this as completed Jun 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants