diff --git a/mailpoet/lib/Automation/Engine/Validation/WorkflowRules/ConsistentStepMapRule.php b/mailpoet/lib/Automation/Engine/Validation/WorkflowRules/ConsistentStepMapRule.php new file mode 100644 index 0000000000..ad8d82252a --- /dev/null +++ b/mailpoet/lib/Automation/Engine/Validation/WorkflowRules/ConsistentStepMapRule.php @@ -0,0 +1,24 @@ +getSteps() as $id => $step) { + if ($id !== $step->getId()) { + throw Exceptions::workflowStructureNotValid(__('TODO', 'mailpoet')); + } + } + } + + public function visitNode(Workflow $workflow, WorkflowNode $node): void { + } + + public function complete(Workflow $workflow): void { + } +} diff --git a/mailpoet/tests/unit/Automation/Engine/Validation/WorkflowRules/ConsistentStepMapRuleTest.php b/mailpoet/tests/unit/Automation/Engine/Validation/WorkflowRules/ConsistentStepMapRuleTest.php new file mode 100644 index 0000000000..d760719627 --- /dev/null +++ b/mailpoet/tests/unit/Automation/Engine/Validation/WorkflowRules/ConsistentStepMapRuleTest.php @@ -0,0 +1,30 @@ +make(Workflow::class, ['getSteps' => [ + 'root' => $this->createStep('a'), + ]]); + + $this->expectException(UnexpectedValueException::class); + $this->expectExceptionMessage('Invalid workflow structure: TODO'); + (new WorkflowWalker())->walk($workflow, [new ConsistentStepMapRule()]); + } + + public function testItPassesWithCorrectKeyValuePair(): void { + $workflow = $this->make(Workflow::class, ['getSteps' => [ + 'root' => $this->createStep('root'), + ]]); + + (new WorkflowWalker())->walk($workflow, [new ConsistentStepMapRule()]); + // no exception thrown + } +}