Do not enforce workflow content for non-active workflows

[MAILPOET-4757]
This commit is contained in:
Jan Jakes
2022-11-01 09:49:47 +01:00
committed by David Remer
parent dac8c1e2f3
commit 12f2d1730f
4 changed files with 16 additions and 2 deletions

View File

@@ -25,6 +25,11 @@ class AtLeastOneTriggerRule implements WorkflowNodeVisitor {
}
public function complete(Workflow $workflow): void {
// run full step validation only for active workflows
if ($workflow->getStatus() !== Workflow::STATUS_ACTIVE) {
return;
}
if ($this->triggerFound) {
return;
}

View File

@@ -15,6 +15,11 @@ class TriggerNeedsToBeFollowedByActionRule implements WorkflowNodeVisitor {
}
public function visitNode(Workflow $workflow, WorkflowNode $node): void {
// run full step validation only for active workflows
if ($workflow->getStatus() !== Workflow::STATUS_ACTIVE) {
return;
}
$step = $node->getStep();
if ($step->getType() !== Step::TYPE_TRIGGER) {
return;

View File

@@ -9,7 +9,7 @@ use MailPoet\Automation\Engine\Validation\WorkflowGraph\WorkflowWalker;
require_once __DIR__ . '/WorkflowRuleTest.php';
class AtLeastOnTriggerTest extends WorkflowRuleTest
class AtLeastOneTriggerTest extends WorkflowRuleTest
{
public function testItPassesWhenTriggerExists(): void {
$steps = [
@@ -17,6 +17,7 @@ class AtLeastOnTriggerTest extends WorkflowRuleTest
't' => $this->createStep('t', Step::TYPE_TRIGGER),
];
$workflow = $this->make(Workflow::class, ['getSteps' => $steps, 'getStep' => function($id) use ($steps) { return $steps[$id]??null; }]);
$workflow->setStatus(Workflow::STATUS_ACTIVE);
(new WorkflowWalker())->walk($workflow, [new AtLeastOneTriggerRule()]);
//no exception thrown.
@@ -27,7 +28,7 @@ class AtLeastOnTriggerTest extends WorkflowRuleTest
'root' => $this->createStep('root', Step::TYPE_ROOT)
];
$workflow = $this->make(Workflow::class, ['getSteps' => $steps, 'getStep' => function($id) use ($steps) { return $steps[$id]??null; }]);
$workflow->setStatus(Workflow::STATUS_ACTIVE);
$this->expectException(UnexpectedValueException::class);
$this->expectExceptionMessage('Invalid automation structure: There must be at least one trigger in the automation.');

View File

@@ -18,6 +18,7 @@ class TriggerNeedsNextStepsRuleTest extends WorkflowRuleTest
'a' => $this->createStep('a', Step::TYPE_ACTION, []),
];
$workflow = $this->make(Workflow::class, ['getSteps' => $steps, 'getStep' => function($id) use ($steps) { return $steps[$id]??null; }]);
$workflow->setStatus(Workflow::STATUS_ACTIVE);
(new WorkflowWalker())->walk($workflow, [new TriggerNeedsToBeFollowedByActionRule()]);
//no exception thrown.
@@ -29,6 +30,7 @@ class TriggerNeedsNextStepsRuleTest extends WorkflowRuleTest
't' => $this->createStep('t', Step::TYPE_TRIGGER, []),
];
$workflow = $this->make(Workflow::class, ['getSteps' => $steps, 'getStep' => function($id) use ($steps) { return $steps[$id]??null; }]);
$workflow->setStatus(Workflow::STATUS_ACTIVE);
$this->expectException(UnexpectedValueException::class);
$this->expectExceptionMessage('Invalid automation structure: A trigger needs to be followed by an action.');
@@ -43,6 +45,7 @@ class TriggerNeedsNextStepsRuleTest extends WorkflowRuleTest
't2' => $this->createStep('t2', Step::TYPE_TRIGGER, ['a']),
];
$workflow = $this->make(Workflow::class, ['getSteps' => $steps, 'getStep' => function($id) use ($steps) { return $steps[$id]??null; }]);
$workflow->setStatus(Workflow::STATUS_ACTIVE);
$this->expectException(UnexpectedValueException::class);