Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Missing required field with fallback does not return input in getValidInput #22

Conversation

Maks3w
Copy link
Member

@Maks3w Maks3w commented Aug 20, 2015

Test method says testMissingRequiredThatAllowsEmptyWithFallbackShouldMarkInputValid but don't assert input is returned in getValidInput

Should the input to be returned in getValidInput collection?

IMO it should because has a valid status.

Test was introduced in #10

@weierophinney
Copy link
Member

If it was not present in the submitted data, and is considered optional, it should not be in the returned values, unless it has a fallback value. In the case of the "valid inputs" set, even though it is considered valid, it was never actually validated as it was not submitted.

Further, changing the behavior now could lead to a new category of upgrade issues, as developers have been currently working on the assumption that the valid input set will not return inputs that were not submitted.

@weierophinney weierophinney removed this from the 2.4.8 milestone Aug 26, 2015
@weierophinney weierophinney reopened this Aug 26, 2015
@weierophinney
Copy link
Member

Evidently, what I stated above was the actual intent of the PR.

@@ -1069,6 +1069,8 @@ public function testMissingRequiredThatAllowsEmptyWithFallbackShouldMarkInputVal
$data = $filter->getValues();
$this->assertArrayHasKey('bar', $data);
$this->assertEquals($bar->getFallbackValue(), $data['bar']);
$this->assertArrayHasKey('bar', $filter->getValidInput());
$this->assertArrayNotHasKey('bar', $filter->getInvalidInput());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both of these should be asserting that the key is not present.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But bar has a fallback value. If not then assertTrue(isValid) should be false

@weierophinney
Copy link
Member

I've pulled this locally and made the change as noted above (in the first test, indicating that the input is in neither the list of valid or invalid inputs); all tests pass. I'll merge with that change.

@weierophinney weierophinney added this to the 2.4.8 milestone Aug 26, 2015
@weierophinney weierophinney self-assigned this Aug 26, 2015
@weierophinney weierophinney merged commit 803d555 into zendframework:master Aug 26, 2015
weierophinney added a commit that referenced this pull request Aug 26, 2015
…mark-input-as-valid

Missing required field with fallback does not return input in getValidInput
weierophinney added a commit that referenced this pull request Aug 26, 2015
weierophinney added a commit that referenced this pull request Aug 26, 2015
weierophinney added a commit that referenced this pull request Aug 26, 2015
weierophinney added a commit that referenced this pull request Aug 26, 2015
@Maks3w Maks3w deleted the hotfix/required-fallback-does-not-mark-input-as-valid branch September 1, 2015 07:46
weierophinney added a commit to weierophinney/zend-inputfilter that referenced this pull request Sep 8, 2015
Includes these changes:

- [14: NotEmpty validator doesn't override the required attribute](zendframework#14)
- [16: BC in validators context value](zendframework#16)
- [22: Missing required field with fallback does not return input in getValidInput](zendframework#22)
- [24: Fix loop validation input context is mutable](zendframework#24)
- [25: Fix missing optional fields should not be validated](zendframework#25)
- [32: Promote HHVM](zendframework#32)
- [36: Fix docblocks declared as regular comment block](zendframework#36)
- [40: Remove test about Input setters permutation](zendframework#40)
- [41: Refactor tests for group 7448 as a data set matrix](zendframework#41)
- [42: Consolidate InputFilterPluginManager tests](zendframework#42)
- [43: Consolidate Factory tests + Fixes](zendframework#43)
- [44: Consolidate of InputInterface::merge and Fix unsafe merge](zendframework#44)
- [45: When merge Inputs don't merge values if source does not have one.](zendframework#45)
- [46: Expand test matrix with nonempty value scenarios](zendframework#46)
- [47: Feature/minor test improvements](zendframework#47)
- [48: Empty values + Allow Empty + Not continue if empty is always true](zendframework#48)
- [49: Add tests for exceptions and improve some messages](zendframework#49)
- [50: Optional fields without value should be valid ](zendframework#50)
- [51: Optional input without value are valid](zendframework#51)
- [52: Fix merge two inputs without value, result 'has value' flag should be false](zendframework#52)
- [53: Tune NonEmpty options for detect the expected empty values](zendframework#53)
- [55: Make symmetric the scenarios when required is true/false](zendframework#55)
- [56: Hotfix/minor changes](zendframework#56)
- [57: Consolidate tests for InputFilterInterface](zendframework#57)
- [61: Provide NotEmpty::IS&zendframework#95;EMPTY validation message for required input](zendframework#61)
- [63: Ensure custom error messages are used for required missing inputs](zendframework#63)
- [64: Feature/test cleanup](zendframework#64)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants