Do not enforce workflow content for non-active workflows
[MAILPOET-4757]
This commit is contained in:
@@ -25,6 +25,11 @@ class AtLeastOneTriggerRule implements WorkflowNodeVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function complete(Workflow $workflow): void {
|
public function complete(Workflow $workflow): void {
|
||||||
|
// run full step validation only for active workflows
|
||||||
|
if ($workflow->getStatus() !== Workflow::STATUS_ACTIVE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->triggerFound) {
|
if ($this->triggerFound) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -15,6 +15,11 @@ class TriggerNeedsToBeFollowedByActionRule implements WorkflowNodeVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function visitNode(Workflow $workflow, WorkflowNode $node): void {
|
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();
|
$step = $node->getStep();
|
||||||
if ($step->getType() !== Step::TYPE_TRIGGER) {
|
if ($step->getType() !== Step::TYPE_TRIGGER) {
|
||||||
return;
|
return;
|
||||||
|
@@ -9,7 +9,7 @@ use MailPoet\Automation\Engine\Validation\WorkflowGraph\WorkflowWalker;
|
|||||||
|
|
||||||
require_once __DIR__ . '/WorkflowRuleTest.php';
|
require_once __DIR__ . '/WorkflowRuleTest.php';
|
||||||
|
|
||||||
class AtLeastOnTriggerTest extends WorkflowRuleTest
|
class AtLeastOneTriggerTest extends WorkflowRuleTest
|
||||||
{
|
{
|
||||||
public function testItPassesWhenTriggerExists(): void {
|
public function testItPassesWhenTriggerExists(): void {
|
||||||
$steps = [
|
$steps = [
|
||||||
@@ -17,6 +17,7 @@ class AtLeastOnTriggerTest extends WorkflowRuleTest
|
|||||||
't' => $this->createStep('t', Step::TYPE_TRIGGER),
|
't' => $this->createStep('t', Step::TYPE_TRIGGER),
|
||||||
];
|
];
|
||||||
$workflow = $this->make(Workflow::class, ['getSteps' => $steps, 'getStep' => function($id) use ($steps) { return $steps[$id]??null; }]);
|
$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()]);
|
(new WorkflowWalker())->walk($workflow, [new AtLeastOneTriggerRule()]);
|
||||||
//no exception thrown.
|
//no exception thrown.
|
||||||
@@ -27,7 +28,7 @@ class AtLeastOnTriggerTest extends WorkflowRuleTest
|
|||||||
'root' => $this->createStep('root', Step::TYPE_ROOT)
|
'root' => $this->createStep('root', Step::TYPE_ROOT)
|
||||||
];
|
];
|
||||||
$workflow = $this->make(Workflow::class, ['getSteps' => $steps, 'getStep' => function($id) use ($steps) { return $steps[$id]??null; }]);
|
$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->expectException(UnexpectedValueException::class);
|
||||||
$this->expectExceptionMessage('Invalid automation structure: There must be at least one trigger in the automation.');
|
$this->expectExceptionMessage('Invalid automation structure: There must be at least one trigger in the automation.');
|
@@ -18,6 +18,7 @@ class TriggerNeedsNextStepsRuleTest extends WorkflowRuleTest
|
|||||||
'a' => $this->createStep('a', Step::TYPE_ACTION, []),
|
'a' => $this->createStep('a', Step::TYPE_ACTION, []),
|
||||||
];
|
];
|
||||||
$workflow = $this->make(Workflow::class, ['getSteps' => $steps, 'getStep' => function($id) use ($steps) { return $steps[$id]??null; }]);
|
$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()]);
|
(new WorkflowWalker())->walk($workflow, [new TriggerNeedsToBeFollowedByActionRule()]);
|
||||||
//no exception thrown.
|
//no exception thrown.
|
||||||
@@ -29,6 +30,7 @@ class TriggerNeedsNextStepsRuleTest extends WorkflowRuleTest
|
|||||||
't' => $this->createStep('t', Step::TYPE_TRIGGER, []),
|
't' => $this->createStep('t', Step::TYPE_TRIGGER, []),
|
||||||
];
|
];
|
||||||
$workflow = $this->make(Workflow::class, ['getSteps' => $steps, 'getStep' => function($id) use ($steps) { return $steps[$id]??null; }]);
|
$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->expectException(UnexpectedValueException::class);
|
||||||
$this->expectExceptionMessage('Invalid automation structure: A trigger needs to be followed by an action.');
|
$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']),
|
'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 = $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->expectException(UnexpectedValueException::class);
|
||||||
|
Reference in New Issue
Block a user