From 2bf59eab9a0caf17c957b37d77cc53f278989b6e Mon Sep 17 00:00:00 2001 From: John Oleksowicz Date: Thu, 2 Jun 2022 15:35:02 -0500 Subject: [PATCH] Create templated workflows in draft status MAILPOET-4264 --- .../CreateWorkflowFromTemplateController.php | 1 + .../lib/Automation/Engine/Workflows/Workflow.php | 5 +++++ .../Integrations/MailPoet/Templates/Templates.php | 2 +- .../Workflows/WorkflowsCreateFromTemplateTest.php | 14 ++++++++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/mailpoet/lib/Automation/Engine/Builder/CreateWorkflowFromTemplateController.php b/mailpoet/lib/Automation/Engine/Builder/CreateWorkflowFromTemplateController.php index 99e7eb0aa8..f9afdc56ad 100644 --- a/mailpoet/lib/Automation/Engine/Builder/CreateWorkflowFromTemplateController.php +++ b/mailpoet/lib/Automation/Engine/Builder/CreateWorkflowFromTemplateController.php @@ -34,6 +34,7 @@ class CreateWorkflowFromTemplateController { throw UnexpectedValueException::create()->withMessage('Template not found.'); } + $workflow->setDraft(); $this->storage->createWorkflow($workflow); return $workflow; } diff --git a/mailpoet/lib/Automation/Engine/Workflows/Workflow.php b/mailpoet/lib/Automation/Engine/Workflows/Workflow.php index 2f0115489c..bf94b84589 100644 --- a/mailpoet/lib/Automation/Engine/Workflows/Workflow.php +++ b/mailpoet/lib/Automation/Engine/Workflows/Workflow.php @@ -8,6 +8,7 @@ use MailPoet\Automation\Engine\Utils\Json; class Workflow { public const STATUS_ACTIVE = 'active'; public const STATUS_INACTIVE = 'inactive'; + public const STATUS_DRAFT = 'draft'; /** @var int */ private $id; @@ -55,6 +56,10 @@ class Workflow { return $this->status; } + public function setDraft(): void { + $this->status = self::STATUS_DRAFT; + } + public function getCreatedAt(): DateTimeImmutable { return $this->createdAt; } diff --git a/mailpoet/lib/Automation/Integrations/MailPoet/Templates/Templates.php b/mailpoet/lib/Automation/Integrations/MailPoet/Templates/Templates.php index d5925bc63a..bd0270e4f5 100644 --- a/mailpoet/lib/Automation/Integrations/MailPoet/Templates/Templates.php +++ b/mailpoet/lib/Automation/Integrations/MailPoet/Templates/Templates.php @@ -68,4 +68,4 @@ class Templates { private function uniqueId(): string { return bin2hex(random_bytes(7)); } -} \ No newline at end of file +} diff --git a/mailpoet/tests/integration/REST/Automation/Workflows/WorkflowsCreateFromTemplateTest.php b/mailpoet/tests/integration/REST/Automation/Workflows/WorkflowsCreateFromTemplateTest.php index b084e8a258..2adf1832c0 100644 --- a/mailpoet/tests/integration/REST/Automation/Workflows/WorkflowsCreateFromTemplateTest.php +++ b/mailpoet/tests/integration/REST/Automation/Workflows/WorkflowsCreateFromTemplateTest.php @@ -23,4 +23,18 @@ class WorkflowsCreateFromTemplateTest extends AutomationTest { $countAfter = count($storage->getWorkflows()); expect($countAfter)->equals($countBefore + 1); } + + public function testWorkflowsCreatedFromTemplatesAreCreatedInDraftStatus(): void { + $storage = ContainerWrapper::getInstance()->get(WorkflowStorage::class); + $this->post(self::ENDPOINT_PATH, [ + 'json' => [ + 'name' => 'Testing workflow from template', + 'template' => 'delayed-email-after-signup' + ], + ]); + $allWorkflows = $storage->getWorkflows(); + $createdWorkflow = array_pop($allWorkflows); + expect($createdWorkflow->getStatus())->equals('draft'); + } + }