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] Add `LocaleTypeTest::testInvalidLocaleMessage()` #29828

Open
wants to merge 1 commit into
base: 3.4
from

Conversation

Projects
None yet
3 participants
@phansys
Copy link
Contributor

phansys commented Jan 9, 2019

Q A
Branch 3.4
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets n/a
License MIT
Doc PR n/a

Since passing a invalid locale causes the form to be not synchronized, the validation fails because this reason instead of the locale validation.
Since I don't know if this is the expected behavior, this PR provides a test covering this situation in order to clarify this situation.

@phansys phansys changed the title Add `LocaleTypeTest::testInvalidLocaleMessage()` [Form] Add `LocaleTypeTest::testInvalidLocaleMessage()` Jan 9, 2019

@xabbuh

This comment has been minimized.

Copy link
Member

xabbuh commented Jan 10, 2019

The current behaviour is expected. The LocaleType is a specialised ChoiceType and the ChoiceType is automatically invalid in case an invalid choice is submitted (there have been bugfixes recently to ensure this behaviour).

@phansys

This comment has been minimized.

Copy link
Contributor

phansys commented Jan 10, 2019

Thank you for the response.
IIUC, based on that premise, when I submit a invalid locale through this form type I can't get the violation from LocaleValidator anymore?

@xabbuh

This comment has been minimized.

Copy link
Member

xabbuh commented Jan 10, 2019

Yes, that's right. But you can use the invalid_message option of the form type to reuse the message from the validator.

@phansys

This comment has been minimized.

Copy link
Contributor

phansys commented Jan 10, 2019

In that case, I should instantiate manually the Locale constraint just to obtain the $message property and pass it as the "invalid_message" option. Moreover, I think this solution doesn't cover (in an easy way) the scenario where the validation constraint has multiple possible messages or when one form field has more than one validation constraint associated to the property which the field represents.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment