-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from SandroMiguel/feat/multi-lang-fields
feat(validator.php): add support for specific variant multilingual fi…
- Loading branch information
Showing
3 changed files
with
75 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,15 +3,10 @@ | |
/** | ||
* RequiredTest. | ||
* | ||
* PHP Version 7.2.11-3 | ||
* | ||
* @package Verum-PHP | ||
* @license MIT https://github.com/SandroMiguel/verum-php/blob/master/LICENSE | ||
* @author Sandro Miguel Marques <[email protected]> | ||
* @copyright 2020 Sandro | ||
* @since Verum-PHP 1.0.0 | ||
* @version 2.0.0 (2020/09/16) | ||
* @link https://github.com/SandroMiguel/verum-php | ||
* @package Verum-PHP | ||
* @license MIT https://github.com/SandroMiguel/verum-php/blob/master/LICENSE | ||
* @author Sandro Miguel Marques <[email protected]> | ||
* @version 2.0.0 (2020/09/16) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
@@ -234,6 +229,33 @@ public function testValidateNullForMixedFields(): void | |
$this->assertFalse($isValid); | ||
} | ||
|
||
/** | ||
* A required rule for "subject.pt" should fail if its value is null, even if | ||
* "subject.en" is valid. | ||
*/ | ||
public function testValidateRequiredForSpecificCompositeField(): void | ||
{ | ||
$fieldValues = [ | ||
'subject.en' => 'hello en', | ||
]; | ||
|
||
$fieldRules = [ | ||
'subject.pt' => [ | ||
'rules' => [RuleEnum::REQUIRED], | ||
], | ||
]; | ||
|
||
$validator = new Validator($fieldValues, $fieldRules); | ||
$isValid = $validator->validate(); | ||
|
||
$this->assertFalse($isValid); | ||
$this->assertArrayHasKey('subject.pt', $validator->getErrors()); | ||
$this->assertEquals( | ||
'This field is required.', | ||
$validator->getErrors()['subject.pt']['rules']['required'] | ||
); | ||
} | ||
|
||
/** | ||
* A field with a rule defined but not present in the payload should not | ||
* pass validation. | ||
|