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

Commit

Permalink
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
19 changes: 12 additions & 7 deletions src/BaseInputFilter.php
Expand Up @@ -192,13 +192,15 @@ protected function validateInputs(array $inputs)
continue;
}

// key doesn't exist, input is required, allows empty; valid
// key doesn't exist, input is required, allows empty; valid if
// continueIfEmpty is false or input doesn't implement
// that interface; otherwise validation chain continues
if (!$dataExists
&& $input instanceof InputInterface
&& $input->isRequired()
&& $input->allowEmpty()
) {
if (!$input->allowEmpty()) {
if(!($input instanceOf EmptyContextInterface && $input->continueIfEmpty())) {
$this->validInputs[$name] = $input;
continue;
}
Expand All @@ -214,15 +216,19 @@ protected function validateInputs(array $inputs)
continue;
}

// key exists, is null, input is required, allows empty; valid
// key exists, is null, input is required, allows empty; valid if
// continueIfEmpty is false or input doesn't implement
// that interface; otherwise validation chain continues
if ($dataExists
&& null === $this->data[$name]
&& $input instanceof InputInterface
&& $input->isRequired()
&& $input->allowEmpty()
) {
$this->validInputs[$name] = $input;
continue;
if (!($input instanceof EmptyContextInterface && $input->continueIfEmpty())) {
$this->validInputs[$name] = $input;
continue;
}
}

// key exists, empty string, input is not required, allows empty; valid
Expand All @@ -240,11 +246,10 @@ protected function validateInputs(array $inputs)
if ($dataExists
&& '' === $this->data[$name]
&& $input instanceof InputInterface
&& $input instanceof EmptyContextInterface
&& $input->isRequired()
&& $input->allowEmpty()
) {
if (!$input->continueIfEmpty()) {
if (!($input instanceof EmptyContextInterface && $input->continueIfEmpty())) {
$this->validInputs[$name] = $input;
continue;
}
Expand Down
3 changes: 0 additions & 3 deletions test/BaseInputFilterTest.php
Expand Up @@ -581,8 +581,6 @@ public static function contextDataProvider()
*/
public function testValidationMarksInputValidWhenAllowEmptyFlagIsTrueAndContinueIfEmptyIsTrueAndContextValidatesEmptyField($allowEmpty, $blankIsValid, $valid)
{
// $this->markTestSkipped();

$filter = new InputFilter();

$data = array (
Expand All @@ -602,7 +600,6 @@ public function testValidationMarksInputValidWhenAllowEmptyFlagIsTrueAndContinue
$filter->add($allowEmpty, 'allowEmpty')
->add($blankIsValid, 'blankIsValid');
$filter->setData($data);
// die(var_dump($filter->get('blankIsValid')));

$this->assertSame($valid, $filter->isValid());
}
Expand Down

0 comments on commit 28a083e

Please sign in to comment.