diff --git a/Classes/Validation/Validator/SettingsValidator.php b/Classes/Validation/Validator/SettingsValidator.php index af0e009..08a98d0 100644 --- a/Classes/Validation/Validator/SettingsValidator.php +++ b/Classes/Validation/Validator/SettingsValidator.php @@ -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']; } } } diff --git a/Configuration/Testing/Validation.yaml b/Configuration/Testing/Validation.yaml index 2ae4032..e61cfb0 100644 --- a/Configuration/Testing/Validation.yaml +++ b/Configuration/Testing/Validation.yaml @@ -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 diff --git a/Tests/Functional/Fixtures/TestValidationGroupsCustomObject.php b/Tests/Functional/Fixtures/TestValidationGroupsCustomObject.php index 78606ab..29df333 100644 --- a/Tests/Functional/Fixtures/TestValidationGroupsCustomObject.php +++ b/Tests/Functional/Fixtures/TestValidationGroupsCustomObject.php @@ -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; diff --git a/Tests/Functional/Fixtures/TestValidationGroupsDefaultObject.php b/Tests/Functional/Fixtures/TestValidationGroupsDefaultObject.php index 9afe2c1..4d4197c 100644 --- a/Tests/Functional/Fixtures/TestValidationGroupsDefaultObject.php +++ b/Tests/Functional/Fixtures/TestValidationGroupsDefaultObject.php @@ -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; diff --git a/Tests/Functional/SettingsValidatorTest.php b/Tests/Functional/SettingsValidatorTest.php index 2b5493f..1d2a285 100644 --- a/Tests/Functional/SettingsValidatorTest.php +++ b/Tests/Functional/SettingsValidatorTest.php @@ -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"');