Use new Automation data factory in other tests
[MAILPOET-4966]
This commit is contained in:
@@ -33,7 +33,7 @@ class Automation {
|
||||
[],
|
||||
[]
|
||||
),
|
||||
], new \WP_User());
|
||||
], new \WP_User(1));
|
||||
}
|
||||
|
||||
public function withName($name) {
|
||||
|
@@ -2,15 +2,13 @@
|
||||
|
||||
namespace MailPoet\Test\Acceptance;
|
||||
|
||||
use MailPoet\Automation\Engine\Data\Automation;
|
||||
use MailPoet\Automation\Engine\Data\NextStep;
|
||||
use MailPoet\Automation\Engine\Data\Step;
|
||||
use MailPoet\Automation\Engine\Storage\AutomationRunLogStorage;
|
||||
use MailPoet\Automation\Engine\Storage\AutomationRunStorage;
|
||||
use MailPoet\Automation\Engine\Storage\AutomationStorage;
|
||||
use MailPoet\Automation\Integrations\Core\Actions\DelayAction;
|
||||
use MailPoet\Automation\Integrations\MailPoet\Triggers\SomeoneSubscribesTrigger;
|
||||
use MailPoet\DI\ContainerWrapper;
|
||||
use MailPoet\Test\DataFactories\Automation as AutomationFactory;
|
||||
use MailPoet\Test\DataFactories\Settings;
|
||||
use MailPoet\Test\DataFactories\WooCommerceProduct;
|
||||
|
||||
@@ -49,7 +47,14 @@ class SomeoneSubscribesAutomationTriggeredByCheckoutCest {
|
||||
$i->wantTo("Activate a trigger by going through the Woocommerce checkout.");
|
||||
|
||||
$this->settingsFactory->withConfirmationEmailDisabled(); // Just so we do not have to check our mailbox first.
|
||||
$this->createAutomation();
|
||||
|
||||
$someoneSubscribesTrigger = $this->container->get(SomeoneSubscribesTrigger::class);
|
||||
(new AutomationFactory())
|
||||
->withName('test')
|
||||
->addStep(new Step('t', Step::TYPE_TRIGGER, $someoneSubscribesTrigger->getKey(), ['segment_ids' => []], []))
|
||||
->withDelayAction()
|
||||
->withStatusActive()
|
||||
->create();
|
||||
|
||||
$i->login();
|
||||
$i->amOnMailpoetPage('settings');
|
||||
@@ -75,28 +80,6 @@ class SomeoneSubscribesAutomationTriggeredByCheckoutCest {
|
||||
$i->dontSee('Entered 0');
|
||||
}
|
||||
|
||||
private function createAutomation(): Automation {
|
||||
$someoneSubscribesTrigger = $this->container->get(SomeoneSubscribesTrigger::class);
|
||||
$delayStep = $this->container->get(DelayAction::class);
|
||||
$steps = [
|
||||
'root' => new Step('root', Step::TYPE_ROOT, 'root', [], [new NextStep('t')]),
|
||||
't' => new Step('t', Step::TYPE_TRIGGER, $someoneSubscribesTrigger->getKey(), ['segment_ids' => []], [new NextStep('a1')]),
|
||||
'a1' => new Step('a1', Step::TYPE_ACTION, $delayStep->getKey(), ['delay' => 1, 'delay_type' => 'HOURS'], []),
|
||||
];
|
||||
$automation = new Automation(
|
||||
'test',
|
||||
$steps,
|
||||
new \WP_User(1)
|
||||
);
|
||||
$automation->setStatus(Automation::STATUS_ACTIVE);
|
||||
$id = $this->automationStorage->createAutomation($automation);
|
||||
$storedAutomation = $this->automationStorage->getAutomation($id);
|
||||
if (!$storedAutomation) {
|
||||
throw new \Exception("Automation not found.");
|
||||
}
|
||||
return $storedAutomation;
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
$this->automationStorage->truncate();
|
||||
$this->automationRunStorage->truncate();
|
||||
|
@@ -3,15 +3,13 @@
|
||||
namespace MailPoet\Test\Acceptance;
|
||||
|
||||
use Codeception\Util\Locator;
|
||||
use MailPoet\Automation\Engine\Data\Automation;
|
||||
use MailPoet\Automation\Engine\Data\NextStep;
|
||||
use MailPoet\Automation\Engine\Data\Step;
|
||||
use MailPoet\Automation\Engine\Storage\AutomationRunLogStorage;
|
||||
use MailPoet\Automation\Engine\Storage\AutomationRunStorage;
|
||||
use MailPoet\Automation\Engine\Storage\AutomationStorage;
|
||||
use MailPoet\Automation\Integrations\Core\Actions\DelayAction;
|
||||
use MailPoet\Automation\Integrations\MailPoet\Triggers\UserRegistrationTrigger;
|
||||
use MailPoet\DI\ContainerWrapper;
|
||||
use MailPoet\Test\DataFactories\Automation as AutomationFactory;
|
||||
use MailPoet\Test\DataFactories\Settings;
|
||||
|
||||
class UserRegistrationTriggerCest {
|
||||
@@ -46,6 +44,7 @@ class UserRegistrationTriggerCest {
|
||||
$this->settingsFactory
|
||||
->withSubscribeOnRegisterEnabled()
|
||||
->withConfirmationEmailDisabled();
|
||||
|
||||
$this->createAutomation();
|
||||
|
||||
$i->login();
|
||||
@@ -120,26 +119,14 @@ class UserRegistrationTriggerCest {
|
||||
}
|
||||
}
|
||||
|
||||
private function createAutomation(): Automation {
|
||||
$someoneSubscribesTrigger = $this->container->get(UserRegistrationTrigger::class);
|
||||
$delayStep = $this->container->get(DelayAction::class);
|
||||
$steps = [
|
||||
'root' => new Step('root', Step::TYPE_ROOT, 'root', [], [new NextStep('t')]),
|
||||
't' => new Step('t', Step::TYPE_TRIGGER, $someoneSubscribesTrigger->getKey(), ['roles' => []], [new NextStep('a1')]),
|
||||
'a1' => new Step('a1', Step::TYPE_ACTION, $delayStep->getKey(), ['delay' => 1, 'delay_type' => 'HOURS'], []),
|
||||
];
|
||||
$automation = new Automation(
|
||||
'test',
|
||||
$steps,
|
||||
new \WP_User(1)
|
||||
);
|
||||
$automation->setStatus(Automation::STATUS_ACTIVE);
|
||||
$id = $this->automationStorage->createAutomation($automation);
|
||||
$storedAutomation = $this->automationStorage->getAutomation($id);
|
||||
if (!$storedAutomation) {
|
||||
throw new \Exception("Automation not found.");
|
||||
}
|
||||
return $storedAutomation;
|
||||
private function createAutomation() {
|
||||
$userRegistrationTrigger = $this->container->get(UserRegistrationTrigger::class);
|
||||
(new AutomationFactory())
|
||||
->withName('test')
|
||||
->addStep(new Step('t', Step::TYPE_TRIGGER, $userRegistrationTrigger->getKey(), ['roles' => []], []))
|
||||
->withDelayAction()
|
||||
->withStatusActive()
|
||||
->create();
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
|
Reference in New Issue
Block a user