Add tests for unknown step rule and step args rules
[MAILPOET-4659]
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace MailPoet\Automation\Engine\Validation\WorkflowRules;
|
||||
|
||||
require_once __DIR__ . '/WorkflowRuleTest.php';
|
||||
|
||||
use MailPoet\Automation\Engine\Control\RootStep;
|
||||
use MailPoet\Automation\Engine\Data\Step;
|
||||
use MailPoet\Automation\Engine\Data\Workflow;
|
||||
use MailPoet\Automation\Engine\Exceptions\UnexpectedValueException;
|
||||
use MailPoet\Automation\Engine\Registry;
|
||||
use MailPoet\Automation\Engine\Storage\WorkflowStorage;
|
||||
use MailPoet\Automation\Engine\Validation\WorkflowGraph\WorkflowWalker;
|
||||
|
||||
class UnknownStepRuleTest extends WorkflowRuleTest {
|
||||
public function testItDetectsModificationWithoutExistingWorkflow(): void {
|
||||
$workflow = $this->getWorkflow();
|
||||
$this->expectException(UnexpectedValueException::class);
|
||||
$this->expectExceptionMessage("Modification of step 'core:root' of type 'root' with ID 'root' is not supported when the related plugin is not active.");
|
||||
(new WorkflowWalker())->walk($workflow, [$this->getRule()]);
|
||||
}
|
||||
|
||||
public function testItDetectsAddedStep(): void {
|
||||
$workflow = $this->getWorkflow();
|
||||
$existingWorkflow = $this->make(Workflow::class, [
|
||||
'getId' => 1,
|
||||
'getSteps' => [],
|
||||
]);
|
||||
|
||||
$this->expectException(UnexpectedValueException::class);
|
||||
$this->expectExceptionMessage("Modification of step 'core:root' of type 'root' with ID 'root' is not supported when the related plugin is not active.");
|
||||
(new WorkflowWalker())->walk($workflow, [$this->getRule($existingWorkflow)]);
|
||||
}
|
||||
|
||||
public function testItDetectsChangedStep(): void {
|
||||
$workflow = $this->getWorkflow();
|
||||
$existingWorkflow = $this->make(Workflow::class, [
|
||||
'getId' => 1,
|
||||
'getSteps' => [
|
||||
'root' => $this->createStep('root', Step::TYPE_ROOT, ['next-step-id']),
|
||||
],
|
||||
]);
|
||||
|
||||
$this->expectException(UnexpectedValueException::class);
|
||||
$this->expectExceptionMessage("Modification of step 'core:root' of type 'root' with ID 'root' is not supported when the related plugin is not active.");
|
||||
(new WorkflowWalker())->walk($workflow, [$this->getRule($existingWorkflow)]);
|
||||
}
|
||||
|
||||
|
||||
public function testItPassesWithDeletedStep(): void {
|
||||
$workflow = $this->getWorkflow();
|
||||
$existingWorkflow = $this->make(Workflow::class, [
|
||||
'getId' => 1,
|
||||
'getSteps' => [
|
||||
'root' => new Step('root', 'root', 'core:root', [], []),
|
||||
'abc' => $this->createStep('abc', Step::TYPE_TRIGGER, []),
|
||||
],
|
||||
]);
|
||||
(new WorkflowWalker())->walk($workflow, [$this->getRule($existingWorkflow)]);
|
||||
}
|
||||
|
||||
public function testItPassesWithoutChanges(): void {
|
||||
$workflow = $this->getWorkflow();
|
||||
(new WorkflowWalker())->walk($workflow, [$this->getRule($workflow)]);
|
||||
}
|
||||
|
||||
public function testItPassesWithExistingRegistryStep(): void {
|
||||
$workflow = $this->make(Workflow::class, [
|
||||
'getId' => 1,
|
||||
'getSteps' => [
|
||||
'root' => new Step('root', 'root', 'core:root', [], []),
|
||||
],
|
||||
]);
|
||||
|
||||
$existingWorkflow = $this->make(Workflow::class, [
|
||||
'getId' => 1,
|
||||
'getSteps' => [
|
||||
'root' => new Step('root', 'root', 'core:root', ['key' => 'value'], []),
|
||||
],
|
||||
]);
|
||||
(new WorkflowWalker())->walk($workflow, [$this->getRule($existingWorkflow, [new RootStep()])]);
|
||||
}
|
||||
|
||||
private function getRule(Workflow $existingWorkflow = null, array $steps = []): UnknownStepRule {
|
||||
$stepMap = [];
|
||||
foreach ($steps as $step) {
|
||||
$stepMap[$step->getKey()] = $step;
|
||||
}
|
||||
$registry = $this->make(Registry::class, [
|
||||
'steps' => $stepMap,
|
||||
]);
|
||||
$storage = $this->make(WorkflowStorage::class, [
|
||||
'getWorkflow' => $existingWorkflow,
|
||||
]);
|
||||
return new UnknownStepRule($registry, $storage);
|
||||
}
|
||||
|
||||
private function getWorkflow(): Workflow {
|
||||
return $this->make(Workflow::class, [
|
||||
'getId' => 1,
|
||||
'getSteps' => [
|
||||
'root' => new Step('root', 'root', 'core:root', [], []),
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
@@ -0,0 +1,48 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace MailPoet\Automation\Engine\Validation\WorkflowRules;
|
||||
|
||||
require_once __DIR__ . '/WorkflowRuleTest.php';
|
||||
|
||||
use Codeception\Stub\Expected;
|
||||
use MailPoet\Automation\Engine\Control\RootStep;
|
||||
use MailPoet\Automation\Engine\Data\Step;
|
||||
use MailPoet\Automation\Engine\Data\Workflow;
|
||||
use MailPoet\Automation\Engine\Registry;
|
||||
use MailPoet\Automation\Engine\Validation\WorkflowGraph\WorkflowWalker;
|
||||
use MailPoet\Validator\Validator;
|
||||
|
||||
class ValidStepArgsRuleTest extends WorkflowRuleTest {
|
||||
public function testItRunsArgsValidation(): void {
|
||||
$registry = $this->make(Registry::class, [
|
||||
'steps' => ['core:root' => new RootStep()],
|
||||
]);
|
||||
|
||||
$validator = $this->make(Validator::class, [
|
||||
'validate' => Expected::once(),
|
||||
]);
|
||||
|
||||
$rule = new ValidStepArgsRule($registry, $validator);
|
||||
$workflow = $this->getWorkflow();
|
||||
(new WorkflowWalker())->walk($workflow, [$rule]);
|
||||
}
|
||||
|
||||
public function testItSkipsArgsValidationForNonExistentStep(): void {
|
||||
$registry = $this->make(Registry::class);
|
||||
$validator = $this->make(Validator::class, [
|
||||
'validate' => Expected::never(),
|
||||
]);
|
||||
|
||||
$rule = new ValidStepArgsRule($registry, $validator);
|
||||
$workflow = $this->getWorkflow();
|
||||
(new WorkflowWalker())->walk($workflow, [$rule]);
|
||||
}
|
||||
|
||||
private function getWorkflow(): Workflow {
|
||||
return $this->make(Workflow::class, [
|
||||
'getSteps' => [
|
||||
'root' => new Step('root', 'root', 'core:root', [], []),
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user