diff --git a/mailpoet/lib/Automation/Engine/Validation/WorkflowRules/ValidStepRule.php b/mailpoet/lib/Automation/Engine/Validation/WorkflowRules/ValidStepRule.php index 7267190768..058f7ad2bb 100644 --- a/mailpoet/lib/Automation/Engine/Validation/WorkflowRules/ValidStepRule.php +++ b/mailpoet/lib/Automation/Engine/Validation/WorkflowRules/ValidStepRule.php @@ -7,13 +7,14 @@ use MailPoet\Automation\Engine\Exceptions; use MailPoet\Automation\Engine\Exceptions\UnexpectedValueException; use MailPoet\Automation\Engine\Validation\WorkflowGraph\WorkflowNode; use MailPoet\Automation\Engine\Validation\WorkflowGraph\WorkflowNodeVisitor; +use MailPoet\Validator\ValidationException; use Throwable; class ValidStepRule implements WorkflowNodeVisitor { /** @var WorkflowNodeVisitor[] */ private $rules; - /** @var array */ + /** @var array}> */ private $errors = []; /** @param WorkflowNodeVisitor[] $rules */ @@ -45,9 +46,19 @@ class ValidStepRule implements WorkflowNodeVisitor { try { $rule->visitNode($workflow, $node); } catch (UnexpectedValueException $e) { - $this->errors[$stepId] = ['step_id' => $stepId, 'message' => $e->getMessage()]; + if (!isset($this->errors[$stepId])) { + $this->errors[$stepId] = ['step_id' => $stepId, 'message' => $e->getMessage(), 'fields' => []]; + } + $this->errors[$stepId]['fields'] = array_merge($e->getErrors(), $this->errors[$stepId]['fields']); + } catch (ValidationException $e) { + if (!isset($this->errors[$stepId])) { + $this->errors[$stepId] = ['step_id' => $stepId, 'message' => $e->getMessage(), 'fields' => []]; + } + $this->errors[$stepId]['fields'] = array_merge($e->getErrors(), $this->errors[$stepId]['fields']); } catch (Throwable $e) { - $this->errors[$stepId] = ['step_id' => $stepId, 'message' => __('Unknown error.', 'mailpoet')]; + if (!isset($this->errors[$stepId])) { + $this->errors[$stepId] = ['step_id' => $stepId, 'message' => __('Unknown error.', 'mailpoet'), 'fields' => []]; + } } } } diff --git a/mailpoet/tests/unit/Automation/Engine/Validation/WorkflowRules/ValidStepRuleTest.php b/mailpoet/tests/unit/Automation/Engine/Validation/WorkflowRules/ValidStepRuleTest.php index 9d34bc746d..aa051d6451 100644 --- a/mailpoet/tests/unit/Automation/Engine/Validation/WorkflowRules/ValidStepRuleTest.php +++ b/mailpoet/tests/unit/Automation/Engine/Validation/WorkflowRules/ValidStepRuleTest.php @@ -42,11 +42,13 @@ class ValidStepRuleTest extends WorkflowRuleTest { try { (new WorkflowWalker())->walk($workflow, [$rule]); } catch (UnexpectedValueException $e) { + $errors = $e->getErrors(); $this->assertSame( [ 'root' => [ 'step_id' => 'root', 'message' => 'Test error', + 'fields' => [] ], ], $e->getErrors() @@ -77,6 +79,7 @@ class ValidStepRuleTest extends WorkflowRuleTest { 'root' => [ 'step_id' => 'root', 'message' => 'Unknown error.', + 'fields' => [], ], ], $e->getErrors()