BUGFIX: Fix broken recursion with validation groups
Provide current validation group for recursive SettingsValidator. Adjust test. Provide configuration to outline the issue.
This commit is contained in:
parent
5c927e9dda
commit
2b41d5f3db
5 changed files with 33 additions and 24 deletions
|
@ -179,12 +179,11 @@ class SettingsValidator extends AbstractValidator
|
|||
protected function handleValidationGroups(array &$validatorConfig)
|
||||
{
|
||||
if (isset($validatorConfig['options']['validationGroups'])
|
||||
&& (
|
||||
$validatorConfig['validator'] !== 'DigiComp.SettingValidator:Settings'
|
||||
|| empty($validatorConfig['options']['validationGroups'])
|
||||
)
|
||||
&& $validatorConfig['validator'] !== 'DigiComp.SettingValidator:Settings'
|
||||
) {
|
||||
unset($validatorConfig['options']['validationGroups']);
|
||||
} elseif ($validatorConfig['validator'] === 'DigiComp.SettingValidator:Settings') {
|
||||
$validatorConfig['options']['validationGroups'] = $this->options['validationGroups'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,16 +13,26 @@ TrueValidator:
|
|||
BooleanValue:
|
||||
expectedValue: true
|
||||
|
||||
GroupValidatorDefault:
|
||||
DigiComp\SettingValidator\Tests\Functional\Fixtures\TestValidationGroupsCustomObject:
|
||||
self:
|
||||
BooleanValue:
|
||||
expectedValue: true
|
||||
validationGroups:
|
||||
- Default
|
||||
GroupValidatorCustom:
|
||||
self:
|
||||
BooleanValue:
|
||||
expectedValue: false
|
||||
validationGroups:
|
||||
- Custom
|
||||
DigiComp.SettingValidator:Settings:
|
||||
name: GroupValidatorCustom
|
||||
|
||||
DigiComp\SettingValidator\Tests\Functional\Fixtures\TestValidationGroupsDefaultObject:
|
||||
self:
|
||||
DigiComp.SettingValidator:Settings:
|
||||
name: GroupValidatorDefault
|
||||
|
||||
GroupValidatorDefault:
|
||||
properties:
|
||||
shouldBeTrue:
|
||||
BooleanValue:
|
||||
expectedValue: true
|
||||
|
||||
GroupValidatorCustom:
|
||||
properties:
|
||||
shouldBeFalse:
|
||||
BooleanValue:
|
||||
expectedValue: false
|
||||
validationGroups:
|
||||
- Custom
|
||||
|
|
|
@ -6,13 +6,11 @@ use Neos\Flow\Annotations as Flow;
|
|||
class TestValidationGroupsCustomObject
|
||||
{
|
||||
/**
|
||||
* @Flow\Validate(type="DigiComp.SettingValidator:Settings", options={"name": "GroupValidatorDefault", "validationGroups"={"Custom"}})
|
||||
* @var bool
|
||||
*/
|
||||
protected $shouldBeTrue = false;
|
||||
|
||||
/**
|
||||
* @Flow\Validate(type="DigiComp.SettingValidator:Settings", options={"name": "GroupValidatorCustom", "validationGroups"={"Custom"}})
|
||||
* @var bool
|
||||
*/
|
||||
protected $shouldBeFalse = true;
|
||||
|
|
|
@ -6,13 +6,11 @@ use Neos\Flow\Annotations as Flow;
|
|||
class TestValidationGroupsDefaultObject
|
||||
{
|
||||
/**
|
||||
* @Flow\Validate(type="DigiComp.SettingValidator:Settings", options={"name": "GroupValidatorDefault"})
|
||||
* @var bool
|
||||
*/
|
||||
protected $shouldBeTrue = false;
|
||||
|
||||
/**
|
||||
* @Flow\Validate(type="DigiComp.SettingValidator:Settings", options={"name": "GroupValidatorCustom"})
|
||||
* @var bool
|
||||
*/
|
||||
protected $shouldBeFalse = true;
|
||||
|
|
|
@ -37,17 +37,21 @@ class SettingsValidatorTest extends FunctionalTestCase
|
|||
/**
|
||||
* @test
|
||||
*/
|
||||
public function validationGroupsAreRespected()
|
||||
public function defaultValidationGroupWorks()
|
||||
{
|
||||
$validatorResolver = $this->objectManager->get(ValidatorResolver::class);
|
||||
|
||||
$validator = $validatorResolver->getBaseValidatorConjunction(TestValidationGroupsDefaultObject::class);
|
||||
$validator = $this->objectManager->get(SettingsValidator::class, ['validationGroups' => ['Default']]);
|
||||
$result = $validator->validate(new TestValidationGroupsDefaultObject());
|
||||
$this->assertTrue($result->hasErrors(), 'No Errors for validation group "Default"');
|
||||
$this->assertCount(1, $result->getFlattenedErrors(), 'Got a non expected number of errors for group "Default"');
|
||||
$this->assertCount(1, $result->forProperty('shouldBeTrue')->getErrors(), 'Got no error for shouldBeTrue property');
|
||||
}
|
||||
|
||||
$validator = $validatorResolver->getBaseValidatorConjunction(TestValidationGroupsCustomObject::class);
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function customValidationGroupWorks()
|
||||
{
|
||||
$validator = $this->objectManager->get(SettingsValidator::class, ['validationGroups' => ['Custom']]);
|
||||
$result = $validator->validate(new TestValidationGroupsCustomObject());
|
||||
$this->assertTrue($result->hasErrors(), 'No Errors for validation group "Custom"');
|
||||
$this->assertCount(1, $result->getFlattenedErrors(), 'Got a non expected number of errors for group "Custom"');
|
||||
|
|
Loading…
Reference in a new issue