From 9531b7af46c9b3931f50770728329ec1a7bb87bb Mon Sep 17 00:00:00 2001 From: Robin Krahnen Date: Sat, 4 Mar 2017 17:29:20 +0100 Subject: [PATCH 01/30] edit composer.json for feature/neos-flow4 --- composer.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 4143c8e..d94ec34 100644 --- a/composer.json +++ b/composer.json @@ -17,8 +17,7 @@ "validation" ], "require": { - "typo3/flow": "~2.0|~3.0", - "php": ">=5.3.0" + "neos/flow": "~4.0" }, "autoload": { "psr-0": { @@ -27,7 +26,8 @@ }, "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "1.0.x-dev", + "dev-feature/neos-flow4": "1.1.x-dev" }, "applied-flow-migrations": [ "Inwebs.Basket-201409170938", @@ -47,4 +47,4 @@ "TYPO3.Fluid-20150214130800" ] } -} \ No newline at end of file +} From baa35e09261674b47d1596b0eac63ad9d29840b7 Mon Sep 17 00:00:00 2001 From: Robin Krahnen Date: Mon, 13 Mar 2017 17:00:13 +0100 Subject: [PATCH 02/30] update project; fit neos/flow 4 --- Classes/DigiComp/SettingValidator/Package.php | 20 +++--- .../Validator/SettingsValidator.php | 72 ++++++++++--------- .../Private/Schema/Validation.schema.yaml | 6 +- composer.json | 5 +- 4 files changed, 55 insertions(+), 48 deletions(-) diff --git a/Classes/DigiComp/SettingValidator/Package.php b/Classes/DigiComp/SettingValidator/Package.php index b7e328c..c821e77 100644 --- a/Classes/DigiComp/SettingValidator/Package.php +++ b/Classes/DigiComp/SettingValidator/Package.php @@ -1,27 +1,27 @@ getSignalSlotDispatcher(); - $dispatcher->connect( - 'TYPO3\Flow\Configuration\ConfigurationManager', - 'configurationManagerReady', - function (ConfigurationManager $configurationManager) { + $dispatcher->connect(ConfigurationManager::class, 'configurationManagerReady', + function ($configurationManager) { + /** @var ConfigurationManager $configurationManager */ $configurationManager->registerConfigurationType( 'Validation', ConfigurationManager::CONFIGURATION_PROCESSING_TYPE_DEFAULT, diff --git a/Classes/DigiComp/SettingValidator/Validation/Validator/SettingsValidator.php b/Classes/DigiComp/SettingValidator/Validation/Validator/SettingsValidator.php index f29f969..7132f62 100644 --- a/Classes/DigiComp/SettingValidator/Validation/Validator/SettingsValidator.php +++ b/Classes/DigiComp/SettingValidator/Validation/Validator/SettingsValidator.php @@ -1,15 +1,15 @@ configurationManager = $configurationManager; - $this->validations = $this->configurationManager->getConfiguration('Validation'); - } - /** * @var ReflectionService * @Flow\Inject */ protected $reflectionService; - protected $supportedOptions = array( - 'name' => array('', 'Set the name of the setting-array to use', 'string', false) - ); + /** + * @var array + */ + protected $supportedOptions = [ + 'name' => ['', 'Set the name of the setting-array to use', 'string', false] + ]; + + /** + * @var array + */ + protected $validations; + + /** + * @param ConfigurationManager $configurationManager + */ + public function injectConfigurationManager(ConfigurationManager $configurationManager) + { + $this->configurationManager = $configurationManager; + $this->validations = $this->configurationManager->getConfiguration('Validation'); + } /** * Check if $value is valid. If it is not valid, needs to add an error @@ -62,33 +67,34 @@ class SettingsValidator extends AbstractValidator */ protected function isValid($value) { - $name = $this->options['name'] ? $this->options['name'] : $this->reflectionService->getClassNameByObject( - $value - ); - if (!isset($this->validations[$name])) { + $name = $this->options['name'] ? $this->options['name'] : TypeHandling::getTypeForValue($value); + if (! isset($this->validations[$name])) { throw new InvalidValidationOptionsException( 'The name ' . $name . ' has not been defined in Validation.yaml!', 1397821438 ); } + $config = &$this->validations[$name]; foreach ($config as $validatorConfig) { $validator = $this->validatorResolver->createValidator( $validatorConfig['validator'], $validatorConfig['options'] ); - if (!$validator) { + + if (! $validator) { throw new InvalidValidationConfigurationException( - 'Validator could not be resolved: ' . - $validatorConfig['validator'] . '. Check your Validation.yaml', + 'Validator could not be resolved: ' . $validatorConfig['validator'] . '. Check your Validation.yaml', 1402326139 ); } + if (isset($validatorConfig['property'])) { $this->result->forProperty($validatorConfig['property'])->merge( $validator->validate(ObjectAccess::getPropertyPath($value, $validatorConfig['property'])) ); - } else { + } + else { $this->result->merge($validator->validate($value)); } } diff --git a/Resources/Private/Schema/Validation.schema.yaml b/Resources/Private/Schema/Validation.schema.yaml index 088e51b..b917695 100644 --- a/Resources/Private/Schema/Validation.schema.yaml +++ b/Resources/Private/Schema/Validation.schema.yaml @@ -6,6 +6,6 @@ additionalProperties: additionalProperties: false # This validation sadly only hits the first level of validation, and options are not coverable with current validator properties: - validator: {type: string, required: TRUE} - options: {type: dictionary, required: TRUE} - property: {type: string, required: FALSE} + validator: {type: string, required: true} + options: {type: dictionary, required: true} + property: {type: string, required: false} diff --git a/composer.json b/composer.json index d94ec34..5328e01 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "digicomp/settingvalidator", - "type": "typo3-flow-package", - "description": "Just a TYPO3\\Flow Validator resolving other Validators with Configuration/Validation.yaml", + "type": "neos-package", + "description": "Just a Neos\\Flow Validator resolving other Validators with Configuration/Validation.yaml", "authors": [ { "name": "Ferdinand Kuhl", @@ -13,6 +13,7 @@ "license": "MIT", "homepage": "https://github.com/fcool/DigiComp.SettingValidator", "keywords": [ + "Neos", "Flow", "validation" ], From 5c44ad5579d7dfad2c22de573350087abf9cae0d Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Wed, 15 Mar 2017 09:06:44 +0100 Subject: [PATCH 03/30] TASK: Apply migration TYPO3.Flow-20151113161300 Adjust "Settings.yaml" to new "requestPattern" and "firewall" syntax (see FLOW-412) Note: This migration did not produce any changes, so the commit simply marks the migration as applied. This makes sure it will not be applied again. --- composer.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 5328e01..a15e070 100644 --- a/composer.json +++ b/composer.json @@ -45,7 +45,8 @@ "TYPO3.Fluid-20141113120800", "TYPO3.Flow-20141113121400", "TYPO3.Fluid-20141121091700", - "TYPO3.Fluid-20150214130800" + "TYPO3.Fluid-20150214130800", + "TYPO3.Flow-20151113161300" ] } -} +} \ No newline at end of file From 2b9b1febe9af69a54660b6dcbe423039bbb75bcd Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Wed, 15 Mar 2017 09:06:45 +0100 Subject: [PATCH 04/30] TASK: Apply migration TYPO3.Flow-20161115140400 Adjust to the renaming of the Resource namespace and class in Flow 4.0 Note: This migration did not produce any changes, so the commit simply marks the migration as applied. This makes sure it will not be applied again. --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a15e070..f855873 100644 --- a/composer.json +++ b/composer.json @@ -46,7 +46,8 @@ "TYPO3.Flow-20141113121400", "TYPO3.Fluid-20141121091700", "TYPO3.Fluid-20150214130800", - "TYPO3.Flow-20151113161300" + "TYPO3.Flow-20151113161300", + "TYPO3.Flow-20161115140400" ] } } \ No newline at end of file From 0e7d19b3cd14732c637b5f26dea767a6fdad1448 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Wed, 15 Mar 2017 09:06:45 +0100 Subject: [PATCH 05/30] TASK: Apply migration TYPO3.Flow-20161115140430 Adjust to the renaming of the Object namespace in Flow 4.0 Note: This migration did not produce any changes, so the commit simply marks the migration as applied. This makes sure it will not be applied again. --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f855873..e8753e2 100644 --- a/composer.json +++ b/composer.json @@ -47,7 +47,8 @@ "TYPO3.Fluid-20141121091700", "TYPO3.Fluid-20150214130800", "TYPO3.Flow-20151113161300", - "TYPO3.Flow-20161115140400" + "TYPO3.Flow-20161115140400", + "TYPO3.Flow-20161115140430" ] } } \ No newline at end of file From 85174f74892589fd3e2a9892276f3bfc5d2fd736 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Wed, 15 Mar 2017 09:06:45 +0100 Subject: [PATCH 06/30] TASK: Apply migration Neos.Flow-20161124204700 Adjusts code to package renaming from "TYPO3.Flow" to "Neos.Flow" Note: This migration did not produce any changes, so the commit simply marks the migration as applied. This makes sure it will not be applied again. --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e8753e2..e8ecaae 100644 --- a/composer.json +++ b/composer.json @@ -48,7 +48,8 @@ "TYPO3.Fluid-20150214130800", "TYPO3.Flow-20151113161300", "TYPO3.Flow-20161115140400", - "TYPO3.Flow-20161115140430" + "TYPO3.Flow-20161115140430", + "Neos.Flow-20161124204700" ] } } \ No newline at end of file From e36874e26d7e873dba19814d144a41b1e9c31504 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Wed, 15 Mar 2017 09:06:45 +0100 Subject: [PATCH 07/30] TASK: Apply migration Neos.Flow-20161124204701 Adjusts code to package renaming from "Neos.Flow.Utility.Files" to "Neos.Utility.Files" and other extractions of the "Utility" packages. Note: This migration did not produce any changes, so the commit simply marks the migration as applied. This makes sure it will not be applied again. --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e8ecaae..bea002a 100644 --- a/composer.json +++ b/composer.json @@ -49,7 +49,8 @@ "TYPO3.Flow-20151113161300", "TYPO3.Flow-20161115140400", "TYPO3.Flow-20161115140430", - "Neos.Flow-20161124204700" + "Neos.Flow-20161124204700", + "Neos.Flow-20161124204701" ] } } \ No newline at end of file From 2fc3edd6c0ee7e6ad4b6831d7a2e64f269824160 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Wed, 15 Mar 2017 09:06:45 +0100 Subject: [PATCH 08/30] TASK: Apply migration Neos.Flow-20161124224015 Adjusts code to cache extraction Note: This migration did not produce any changes, so the commit simply marks the migration as applied. This makes sure it will not be applied again. --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index bea002a..f9f067d 100644 --- a/composer.json +++ b/composer.json @@ -50,7 +50,8 @@ "TYPO3.Flow-20161115140400", "TYPO3.Flow-20161115140430", "Neos.Flow-20161124204700", - "Neos.Flow-20161124204701" + "Neos.Flow-20161124204701", + "Neos.Flow-20161124224015" ] } } \ No newline at end of file From 365ed39776541e2cb019324c362577df05717bb4 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Wed, 15 Mar 2017 09:06:45 +0100 Subject: [PATCH 09/30] TASK: Apply migration Neos.Eel-20161124230101 Adjusts code to Eel Renaming Note: This migration did not produce any changes, so the commit simply marks the migration as applied. This makes sure it will not be applied again. --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f9f067d..c8b2635 100644 --- a/composer.json +++ b/composer.json @@ -51,7 +51,8 @@ "TYPO3.Flow-20161115140430", "Neos.Flow-20161124204700", "Neos.Flow-20161124204701", - "Neos.Flow-20161124224015" + "Neos.Flow-20161124224015", + "Neos.Eel-20161124230101" ] } } \ No newline at end of file From 22e060163f372bc0e1960845b1a4e5812b26e916 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Wed, 15 Mar 2017 09:06:45 +0100 Subject: [PATCH 10/30] TASK: Apply migration Neos.Imagine-20161124231742 Adjusts code to Imagine Renaming Note: This migration did not produce any changes, so the commit simply marks the migration as applied. This makes sure it will not be applied again. --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c8b2635..9e75f8f 100644 --- a/composer.json +++ b/composer.json @@ -52,7 +52,8 @@ "Neos.Flow-20161124204700", "Neos.Flow-20161124204701", "Neos.Flow-20161124224015", - "Neos.Eel-20161124230101" + "Neos.Eel-20161124230101", + "Neos.Imagine-20161124231742" ] } } \ No newline at end of file From 5120239c126904741fe9236b3467f9f3b92d78f6 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Wed, 15 Mar 2017 09:06:45 +0100 Subject: [PATCH 11/30] TASK: Apply migration Neos.Media-20161124233100 Adjusts code to package renaming from "TYPO3.Media" to "Neos.Media" Note: This migration did not produce any changes, so the commit simply marks the migration as applied. This makes sure it will not be applied again. --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9e75f8f..9602db3 100644 --- a/composer.json +++ b/composer.json @@ -53,7 +53,8 @@ "Neos.Flow-20161124204701", "Neos.Flow-20161124224015", "Neos.Eel-20161124230101", - "Neos.Imagine-20161124231742" + "Neos.Imagine-20161124231742", + "Neos.Media-20161124233100" ] } } \ No newline at end of file From 6855634a8049a255550e4cb3361b19210d239a15 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Wed, 15 Mar 2017 09:06:45 +0100 Subject: [PATCH 12/30] TASK: Apply migration Neos.Flow-20161125124112 Adjusts code to Neos\Flow\Utility\Unicode adjustment Note: This migration did not produce any changes, so the commit simply marks the migration as applied. This makes sure it will not be applied again. --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9602db3..ab6fbb6 100644 --- a/composer.json +++ b/composer.json @@ -54,7 +54,8 @@ "Neos.Flow-20161124224015", "Neos.Eel-20161124230101", "Neos.Imagine-20161124231742", - "Neos.Media-20161124233100" + "Neos.Media-20161124233100", + "Neos.Flow-20161125124112" ] } } \ No newline at end of file From 9e980e40e1efb5f42157f38c321a50e40fa34680 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Wed, 15 Mar 2017 09:06:45 +0100 Subject: [PATCH 13/30] TASK: Apply migration Neos.SwiftMailer-20161130105617 Adjusts code to package renaming from "TYPO3.SwiftMailer" to "Neos.SwiftMailer". Note: This migration did not produce any changes, so the commit simply marks the migration as applied. This makes sure it will not be applied again. --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ab6fbb6..e33d6dc 100644 --- a/composer.json +++ b/composer.json @@ -55,7 +55,8 @@ "Neos.Eel-20161124230101", "Neos.Imagine-20161124231742", "Neos.Media-20161124233100", - "Neos.Flow-20161125124112" + "Neos.Flow-20161125124112", + "Neos.SwiftMailer-20161130105617" ] } } \ No newline at end of file From d24fefeda497938fdcbb5a2c8757e84a3c53ea74 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Wed, 15 Mar 2017 09:06:45 +0100 Subject: [PATCH 14/30] TASK: Apply migration TYPO3.FluidAdaptor-20161130112935 Adjusts code to package renaming from "TYPO3.Fluid" to "Neos.FluidAdaptor". Note: This migration did not produce any changes, so the commit simply marks the migration as applied. This makes sure it will not be applied again. --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e33d6dc..ed614f6 100644 --- a/composer.json +++ b/composer.json @@ -56,7 +56,8 @@ "Neos.Imagine-20161124231742", "Neos.Media-20161124233100", "Neos.Flow-20161125124112", - "Neos.SwiftMailer-20161130105617" + "Neos.SwiftMailer-20161130105617", + "TYPO3.FluidAdaptor-20161130112935" ] } } \ No newline at end of file From 55352da4d695ed205d7acbad450a6ec88d2d014b Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Wed, 15 Mar 2017 09:06:45 +0100 Subject: [PATCH 15/30] TASK: Apply migration Neos.Media-20161219094126 Migrate name for the media image size cache Note: This migration did not produce any changes, so the commit simply marks the migration as applied. This makes sure it will not be applied again. --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ed614f6..67e0a5f 100644 --- a/composer.json +++ b/composer.json @@ -57,7 +57,8 @@ "Neos.Media-20161124233100", "Neos.Flow-20161125124112", "Neos.SwiftMailer-20161130105617", - "TYPO3.FluidAdaptor-20161130112935" + "TYPO3.FluidAdaptor-20161130112935", + "Neos.Media-20161219094126" ] } } \ No newline at end of file From 610a89bfaf70f832d808c055544519e5dd9371e6 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Wed, 15 Mar 2017 09:06:45 +0100 Subject: [PATCH 16/30] TASK: Apply migration Neos.Flow-20170125103800 Migrate usages of the path [TYPO3][Flow][Security][Authentication] to [Neos][Flow][Security][Authentication] Note: This migration did not produce any changes, so the commit simply marks the migration as applied. This makes sure it will not be applied again. --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 67e0a5f..af6b7cf 100644 --- a/composer.json +++ b/composer.json @@ -58,7 +58,8 @@ "Neos.Flow-20161125124112", "Neos.SwiftMailer-20161130105617", "TYPO3.FluidAdaptor-20161130112935", - "Neos.Media-20161219094126" + "Neos.Media-20161219094126", + "Neos.Flow-20170125103800" ] } } \ No newline at end of file From 30adb0f7ccf3097d4f7f76f1689cf1aa05cfcdb5 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Wed, 15 Mar 2017 09:06:45 +0100 Subject: [PATCH 17/30] TASK: Apply migration Neos.Flow-20170127183102 Migrate bootstep names. Note: This migration did not produce any changes, so the commit simply marks the migration as applied. This makes sure it will not be applied again. --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index af6b7cf..667a99e 100644 --- a/composer.json +++ b/composer.json @@ -59,7 +59,8 @@ "Neos.SwiftMailer-20161130105617", "TYPO3.FluidAdaptor-20161130112935", "Neos.Media-20161219094126", - "Neos.Flow-20170125103800" + "Neos.Flow-20170125103800", + "Neos.Flow-20170127183102" ] } } \ No newline at end of file From 5c2a5babdd2e50276a3da2da5537bfa76025c567 Mon Sep 17 00:00:00 2001 From: Ferdinand Kuhl Date: Mon, 3 Apr 2017 17:05:47 +0200 Subject: [PATCH 18/30] TASK: Updating dependencies --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 667a99e..e311061 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "extra": { "branch-alias": { "dev-master": "1.0.x-dev", - "dev-feature/neos-flow4": "1.1.x-dev" + "dev-feature/neos-flow4": "2.0.x-dev" }, "applied-flow-migrations": [ "Inwebs.Basket-201409170938", From 8dfb72c23063350bea129bc21fe1f9730a74baa5 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Wed, 24 May 2017 14:02:27 +0200 Subject: [PATCH 19/30] TASK: Raise flow version constraint --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index e311061..f8551f2 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "validation" ], "require": { - "neos/flow": "~4.0" + "neos/flow": "~4.1" }, "autoload": { "psr-0": { @@ -63,4 +63,4 @@ "Neos.Flow-20170127183102" ] } -} \ No newline at end of file +} From 93fa97e81773d3e5c06548a43bf6d238b80cdb79 Mon Sep 17 00:00:00 2001 From: Ferdinand Kuhl Date: Fri, 2 Jun 2017 21:18:27 +0200 Subject: [PATCH 20/30] TASK: Migrate to PSR-4 --- Classes/{DigiComp/SettingValidator => }/Package.php | 0 .../Validation/Validator/SettingsValidator.php | 3 +-- composer.json | 4 ++-- 3 files changed, 3 insertions(+), 4 deletions(-) rename Classes/{DigiComp/SettingValidator => }/Package.php (100%) rename Classes/{DigiComp/SettingValidator => }/Validation/Validator/SettingsValidator.php (98%) diff --git a/Classes/DigiComp/SettingValidator/Package.php b/Classes/Package.php similarity index 100% rename from Classes/DigiComp/SettingValidator/Package.php rename to Classes/Package.php diff --git a/Classes/DigiComp/SettingValidator/Validation/Validator/SettingsValidator.php b/Classes/Validation/Validator/SettingsValidator.php similarity index 98% rename from Classes/DigiComp/SettingValidator/Validation/Validator/SettingsValidator.php rename to Classes/Validation/Validator/SettingsValidator.php index 7132f62..112bdc4 100644 --- a/Classes/DigiComp/SettingValidator/Validation/Validator/SettingsValidator.php +++ b/Classes/Validation/Validator/SettingsValidator.php @@ -93,8 +93,7 @@ class SettingsValidator extends AbstractValidator $this->result->forProperty($validatorConfig['property'])->merge( $validator->validate(ObjectAccess::getPropertyPath($value, $validatorConfig['property'])) ); - } - else { + } else { $this->result->merge($validator->validate($value)); } } diff --git a/composer.json b/composer.json index f8551f2..20f8488 100644 --- a/composer.json +++ b/composer.json @@ -21,8 +21,8 @@ "neos/flow": "~4.1" }, "autoload": { - "psr-0": { - "DigiComp\\SettingValidator": "Classes" + "psr-4": { + "DigiComp\\SettingValidator\\": "Classes" } }, "extra": { From 40fc82e515cc752d01e06c44a9d64d4c24ce3712 Mon Sep 17 00:00:00 2001 From: Ferdinand Kuhl Date: Fri, 2 Jun 2017 21:58:33 +0200 Subject: [PATCH 21/30] TASK: Add basic functional tests --- Configuration/Testing/Validation.yaml | 18 +++++++++ Tests/Functional/Fixtures/TestObject.php | 47 ++++++++++++++++++++++ Tests/Functional/SettingsValidatorTest.php | 34 ++++++++++++++++ composer.json | 5 +++ 4 files changed, 104 insertions(+) create mode 100644 Configuration/Testing/Validation.yaml create mode 100644 Tests/Functional/Fixtures/TestObject.php create mode 100644 Tests/Functional/SettingsValidatorTest.php diff --git a/Configuration/Testing/Validation.yaml b/Configuration/Testing/Validation.yaml new file mode 100644 index 0000000..f9575d2 --- /dev/null +++ b/Configuration/Testing/Validation.yaml @@ -0,0 +1,18 @@ +DigiComp\SettingValidator\Tests\Functional\Fixtures\TestObject: + - + property: shouldBeTrue + validator: BooleanValue + options: + expectedValue: true + - + property: shouldBeFalse + validator: BooleanValue + options: + expectedValue: false + + +TrueValidator: + - + validator: BooleanValue + options: + expectedValue: true \ No newline at end of file diff --git a/Tests/Functional/Fixtures/TestObject.php b/Tests/Functional/Fixtures/TestObject.php new file mode 100644 index 0000000..ddd62c5 --- /dev/null +++ b/Tests/Functional/Fixtures/TestObject.php @@ -0,0 +1,47 @@ +shouldBeTrue; + } + + /** + * @return bool + */ + public function isShouldBeFalse(): bool + { + return $this->shouldBeFalse; + } + + /** + * @return bool + */ + public function isShouldBeTrueAndValidatedByAnnotation(): bool + { + return $this->shouldBeTrueAndValidatedByAnnotation; + } +} diff --git a/Tests/Functional/SettingsValidatorTest.php b/Tests/Functional/SettingsValidatorTest.php new file mode 100644 index 0000000..8feae6d --- /dev/null +++ b/Tests/Functional/SettingsValidatorTest.php @@ -0,0 +1,34 @@ +objectManager->get(SettingsValidator::class); + $result = $validator->validate(new TestObject()); + $this->assertTrue($result->hasErrors()); + $this->assertCount(1, $result->getFlattenedErrors()); + $this->assertCount(1, $result->forProperty('shouldBeFalse')->getErrors()); + } + + /** + * @test + */ + public function conjunctionValidationWorksAsExpected() + { + $validatorResolver = $this->objectManager->get(ValidatorResolver::class); + $validator = $validatorResolver->getBaseValidatorConjunction(TestObject::class); + $result = $validator->validate(new TestObject()); + $this->assertTrue($result->hasErrors()); + $this->assertCount(1, $result->getFlattenedErrors()); + } +} diff --git a/composer.json b/composer.json index 20f8488..a3cd64d 100644 --- a/composer.json +++ b/composer.json @@ -25,6 +25,11 @@ "DigiComp\\SettingValidator\\": "Classes" } }, + "autoload-dev": { + "psr-4": { + "DigiComp\\SettingValidator\\Tests\\": "Tests" + } + }, "extra": { "branch-alias": { "dev-master": "1.0.x-dev", From 9a055a2f7744d8cd17fdf9269b7a1edb2338813d Mon Sep 17 00:00:00 2001 From: Ferdinand Kuhl Date: Fri, 2 Jun 2017 23:14:05 +0200 Subject: [PATCH 22/30] TASK: Completely changing the layout of Validation.yaml --- .../Validator/SettingsValidator.php | 26 ++++++++++++++++++- Configuration/Testing/Validation.yaml | 26 ++++++++----------- .../Private/Schema/Validation.schema.yaml | 12 ++++----- 3 files changed, 42 insertions(+), 22 deletions(-) diff --git a/Classes/Validation/Validator/SettingsValidator.php b/Classes/Validation/Validator/SettingsValidator.php index 112bdc4..c94efff 100644 --- a/Classes/Validation/Validator/SettingsValidator.php +++ b/Classes/Validation/Validator/SettingsValidator.php @@ -75,7 +75,31 @@ class SettingsValidator extends AbstractValidator ); } - $config = &$this->validations[$name]; + $config = []; + if (isset($this->validations[$name]['self'])) { + foreach ($this->validations[$name]['self'] as $validator => &$validation) { + if (is_null($validation)) { + continue; + } + $newValidation['options'] = $validation; + $newValidation['validator'] = $validator; + $config[] = $newValidation; + } + } + if (isset($this->validations[$name]['properties'])) { + foreach ($this->validations[$name]['properties'] as $propertyName => &$validation) { + foreach ($validation as $validator => &$options) { + if (is_null($options)) { + continue; + } + $newValidation['property'] = $propertyName; + $newValidation['validator'] = $validator; + $newValidation['options'] = $options; + $config[] = $newValidation; + } + } + } + foreach ($config as $validatorConfig) { $validator = $this->validatorResolver->createValidator( $validatorConfig['validator'], diff --git a/Configuration/Testing/Validation.yaml b/Configuration/Testing/Validation.yaml index f9575d2..bc17503 100644 --- a/Configuration/Testing/Validation.yaml +++ b/Configuration/Testing/Validation.yaml @@ -1,18 +1,14 @@ DigiComp\SettingValidator\Tests\Functional\Fixtures\TestObject: - - - property: shouldBeTrue - validator: BooleanValue - options: - expectedValue: true - - - property: shouldBeFalse - validator: BooleanValue - options: - expectedValue: false - + properties: + shouldBeTrue: + BooleanValue: + expectedValue: true + shouldBeFalse: + BooleanValue: + expectedValue: false + Grumble: ~ TrueValidator: - - - validator: BooleanValue - options: - expectedValue: true \ No newline at end of file + self: + BooleanValue: + expectedValue: true diff --git a/Resources/Private/Schema/Validation.schema.yaml b/Resources/Private/Schema/Validation.schema.yaml index b917695..3f96d9d 100644 --- a/Resources/Private/Schema/Validation.schema.yaml +++ b/Resources/Private/Schema/Validation.schema.yaml @@ -1,11 +1,11 @@ type: dictionary additionalProperties: - type: array - items: + type: dictionary + additionalProperties: false + properties: type: dictionary additionalProperties: false - # This validation sadly only hits the first level of validation, and options are not coverable with current validator properties: - validator: {type: string, required: true} - options: {type: dictionary, required: true} - property: {type: string, required: false} + type: dictionary + self: + type: dictionary From 4534099d3a196cbb9083d4cf4317057b4928dfa2 Mon Sep 17 00:00:00 2001 From: Ferdinand Kuhl Date: Sat, 3 Jun 2017 12:56:14 +0200 Subject: [PATCH 23/30] TASK: Added code migration for Validation.yaml structure --- Classes/Package.php | 17 +++++- .../Validator/SettingsValidator.php | 10 ++++ Migrations/Code/Version20170603120900.php | 55 +++++++++++++++++++ composer.json | 5 +- 4 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 Migrations/Code/Version20170603120900.php diff --git a/Classes/Package.php b/Classes/Package.php index c821e77..06276a7 100644 --- a/Classes/Package.php +++ b/Classes/Package.php @@ -1,16 +1,27 @@ registerConfigurationType( - 'Validation', + static::CONFIGURATION_TYPE_VALIDATION, ConfigurationManager::CONFIGURATION_PROCESSING_TYPE_DEFAULT, true ); diff --git a/Classes/Validation/Validator/SettingsValidator.php b/Classes/Validation/Validator/SettingsValidator.php index c94efff..4a87bd9 100644 --- a/Classes/Validation/Validator/SettingsValidator.php +++ b/Classes/Validation/Validator/SettingsValidator.php @@ -1,6 +1,16 @@ processConfiguration(Package::CONFIGURATION_TYPE_VALIDATION, + function (&$configuration) { + foreach ($configuration as $validatorName => &$validators) { + $newConfiguration = ['properties' => [], 'self' => []]; + + foreach ($validators as $key => &$validator) { + if (!isset($validator['validator']) || !isset($validator['options'])) { + $this->showWarning('The Validation.yaml files contained no validator or options for ' . + 'validation: "' . $validatorName . '.' . $key . '". It was not be migrated.'); + continue; + } + if (isset($validator['property'])) { + $newConfiguration['properties'][$validator['property']][$validator['validator']] + = $validator['options']; + } else { + $newConfiguration['self'][$validator['validator']] = $validator['options']; + } + } + $validators = $newConfiguration; + } + }, + true + ); + } +} diff --git a/composer.json b/composer.json index a3cd64d..65020c7 100644 --- a/composer.json +++ b/composer.json @@ -65,7 +65,8 @@ "TYPO3.FluidAdaptor-20161130112935", "Neos.Media-20161219094126", "Neos.Flow-20170125103800", - "Neos.Flow-20170127183102" + "Neos.Flow-20170127183102", + "DigiComp.SettingValidator-20170603120900" ] } -} +} \ No newline at end of file From d83c009b28108adff94696cc252162d962b594f4 Mon Sep 17 00:00:00 2001 From: Ferdinand Kuhl Date: Sat, 3 Jun 2017 14:11:13 +0200 Subject: [PATCH 24/30] TASK: taming complexity --- .../Validator/SettingsValidator.php | 58 ++++++++++++------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/Classes/Validation/Validator/SettingsValidator.php b/Classes/Validation/Validator/SettingsValidator.php index 4a87bd9..c10655f 100644 --- a/Classes/Validation/Validator/SettingsValidator.php +++ b/Classes/Validation/Validator/SettingsValidator.php @@ -85,6 +85,41 @@ class SettingsValidator extends AbstractValidator ); } + $config = $this->getConfigForName($name); + + foreach ($config as $validatorConfig) { + $validator = $this->validatorResolver->createValidator( + $validatorConfig['validator'], + $validatorConfig['options'] + ); + + if (! $validator) { + throw new InvalidValidationConfigurationException( + sprintf( + 'Validator could not be resolved: "%s" Check your Validation.yaml', + $validatorConfig['validator'] + ), + 1402326139 + ); + } + + if (isset($validatorConfig['property'])) { + $this->result->forProperty($validatorConfig['property'])->merge( + $validator->validate(ObjectAccess::getPropertyPath($value, $validatorConfig['property'])) + ); + } else { + $this->result->merge($validator->validate($value)); + } + } + } + + /** + * @param $name + * + * @return array + */ + protected function getConfigForName($name): array + { $config = []; if (isset($this->validations[$name]['self'])) { foreach ($this->validations[$name]['self'] as $validator => &$validation) { @@ -109,27 +144,6 @@ class SettingsValidator extends AbstractValidator } } } - - foreach ($config as $validatorConfig) { - $validator = $this->validatorResolver->createValidator( - $validatorConfig['validator'], - $validatorConfig['options'] - ); - - if (! $validator) { - throw new InvalidValidationConfigurationException( - 'Validator could not be resolved: ' . $validatorConfig['validator'] . '. Check your Validation.yaml', - 1402326139 - ); - } - - if (isset($validatorConfig['property'])) { - $this->result->forProperty($validatorConfig['property'])->merge( - $validator->validate(ObjectAccess::getPropertyPath($value, $validatorConfig['property'])) - ); - } else { - $this->result->merge($validator->validate($value)); - } - } + return $config; } } From e5b5f081535ba71b7172359d2c518a8f730e8f3a Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Wed, 21 Jun 2017 11:26:13 +0200 Subject: [PATCH 25/30] FEATURE: Support validation groups as done by flow itself. * Provide another option validationGroups. * Allow each validation entry to be executed only for matching validation groups. * Necessary for the same reason as documented in flow documentation. It should be possible to execute different validation rules for the same name or class, only at some points, e.g. at a specific action. --- .../Validator/SettingsValidator.php | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/Classes/Validation/Validator/SettingsValidator.php b/Classes/Validation/Validator/SettingsValidator.php index 112bdc4..40825a9 100644 --- a/Classes/Validation/Validator/SettingsValidator.php +++ b/Classes/Validation/Validator/SettingsValidator.php @@ -39,7 +39,8 @@ class SettingsValidator extends AbstractValidator * @var array */ protected $supportedOptions = [ - 'name' => ['', 'Set the name of the setting-array to use', 'string', false] + 'name' => ['', 'Set the name of the setting-array to use', 'string', false], + 'validationGroups' => [['Default'], 'Same as "Validation Groups" of Flow Framework.', 'array', false], ]; /** @@ -77,6 +78,12 @@ class SettingsValidator extends AbstractValidator $config = &$this->validations[$name]; foreach ($config as $validatorConfig) { + if (! $this->doesValidationGroupsMatch($validatorConfig)) { + continue; + } + + $this->handleValidationGroups($validatorConfig); + $validator = $this->validatorResolver->createValidator( $validatorConfig['validator'], $validatorConfig['options'] @@ -98,4 +105,33 @@ class SettingsValidator extends AbstractValidator } } } + + /** + * Check whether at least one configured group does match, if any is configured. + * + * @param array $validatorConfig + * @return bool + */ + protected function doesValidationGroupsMatch(array &$validatorConfig) + { + if (isset($validatorConfig['validationGroups']) + && count(array_intersect($validatorConfig['validationGroups'], $this->options['validationGroups'])) === 0 + ) { + return false; + } + + return true; + } + + /** + * Add validation groups for recursion if necessary. + * + * @param array $validatorConfig + */ + protected function handleValidationGroups(array &$validatorConfig) + { + if ($validatorConfig['validator'] === 'DigiComp.SettingValidator:Settings' && empty($validatorConfig['options']['validationGroups'])) { + $validatorConfig['options']['validationGroups'] = $this->options['validationGroups']; + } + } } From eccc2b1bdd0528e4138e9c8b5e0dfacff78983ca Mon Sep 17 00:00:00 2001 From: Ferdinand Kuhl Date: Thu, 29 Jun 2017 21:34:20 +0200 Subject: [PATCH 26/30] MERGE: Bringing the ValidationGroup feature back to work. - ugly: they get extracted from options, as I do not see any other possibility --- Classes/Validation/Validator/SettingsValidator.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Classes/Validation/Validator/SettingsValidator.php b/Classes/Validation/Validator/SettingsValidator.php index 9ba1929..3752ed7 100644 --- a/Classes/Validation/Validator/SettingsValidator.php +++ b/Classes/Validation/Validator/SettingsValidator.php @@ -133,6 +133,7 @@ class SettingsValidator extends AbstractValidator if (is_null($validation)) { continue; } + $this->extractValidationGroupsFromOptions($newValidation); $newValidation['options'] = $validation; $newValidation['validator'] = $validator; $config[] = $newValidation; @@ -144,6 +145,7 @@ class SettingsValidator extends AbstractValidator if (is_null($options)) { continue; } + $this->extractValidationGroupsFromOptions($options); $newValidation['property'] = $propertyName; $newValidation['validator'] = $validator; $newValidation['options'] = $options; @@ -182,4 +184,15 @@ class SettingsValidator extends AbstractValidator $validatorConfig['options']['validationGroups'] = $this->options['validationGroups']; } } + + /** + * @param $newValidation + */ + protected function extractValidationGroupsFromOptions(&$newValidation) + { + if (isset($newValidation['options']['validationGroups'])) { + $newValidation['validationGroups'] = $newValidation['options']['validationGroups']; + unset($newValidation['options']['validationGroups']); + } + } } From 3da68c2e490e71edd206bb491ee8bb73b89eb490 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Mon, 3 Jul 2017 10:11:18 +0200 Subject: [PATCH 27/30] TASK: Fix ValidationGroups Fix handling of validation groups. Also added test to cover the feature. --- .../Validator/SettingsValidator.php | 21 +++-------- Configuration/Testing/Validation.yaml | 14 ++++++++ .../TestValidationGroupsCustomObject.php | 35 +++++++++++++++++++ .../TestValidationGroupsDefaultObject.php | 35 +++++++++++++++++++ Tests/Functional/SettingsValidatorTest.php | 22 ++++++++++++ 5 files changed, 110 insertions(+), 17 deletions(-) create mode 100644 Tests/Functional/Fixtures/TestValidationGroupsCustomObject.php create mode 100644 Tests/Functional/Fixtures/TestValidationGroupsDefaultObject.php diff --git a/Classes/Validation/Validator/SettingsValidator.php b/Classes/Validation/Validator/SettingsValidator.php index 3752ed7..3f1bb0d 100644 --- a/Classes/Validation/Validator/SettingsValidator.php +++ b/Classes/Validation/Validator/SettingsValidator.php @@ -133,7 +133,6 @@ class SettingsValidator extends AbstractValidator if (is_null($validation)) { continue; } - $this->extractValidationGroupsFromOptions($newValidation); $newValidation['options'] = $validation; $newValidation['validator'] = $validator; $config[] = $newValidation; @@ -145,7 +144,6 @@ class SettingsValidator extends AbstractValidator if (is_null($options)) { continue; } - $this->extractValidationGroupsFromOptions($options); $newValidation['property'] = $propertyName; $newValidation['validator'] = $validator; $newValidation['options'] = $options; @@ -164,8 +162,8 @@ class SettingsValidator extends AbstractValidator */ protected function doesValidationGroupsMatch(array &$validatorConfig) { - if (isset($validatorConfig['validationGroups']) - && count(array_intersect($validatorConfig['validationGroups'], $this->options['validationGroups'])) === 0 + if (isset($validatorConfig['options']['validationGroups']) + && count(array_intersect($validatorConfig['options']['validationGroups'], $this->options['validationGroups'])) === 0 ) { return false; } @@ -180,19 +178,8 @@ class SettingsValidator extends AbstractValidator */ protected function handleValidationGroups(array &$validatorConfig) { - if ($validatorConfig['validator'] === 'DigiComp.SettingValidator:Settings' && empty($validatorConfig['options']['validationGroups'])) { - $validatorConfig['options']['validationGroups'] = $this->options['validationGroups']; - } - } - - /** - * @param $newValidation - */ - protected function extractValidationGroupsFromOptions(&$newValidation) - { - if (isset($newValidation['options']['validationGroups'])) { - $newValidation['validationGroups'] = $newValidation['options']['validationGroups']; - unset($newValidation['options']['validationGroups']); + if ($validatorConfig['validator'] !== 'DigiComp.SettingValidator:Settings' || empty($validatorConfig['options']['validationGroups'])) { + unset($validatorConfig['options']['validationGroups']); } } } diff --git a/Configuration/Testing/Validation.yaml b/Configuration/Testing/Validation.yaml index bc17503..2ae4032 100644 --- a/Configuration/Testing/Validation.yaml +++ b/Configuration/Testing/Validation.yaml @@ -12,3 +12,17 @@ TrueValidator: self: BooleanValue: expectedValue: true + +GroupValidatorDefault: + self: + BooleanValue: + expectedValue: true + validationGroups: + - Default +GroupValidatorCustom: + self: + BooleanValue: + expectedValue: false + validationGroups: + - Custom + diff --git a/Tests/Functional/Fixtures/TestValidationGroupsCustomObject.php b/Tests/Functional/Fixtures/TestValidationGroupsCustomObject.php new file mode 100644 index 0000000..78606ab --- /dev/null +++ b/Tests/Functional/Fixtures/TestValidationGroupsCustomObject.php @@ -0,0 +1,35 @@ +shouldBeTrue; + } + + /** + * @return bool + */ + public function isShouldBeFalse(): bool + { + return $this->shouldBeFalse; + } +} diff --git a/Tests/Functional/Fixtures/TestValidationGroupsDefaultObject.php b/Tests/Functional/Fixtures/TestValidationGroupsDefaultObject.php new file mode 100644 index 0000000..9afe2c1 --- /dev/null +++ b/Tests/Functional/Fixtures/TestValidationGroupsDefaultObject.php @@ -0,0 +1,35 @@ +shouldBeTrue; + } + + /** + * @return bool + */ + public function isShouldBeFalse(): bool + { + return $this->shouldBeFalse; + } +} diff --git a/Tests/Functional/SettingsValidatorTest.php b/Tests/Functional/SettingsValidatorTest.php index 8feae6d..2b5493f 100644 --- a/Tests/Functional/SettingsValidatorTest.php +++ b/Tests/Functional/SettingsValidatorTest.php @@ -2,6 +2,8 @@ namespace DigiComp\SettingValidator\Tests\Functional; use DigiComp\SettingValidator\Tests\Functional\Fixtures\TestObject; +use DigiComp\SettingValidator\Tests\Functional\Fixtures\TestValidationGroupsCustomObject; +use DigiComp\SettingValidator\Tests\Functional\Fixtures\TestValidationGroupsDefaultObject; use DigiComp\SettingValidator\Validation\Validator\SettingsValidator; use Neos\Flow\Tests\FunctionalTestCase; use Neos\Flow\Validation\ValidatorResolver; @@ -31,4 +33,24 @@ class SettingsValidatorTest extends FunctionalTestCase $this->assertTrue($result->hasErrors()); $this->assertCount(1, $result->getFlattenedErrors()); } + + /** + * @test + */ + public function validationGroupsAreRespected() + { + $validatorResolver = $this->objectManager->get(ValidatorResolver::class); + + $validator = $validatorResolver->getBaseValidatorConjunction(TestValidationGroupsDefaultObject::class); + $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); + $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"'); + $this->assertCount(1, $result->forProperty('shouldBeFalse')->getErrors(), 'Got no error for shouldBeFalse property'); + } } From 5c927e9ddaf7cecb11efb0666e953e0be94d55b5 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Wed, 19 Jul 2017 10:31:01 +0200 Subject: [PATCH 28/30] BUGFIX: Only unset array key if it exists --- Classes/Validation/Validator/SettingsValidator.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Classes/Validation/Validator/SettingsValidator.php b/Classes/Validation/Validator/SettingsValidator.php index 3f1bb0d..af0e009 100644 --- a/Classes/Validation/Validator/SettingsValidator.php +++ b/Classes/Validation/Validator/SettingsValidator.php @@ -178,7 +178,12 @@ class SettingsValidator extends AbstractValidator */ protected function handleValidationGroups(array &$validatorConfig) { - if ($validatorConfig['validator'] !== 'DigiComp.SettingValidator:Settings' || empty($validatorConfig['options']['validationGroups'])) { + if (isset($validatorConfig['options']['validationGroups']) + && ( + $validatorConfig['validator'] !== 'DigiComp.SettingValidator:Settings' + || empty($validatorConfig['options']['validationGroups']) + ) + ) { unset($validatorConfig['options']['validationGroups']); } } From 2b41d5f3db31d475e80e42a4535864c419c19fdc Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Wed, 19 Jul 2017 12:54:29 +0200 Subject: [PATCH 29/30] BUGFIX: Fix broken recursion with validation groups Provide current validation group for recursive SettingsValidator. Adjust test. Provide configuration to outline the issue. --- .../Validator/SettingsValidator.php | 7 ++-- Configuration/Testing/Validation.yaml | 32 ++++++++++++------- .../TestValidationGroupsCustomObject.php | 2 -- .../TestValidationGroupsDefaultObject.php | 2 -- Tests/Functional/SettingsValidatorTest.php | 14 +++++--- 5 files changed, 33 insertions(+), 24 deletions(-) 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"'); From a31595513f6a840e34c10690d2b803620fc61bb7 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Wed, 19 Jul 2017 12:55:31 +0200 Subject: [PATCH 30/30] TASK: Reformat to follow CGL --- Classes/Validation/Validator/SettingsValidator.php | 7 ++++++- Tests/Functional/SettingsValidatorTest.php | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Classes/Validation/Validator/SettingsValidator.php b/Classes/Validation/Validator/SettingsValidator.php index 08a98d0..1db1d4c 100644 --- a/Classes/Validation/Validator/SettingsValidator.php +++ b/Classes/Validation/Validator/SettingsValidator.php @@ -50,7 +50,12 @@ class SettingsValidator extends AbstractValidator */ protected $supportedOptions = [ 'name' => ['', 'Set the name of the setting-array to use', 'string', false], - 'validationGroups' => [['Default'], 'Same as "Validation Groups" of Flow Framework.', 'array', false], + 'validationGroups' => [ + ['Default'], + 'Same as "Validation Groups" of Flow Framework. Defines the groups to execute.', + 'array', + false + ], ]; /** diff --git a/Tests/Functional/SettingsValidatorTest.php b/Tests/Functional/SettingsValidatorTest.php index 1d2a285..813c171 100644 --- a/Tests/Functional/SettingsValidatorTest.php +++ b/Tests/Functional/SettingsValidatorTest.php @@ -43,7 +43,7 @@ class SettingsValidatorTest extends FunctionalTestCase $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'); + $this->assertCount(1, $result->forProperty('shouldBeTrue')->getErrors(), 'Got no error for property'); } /** @@ -55,6 +55,6 @@ class SettingsValidatorTest extends FunctionalTestCase $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"'); - $this->assertCount(1, $result->forProperty('shouldBeFalse')->getErrors(), 'Got no error for shouldBeFalse property'); + $this->assertCount(1, $result->forProperty('shouldBeFalse')->getErrors(), 'Got no error for property'); } }