Skip to content

[Form] BC break in validation #37262

@craue

Description

@craue

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, [

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy