-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow nested input filter definitions.
- Loading branch information
Showing
4 changed files
with
102 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
/** | ||
* ze-content-validation (https://github.com/func0der/ze-content-validation) | ||
* | ||
* @copyright Copyright (c) 2017 MVLabs(http://mvlabs.it) | ||
* @copyright Copyright (c) 2021 func0der | ||
* @license MIT | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ZETest\ContentValidation\Extractor; | ||
|
||
use Laminas\InputFilter\Input; | ||
use Laminas\InputFilter\InputFilter; | ||
use PHPUnit\Framework\TestCase; | ||
use Prophecy\PhpUnit\ProphecyTrait; | ||
use ZE\ContentValidation\Validator\ValidationResult; | ||
|
||
class ValidationResultTest extends TestCase | ||
{ | ||
use ProphecyTrait; | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function itShouldProcessInvalidInputFiltersWithOnlyInputs(): void | ||
{ | ||
$inputFilter = (new InputFilter()) | ||
->add((new Input())->setRequired(true), 'foo') | ||
->add((new Input())->setRequired(true), 'bar'); | ||
|
||
$inputFilter->setData([]); | ||
|
||
$validationResult = ValidationResult::buildFromInputFilter($inputFilter, 'dummy'); | ||
|
||
self::assertEquals( | ||
[ | ||
'foo' => [ | ||
'isEmpty' => 'Value is required and can\'t be empty', | ||
], | ||
'bar' => [ | ||
'isEmpty' => 'Value is required and can\'t be empty', | ||
], | ||
], | ||
$validationResult->getMessages() | ||
); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function itShouldProcessInvalidInputFiltersWithInputsAndInputFilters(): void | ||
{ | ||
$inputFilter = (new InputFilter()) | ||
->add((new Input())->setRequired(true), 'foo') | ||
->add( | ||
(new InputFilter()) | ||
->add((new Input())->setRequired(true), 'nestedFooInBar'), | ||
'bar' | ||
); | ||
|
||
$inputFilter->setData([]); | ||
|
||
$validationResult = ValidationResult::buildFromInputFilter($inputFilter, 'dummy'); | ||
|
||
self::assertEquals( | ||
[ | ||
'foo' => [ | ||
'isEmpty' => 'Value is required and can\'t be empty', | ||
], | ||
'bar' => [ | ||
'nestedFooInBar' => [ | ||
'isEmpty' => 'Value is required and can\'t be empty', | ||
], | ||
], | ||
], | ||
$validationResult->getMessages() | ||
); | ||
} | ||
} |