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:
Daniel Siepmann 2017-07-19 12:54:29 +02:00
parent 5c927e9dda
commit 2b41d5f3db
No known key found for this signature in database
GPG key ID: 33D6629915560EF4
5 changed files with 33 additions and 24 deletions

View file

@ -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'];
}
}
}

View file

@ -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

View file

@ -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;

View file

@ -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;

View file

@ -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"');