diff --git a/mailpoet/lib/Automation/Engine/Validation/WorkflowRules/NoSplitRule.php b/mailpoet/lib/Automation/Engine/Validation/WorkflowRules/NoSplitRule.php new file mode 100644 index 0000000000..f137dfd7c1 --- /dev/null +++ b/mailpoet/lib/Automation/Engine/Validation/WorkflowRules/NoSplitRule.php @@ -0,0 +1,23 @@ +getStep(); + if (count($step->getNextSteps()) > 1) { + throw Exceptions::workflowStructureNotValid(__('Path split found in workflow graph', 'mailpoet')); + } + } + + public function complete(Workflow $workflow): void { + } +} diff --git a/mailpoet/tests/unit/Automation/Engine/Validation/WorkflowRules/NoSplitRuleTest.php b/mailpoet/tests/unit/Automation/Engine/Validation/WorkflowRules/NoSplitRuleTest.php new file mode 100644 index 0000000000..a2abae42f7 --- /dev/null +++ b/mailpoet/tests/unit/Automation/Engine/Validation/WorkflowRules/NoSplitRuleTest.php @@ -0,0 +1,56 @@ +createWorkflow([ + 'root' => ['a1', 'a2'], + 'a1' => [], + 'a2' => [], + ]); + + $this->expectException(UnexpectedValueException::class); + $this->expectExceptionMessage('Invalid workflow structure: Path split found in workflow graph'); + (new WorkflowWalker())->walk($workflow, [new NoSplitRule()]); + } + + public function testItDetectsSplitPathWithSelfLoop(): void { + $workflow = $this->createWorkflow([ + 'root' => ['root', 'a'], + 'a' => [], + ]); + + $this->expectException(UnexpectedValueException::class); + $this->expectExceptionMessage('Invalid workflow structure: Path split found in workflow graph'); + (new WorkflowWalker())->walk($workflow, [new NoSplitRule()]); + } + + public function testItPassesWithSimplePath(): void { + $workflow = $this->createWorkflow([ + 'root' => ['a'], + 'a' => ['b'], + 'b' => ['c'], + 'c' => [], + ]); + + (new WorkflowWalker())->walk($workflow, [new NoSplitRule()]); + // no exception thrown + } + + public function testItPassesWithJoinedPath(): void { + $workflow = $this->createWorkflow([ + 'root' => ['a'], + 'a' => ['b'], + 'b' => ['a'], + ]); + + (new WorkflowWalker())->walk($workflow, [new NoSplitRule()]); + // no exception thrown + } +}