-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] [ChoiceType] Prefer placeholder to empty_value #16886
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
Conversation
4271ab1
to
4dec2c8
Compare
Use assertSame instead of assertEquals in some ChoiceTypeTest methods which test placeholder/empty_value options, because the tested value may be any number of "falsey" values.
Add an extra condition to the use of the value of the empty_value option as the placeholder: the value of the placeholder option must be null or an empty string (i.e. not explicitly set). Test the effects of setting both placeholder and empty_value.
'An unset empty_value is automaticaly made an empty string in a non-required field (but null is expected here) [maintains BC]' => array(false, false, false, null, null, ''), | ||
'An empty string empty_value is used if placeholder is not set [maintains BC]' => array(false, false, false, null, '', ''), | ||
'A non-empty string empty_value is used if placeholder is not set [maintains BC]' => array(false, false, false, null, 'bar', 'bar'), | ||
'A placeholder is not used if it is an empty string and empty_value is set to false [mainatins BC]' => array(false, false, false, '', false, null), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo "maintains"
👍 except your last test being very difficult to read. Perhaps you could organise lines by BC first, then by expanded or multiple. |
The fix looks good, but do we really need so many test fixtures? Can we reduce them to the bare minimum? |
@xabbuh the (admittedly extensive) test data were invaluable in that they revealed when the fix was finally correct after a number of failed attempts. Surely, one datum for each possible permutation is the bare minimum. |
$placeholder, | ||
$emptyValue, | ||
$viewValue | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be moved on one line
👍 |
👍 |
Thank you @boite. |
This PR was squashed before being merged into the 2.7 branch (closes #16886). Discussion ---------- [Form] [ChoiceType] Prefer placeholder to empty_value | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #16885 | License | MIT | Doc PR | - Prefer an explicitly set `placeholder` option (i.e. `false` or a non-empty string) to an `empty_value` option when both are set. The fix is to change the behaviour in the placeholder normalizer in ChoiceType::configureOptions so that the value of the `empty_value` option is used for placeholder only when the value of `placeholder` is null or an empty string. Commits ------- a4d4c8a [Form] [ChoiceType] Prefer placeholder to empty_value
'A placeholder is not used if it is explicitly set to false' => array(false, false, false, false, null, null), | ||
'A placeholder is not used if it is explicitly set to false' => array(false, false, false, false, '', null), | ||
'A placeholder is not used if it is explicitly set to false' => array(false, false, false, false, 'bar', null), | ||
'A placeholder is not used if empty_value is set to false [maintains BC]' => array(false, false, false, null, false, null), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All those tests may not run because some keys are overridden...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm on it
Here's the actual report :
|
Damn it! Will you let me sort this out? I'll do a better job of naming the data keys for readability (and uniqueness). |
I fixed it, but I still can hold the PR. What do I do ? |
This PR was merged into the 2.7 branch. Discussion ---------- [Form] fix tests added by #16886 | Q | A | ------------- | --- | Branch | 2.7+ | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #16886 | License | MIT | Doc PR | - Commits ------- bd22c86 minor [Form] fix tests added by #16886
* 2.7: Updated all the README files [TwigBundle] Fix failing test on appveyor Improved the error message when using "@" in a decorated service Improve error reporting in router panel of web profiler [DoctrineBridge][Form] Fix performance regression in EntityType [FrameworkBundle] Fix a regression in handling absolute and namespaced template paths Allow to normalize \Traversable minor [Form] fix tests added by #16886 Remove _path from query parameters when fragment is a subrequest and request attributes are already set Added tests for _path removal in FragmentListener Simplified everything Added a test Fixed the problem in an easier way Fixed a syntax issue Improved the error message when a template is not found [CodingStandards] Conformed to coding standards [TwigBundle] fixed Include file locations in "Template could not be found" exception
* 2.8: Updated all the README files [TwigBundle] Fix failing test on appveyor Improved the error message when using "@" in a decorated service Improve error reporting in router panel of web profiler [DoctrineBridge][Form] Fix performance regression in EntityType [FrameworkBundle] Fix a regression in handling absolute and namespaced template paths Allow to normalize \Traversable minor [Form] fix tests added by #16886 Remove _path from query parameters when fragment is a subrequest and request attributes are already set Added tests for _path removal in FragmentListener Simplified everything Added a test Fixed the problem in an easier way Fixed a syntax issue Improved the error message when a template is not found [CodingStandards] Conformed to coding standards [TwigBundle] fixed Include file locations in "Template could not be found" exception
* 3.0: Updated all the README files [TwigBundle] Fix failing test on appveyor Improved the error message when using "@" in a decorated service Improve error reporting in router panel of web profiler [DoctrineBridge][Form] Fix performance regression in EntityType [FrameworkBundle] Fix a regression in handling absolute and namespaced template paths Allow to normalize \Traversable minor [Form] fix tests added by #16886 Remove _path from query parameters when fragment is a subrequest and request attributes are already set Added tests for _path removal in FragmentListener Simplified everything Added a test Fixed the problem in an easier way Fixed a syntax issue Improved the error message when a template is not found [CodingStandards] Conformed to coding standards [TwigBundle] fixed Include file locations in "Template could not be found" exception
* 2.7: Updated all the README files [TwigBundle] Fix failing test on appveyor Improved the error message when using "@" in a decorated service Improve error reporting in router panel of web profiler [DoctrineBridge][Form] Fix performance regression in EntityType [FrameworkBundle] Fix a regression in handling absolute and namespaced template paths Allow to normalize \Traversable minor [Form] fix tests added by symfony#16886 Remove _path from query parameters when fragment is a subrequest and request attributes are already set Added tests for _path removal in FragmentListener Simplified everything Added a test Fixed the problem in an easier way Fixed a syntax issue Improved the error message when a template is not found [CodingStandards] Conformed to coding standards [TwigBundle] fixed Include file locations in "Template could not be found" exception
* 2.8: Updated all the README files [TwigBundle] Fix failing test on appveyor Improved the error message when using "@" in a decorated service Improve error reporting in router panel of web profiler [DoctrineBridge][Form] Fix performance regression in EntityType [FrameworkBundle] Fix a regression in handling absolute and namespaced template paths Allow to normalize \Traversable minor [Form] fix tests added by symfony#16886 Remove _path from query parameters when fragment is a subrequest and request attributes are already set Added tests for _path removal in FragmentListener Simplified everything Added a test Fixed the problem in an easier way Fixed a syntax issue Improved the error message when a template is not found [CodingStandards] Conformed to coding standards [TwigBundle] fixed Include file locations in "Template could not be found" exception
* 3.0: Updated all the README files [TwigBundle] Fix failing test on appveyor Improved the error message when using "@" in a decorated service Improve error reporting in router panel of web profiler [DoctrineBridge][Form] Fix performance regression in EntityType [FrameworkBundle] Fix a regression in handling absolute and namespaced template paths Allow to normalize \Traversable minor [Form] fix tests added by symfony#16886 Remove _path from query parameters when fragment is a subrequest and request attributes are already set Added tests for _path removal in FragmentListener Simplified everything Added a test Fixed the problem in an easier way Fixed a syntax issue Improved the error message when a template is not found [CodingStandards] Conformed to coding standards [TwigBundle] fixed Include file locations in "Template could not be found" exception
Prefer an explicitly set
placeholder
option (i.e.false
or a non-emptystring) to an
empty_value
option when both are set.The fix is to change the behaviour in the placeholder normalizer in
ChoiceType::configureOptions so that the value of the
empty_value
option isused for placeholder only when the value of
placeholder
is null or an emptystring.