Extract customer creation/cleanup
This also ensures that cleanup always runs after all integration tests MAILPOET-5145
This commit is contained in:
committed by
John Oleksowicz
parent
f9d6e65ece
commit
cd0b795ac8
@ -1,6 +1,7 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
use Automattic\WooCommerce\Admin\API\Reports\Orders\Stats\DataStore;
|
||||
use Codeception\Scenario;
|
||||
use MailPoet\Automation\Engine\Data\Automation;
|
||||
use MailPoet\Automation\Engine\Data\AutomationRun;
|
||||
use MailPoet\Automation\Engine\Data\NextStep;
|
||||
@ -11,6 +12,7 @@ use MailPoet\Automation\Integrations\Core\Actions\DelayAction;
|
||||
use MailPoet\DI\ContainerWrapper;
|
||||
use MailPoet\Util\Security;
|
||||
use MailPoet\WooCommerce\Helper;
|
||||
use MailPoetVendor\Doctrine\DBAL\Connection;
|
||||
|
||||
require_once(ABSPATH . 'wp-admin/includes/user.php');
|
||||
require_once(ABSPATH . 'wp-admin/includes/ms.php');
|
||||
@ -36,13 +38,50 @@ class IntegrationTester extends \Codeception\Actor {
|
||||
|
||||
private $wooOrderIds = [];
|
||||
|
||||
private $createdUsers = [];
|
||||
|
||||
/** @var Connection */
|
||||
private $connection;
|
||||
|
||||
public function __construct(
|
||||
Scenario $scenario
|
||||
) {
|
||||
parent::__construct($scenario);
|
||||
$this->connection = ContainerWrapper::getInstance()->get(Connection::class);
|
||||
}
|
||||
|
||||
public function createWordPressUser(string $email, string $role) {
|
||||
return wp_insert_user([
|
||||
$userId = wp_insert_user([
|
||||
'user_login' => explode('@', $email)[0],
|
||||
'user_email' => $email,
|
||||
'role' => $role,
|
||||
'user_pass' => '12123154',
|
||||
]);
|
||||
|
||||
if ($userId instanceof WP_Error) {
|
||||
throw new Exception(sprintf("Unable to create WordPress user with email $email: %s", $userId->get_error_message()));
|
||||
}
|
||||
|
||||
$this->createdUsers[] = $email;
|
||||
|
||||
return $userId;
|
||||
}
|
||||
|
||||
public function createCustomer(string $email, string $role = 'customer'): int {
|
||||
global $wpdb;
|
||||
$userId = $this->createWordPressUser($email, $role);
|
||||
$this->connection->executeQuery("
|
||||
INSERT INTO {$wpdb->prefix}wc_customer_lookup (customer_id, user_id, first_name, last_name, email)
|
||||
VALUES ({$userId}, {$userId}, 'First Name', 'Last Name', '{$email}')
|
||||
");
|
||||
return $userId;
|
||||
}
|
||||
|
||||
public function deleteCreatedUsers() {
|
||||
foreach ($this->createdUsers as $createdUserEmail) {
|
||||
$this->deleteWordPressUser($createdUserEmail);
|
||||
}
|
||||
$this->createdUsers = [];
|
||||
}
|
||||
|
||||
public function deleteWordPressUser(string $email) {
|
||||
@ -167,4 +206,9 @@ class IntegrationTester extends \Codeception\Actor {
|
||||
$automationRunStorage = ContainerWrapper::getInstance()->get(AutomationRunStorage::class);
|
||||
return $automationRunStorage->getAutomationRun($automationRunStorage->createAutomationRun($automationRun));
|
||||
}
|
||||
|
||||
public function cleanup() {
|
||||
$this->deleteCreatedUsers();
|
||||
$this->deleteTestWooOrders();
|
||||
}
|
||||
}
|
||||
|
@ -371,6 +371,7 @@ class APITest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
wp_delete_user($this->wpUserId);
|
||||
}
|
||||
}
|
||||
|
@ -588,6 +588,7 @@ class ServicesTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
$this->diContainer->get(SettingsRepository::class)->truncate();
|
||||
}
|
||||
|
||||
|
@ -57,6 +57,7 @@ class SetupTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
$this->diContainer->get(SettingsRepository::class)->truncate();
|
||||
}
|
||||
}
|
||||
|
@ -57,6 +57,7 @@ class UserFlagsTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
$this->cleanup();
|
||||
}
|
||||
|
||||
|
@ -386,6 +386,7 @@ class AbandonedCartTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
WPFunctions::set(new WPFunctions());
|
||||
Carbon::setTestNow();
|
||||
// Restore original cart object
|
||||
|
@ -361,7 +361,7 @@ class FirstPurchaseTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
$this->tester->deleteTestWooOrders();
|
||||
parent::_after();
|
||||
WPFunctions::set(new WPFunctions);
|
||||
}
|
||||
}
|
||||
|
@ -282,6 +282,7 @@ class PurchasedProductTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
WPFunctions::set(new WPFunctions);
|
||||
}
|
||||
}
|
||||
|
@ -102,6 +102,7 @@ class WooCommerceTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
$wp = new WPFunctions;
|
||||
$wp->removeAllFilters('mailpoet_newsletter_shortcode');
|
||||
$wp->removeAllFilters('woocommerce_payment_complete');
|
||||
|
@ -140,6 +140,7 @@ class StepHandlerTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
$this->automationStorage->truncate();
|
||||
$this->automationRunStorage->truncate();
|
||||
$this->automationRunLogStorage->truncate();
|
||||
|
@ -162,6 +162,7 @@ class TriggerHandlerTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
$this->automationRunStorage->truncate();
|
||||
$this->automationStorage->truncate();
|
||||
$this->segmentRepository->truncate();
|
||||
|
@ -221,6 +221,7 @@ class AutomationRunLogTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
$this->automationStorage->truncate();
|
||||
$this->automationRunStorage->truncate();
|
||||
$this->automationRunLogStorage->truncate();
|
||||
|
@ -76,6 +76,7 @@ class AutomationTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
$this->storage->truncate();
|
||||
}
|
||||
}
|
||||
|
@ -44,6 +44,7 @@ class AutomationRunLogStorageTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
$this->storage->truncate();
|
||||
}
|
||||
}
|
||||
|
@ -171,6 +171,7 @@ class AutomationStatisticsStorageTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
$this->automationStorage->truncate();
|
||||
$this->automationRunStorage->truncate();
|
||||
}
|
||||
|
@ -175,6 +175,7 @@ class AutomationStorageTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
$this->diContainer->get(AutomationStorage::class)->truncate();
|
||||
$this->diContainer->get(AutomationRunStorage::class)->truncate();
|
||||
$this->diContainer->get(AutomationRunLogStorage::class)->truncate();
|
||||
|
@ -122,6 +122,7 @@ class OrderSubjectToSubscriberSubjectTransformerTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
$this->expectedSubscriberSubjectEntry = null;
|
||||
$this->subscribersRepository->truncate();
|
||||
$this->automationStorage->truncate();
|
||||
|
@ -71,6 +71,7 @@ class SomeoneSubscribesTriggerTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
$segmentIds = $this->getSegmentIds(array_keys($this->segments));
|
||||
$this->segmentRepository->bulkDelete($segmentIds);
|
||||
}
|
||||
|
@ -142,6 +142,7 @@ class UserRegistrationTriggerTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
if (!$this->userId) {
|
||||
return;
|
||||
}
|
||||
|
@ -114,6 +114,7 @@ class AccessControlTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
WPFunctions::set(new WPFunctions);
|
||||
}
|
||||
}
|
||||
|
@ -89,6 +89,7 @@ class EnvTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
// Restore the original environment
|
||||
Env::init($this->file, $this->version, DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
|
||||
}
|
||||
|
@ -104,6 +104,7 @@ class RendererTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
$this->_removeAssetsManifests();
|
||||
}
|
||||
|
||||
|
@ -336,6 +336,7 @@ class CronHelperTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
$this->diContainer->get(SettingsRepository::class)->truncate();
|
||||
}
|
||||
|
||||
|
@ -278,6 +278,7 @@ class DaemonHttpRunnerTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
$this->diContainer->get(SettingsRepository::class)->truncate();
|
||||
}
|
||||
|
||||
|
@ -91,6 +91,7 @@ class DaemonTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
$this->diContainer->get(SettingsRepository::class)->truncate();
|
||||
}
|
||||
|
||||
|
@ -75,6 +75,7 @@ class SupervisorTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
$this->diContainer->get(SettingsRepository::class)->truncate();
|
||||
}
|
||||
}
|
||||
|
@ -64,6 +64,7 @@ class PremiumKeyCheckTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
$this->diContainer->get(SettingsRepository::class)->truncate();
|
||||
}
|
||||
}
|
||||
|
@ -117,6 +117,7 @@ class SendingServiceKeyCheckTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
$this->diContainer->get(SettingsRepository::class)->truncate();
|
||||
}
|
||||
}
|
||||
|
@ -974,6 +974,7 @@ class SchedulerTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
Carbon::setTestNow();
|
||||
}
|
||||
}
|
||||
|
@ -129,6 +129,7 @@ class MailerTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
$this->diContainer->get(SettingsRepository::class)->truncate();
|
||||
ORM::raw_execute('TRUNCATE ' . Subscriber::$_table);
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ class ShortcodesTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
wp_delete_post($this->wPPost, true);
|
||||
}
|
||||
}
|
||||
|
@ -56,6 +56,6 @@ class WooCommerceSyncTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
$this->tester->deleteTestWooOrders();
|
||||
parent::_after();
|
||||
}
|
||||
}
|
||||
|
@ -342,6 +342,7 @@ class WordpressMailerTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
$this->subscribersRepository->truncate();
|
||||
}
|
||||
}
|
||||
|
@ -145,6 +145,7 @@ class CustomFieldTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
CustomField::deleteMany();
|
||||
Subscriber::deleteMany();
|
||||
SubscriberCustomField::deleteMany();
|
||||
|
@ -85,6 +85,7 @@ class ModelTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
ORM::setDb($this->connection->getWrappedConnection());
|
||||
}
|
||||
}
|
||||
|
@ -80,6 +80,7 @@ class ScheduledTaskSubscriberTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
ORM::raw_execute('TRUNCATE ' . ScheduledTask::$_table);
|
||||
ORM::raw_execute('TRUNCATE ' . ScheduledTaskSubscriber::$_table);
|
||||
ORM::raw_execute('TRUNCATE ' . Subscriber::$_table);
|
||||
|
@ -164,6 +164,7 @@ class ScheduledTaskTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
ORM::raw_execute('TRUNCATE ' . ScheduledTask::$_table);
|
||||
ORM::raw_execute('TRUNCATE ' . ScheduledTaskSubscriber::$_table);
|
||||
}
|
||||
|
@ -270,6 +270,7 @@ class SegmentTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
ORM::raw_execute('TRUNCATE ' . Subscriber::$_table);
|
||||
ORM::raw_execute('TRUNCATE ' . Segment::$_table);
|
||||
ORM::raw_execute('TRUNCATE ' . SubscriberSegment::$_table);
|
||||
|
@ -123,6 +123,7 @@ class SendingQueueTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
ORM::raw_execute('TRUNCATE ' . ScheduledTask::$_table);
|
||||
ORM::raw_execute('TRUNCATE ' . ScheduledTaskSubscriber::$_table);
|
||||
ORM::raw_execute('TRUNCATE ' . SendingQueue::$_table);
|
||||
|
@ -77,6 +77,7 @@ class SubscriberCustomFieldTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
SubscriberCustomField::deleteMany();
|
||||
}
|
||||
}
|
||||
|
@ -336,6 +336,7 @@ class SubscriberSegmentTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
Segment::deleteMany();
|
||||
Subscriber::deleteMany();
|
||||
SubscriberSegment::deleteMany();
|
||||
|
@ -57,6 +57,7 @@ class SendPreviewControllerTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
WPFunctions::set(new WPFunctions());
|
||||
}
|
||||
|
||||
|
@ -355,6 +355,7 @@ class PostNotificationTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
Carbon::setTestNow();
|
||||
}
|
||||
}
|
||||
|
@ -65,6 +65,7 @@ class SchedulerTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
Carbon::setTestNow();
|
||||
}
|
||||
}
|
||||
|
@ -462,6 +462,7 @@ class WelcomeTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
Carbon::setTestNow();
|
||||
}
|
||||
}
|
||||
|
@ -482,6 +482,7 @@ class ShortcodesTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
$this->cleanup();
|
||||
}
|
||||
|
||||
|
@ -237,6 +237,7 @@ class ViewInBrowserControllerTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
// reset WP user role
|
||||
$wpUser = wp_get_current_user();
|
||||
$wpUser->add_role('administrator');
|
||||
|
@ -38,10 +38,10 @@ class WooCommerceCategoryTest extends \MailPoetTest {
|
||||
|
||||
$this->cleanUp();
|
||||
|
||||
$customerId1 = $this->createCustomer('customer1@example.com', 'customer');
|
||||
$customerId2 = $this->createCustomer('customer2@example.com', 'customer');
|
||||
$customerId3OnHold = $this->createCustomer('customer-on-hold@example.com', 'customer');
|
||||
$customerId4PendingPayment = $this->createCustomer('customer-pending-payment@example.com', 'customer');
|
||||
$customerId1 = $this->tester->createCustomer('customer1@example.com', 'customer');
|
||||
$customerId2 = $this->tester->createCustomer('customer2@example.com', 'customer');
|
||||
$customerId3OnHold = $this->tester->createCustomer('customer-on-hold@example.com', 'customer');
|
||||
$customerId4PendingPayment = $this->tester->createCustomer('customer-pending-payment@example.com', 'customer');
|
||||
|
||||
$this->createSubscriber('a1@example.com');
|
||||
$this->createSubscriber('a2@example.com');
|
||||
@ -142,16 +142,6 @@ class WooCommerceCategoryTest extends \MailPoetTest {
|
||||
return $dynamicSegmentFilter;
|
||||
}
|
||||
|
||||
private function createCustomer(string $email, string $role): int {
|
||||
global $wpdb;
|
||||
$userId = $this->tester->createWordPressUser($email, $role);
|
||||
$this->connection->executeQuery("
|
||||
INSERT INTO {$wpdb->prefix}wc_customer_lookup (customer_id, user_id, first_name, last_name, email)
|
||||
VALUES ({$userId}, {$userId}, 'First Name', 'Last Name', '{$email}')
|
||||
");
|
||||
return $userId;
|
||||
}
|
||||
|
||||
private function createOrder(int $customerId, Carbon $createdAt, string $status = 'wc-completed'): int {
|
||||
$order = $this->tester->createWooCommerceOrder();
|
||||
$order->set_customer_id($customerId);
|
||||
@ -199,6 +189,7 @@ class WooCommerceCategoryTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after(): void {
|
||||
parent::_after();
|
||||
$this->cleanUp();
|
||||
}
|
||||
|
||||
|
@ -145,15 +145,11 @@ class WooCommerceCountryTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after(): void {
|
||||
parent::_after();
|
||||
$this->cleanUp();
|
||||
}
|
||||
|
||||
private function cleanup(): void {
|
||||
$emails = ['customer1@example.com', 'customer2@example.com', 'customer3@example.com', 'customer4@example.com'];
|
||||
foreach ($emails as $email) {
|
||||
$this->tester->deleteWordPressUser($email);
|
||||
}
|
||||
$this->tester->deleteTestWooOrders();
|
||||
$this->cleanUpLookUpTables();
|
||||
}
|
||||
}
|
||||
|
@ -32,9 +32,9 @@ class WooCommerceNumberOfOrdersTest extends \MailPoetTest {
|
||||
$this->numberOfOrders = $this->diContainer->get(WooCommerceNumberOfOrders::class);
|
||||
$this->cleanUp();
|
||||
|
||||
$customerId1 = $this->createCustomer('customer1@example.com', 'customer');
|
||||
$customerId2 = $this->createCustomer('customer2@example.com', 'customer');
|
||||
$customerId3 = $this->createCustomer('customer3@example.com', 'customer');
|
||||
$customerId1 = $this->tester->createCustomer('customer1@example.com', 'customer');
|
||||
$customerId2 = $this->tester->createCustomer('customer2@example.com', 'customer');
|
||||
$customerId3 = $this->tester->createCustomer('customer3@example.com', 'customer');
|
||||
|
||||
$this->orders[] = $this->createOrder($customerId1, Carbon::now()->subDays(3));
|
||||
$this->orders[] = $this->createOrder($customerId2, Carbon::now());
|
||||
@ -127,16 +127,6 @@ class WooCommerceNumberOfOrdersTest extends \MailPoetTest {
|
||||
return $dynamicSegmentFilter;
|
||||
}
|
||||
|
||||
private function createCustomer(string $email, string $role): int {
|
||||
global $wpdb;
|
||||
$userId = $this->tester->createWordPressUser($email, $role);
|
||||
$this->connection->executeQuery("
|
||||
INSERT INTO {$wpdb->prefix}wc_customer_lookup (customer_id, user_id, first_name, last_name, email)
|
||||
VALUES ({$userId}, {$userId}, 'First Name', 'Last Name', '{$email}')
|
||||
");
|
||||
return $userId;
|
||||
}
|
||||
|
||||
private function createOrder(int $customerId, Carbon $createdAt, $status = 'wc-completed'): int {
|
||||
$order = $this->tester->createWooCommerceOrder();
|
||||
$order->set_customer_id($customerId);
|
||||
@ -149,15 +139,12 @@ class WooCommerceNumberOfOrdersTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after(): void {
|
||||
parent::_after();
|
||||
$this->cleanUp();
|
||||
}
|
||||
|
||||
private function cleanUp(): void {
|
||||
global $wpdb;
|
||||
$emails = ['customer1@example.com', 'customer2@example.com', 'customer3@example.com'];
|
||||
foreach ($emails as $email) {
|
||||
$this->tester->deleteWordPressUser($email);
|
||||
}
|
||||
|
||||
if (!empty($this->orders)) {
|
||||
foreach ($this->orders as $orderId) {
|
||||
|
@ -33,10 +33,10 @@ class WooCommerceProductTest extends \MailPoetTest {
|
||||
|
||||
$this->cleanUp();
|
||||
|
||||
$customerId1 = $this->createCustomer('customer1@example.com', 'customer');
|
||||
$customerId2 = $this->createCustomer('customer2@example.com', 'customer');
|
||||
$customerIdOnHold = $this->createCustomer('customer-on-hold@example.com', 'customer');
|
||||
$customerIdPendingPayment = $this->createCustomer('customer-pending-payment@example.com', 'customer');
|
||||
$customerId1 = $this->tester->createCustomer('customer1@example.com', 'customer');
|
||||
$customerId2 = $this->tester->createCustomer('customer2@example.com', 'customer');
|
||||
$customerIdOnHold = $this->tester->createCustomer('customer-on-hold@example.com', 'customer');
|
||||
$customerIdPendingPayment = $this->tester->createCustomer('customer-pending-payment@example.com', 'customer');
|
||||
|
||||
$this->createSubscriber('a1@example.com');
|
||||
$this->createSubscriber('a2@example.com');
|
||||
@ -134,16 +134,6 @@ class WooCommerceProductTest extends \MailPoetTest {
|
||||
return $dynamicSegmentFilter;
|
||||
}
|
||||
|
||||
private function createCustomer(string $email, string $role): int {
|
||||
global $wpdb;
|
||||
$userId = $this->tester->createWordPressUser($email, $role);
|
||||
$this->connection->executeQuery("
|
||||
INSERT INTO {$wpdb->prefix}wc_customer_lookup (customer_id, user_id, first_name, last_name, email)
|
||||
VALUES ({$userId}, {$userId}, 'First Name', 'Last Name', '{$email}')
|
||||
");
|
||||
return $userId;
|
||||
}
|
||||
|
||||
private function createOrder(int $customerId, Carbon $createdAt, string $status = 'wc-completed'): int {
|
||||
$order = $this->tester->createWooCommerceOrder();
|
||||
$order->set_customer_id($customerId);
|
||||
@ -183,20 +173,12 @@ class WooCommerceProductTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after(): void {
|
||||
parent::_after();
|
||||
$this->cleanUp();
|
||||
}
|
||||
|
||||
private function cleanUp(): void {
|
||||
global $wpdb;
|
||||
$emails = [
|
||||
'customer1@example.com',
|
||||
'customer2@example.com',
|
||||
'customer-on-hold@example.com',
|
||||
'customer-pending-payment@example.com',
|
||||
];
|
||||
foreach ($emails as $email) {
|
||||
$this->tester->deleteWordPressUser($email);
|
||||
}
|
||||
|
||||
if (!empty($this->orders)) {
|
||||
foreach ($this->orders as $orderId) {
|
||||
|
@ -35,9 +35,9 @@ class WooCommerceSingleOrderValueTest extends \MailPoetTest {
|
||||
$this->wp = $this->diContainer->get(WPFunctions::class);
|
||||
$this->cleanUp();
|
||||
|
||||
$customerId1 = $this->createCustomer('customer1@example.com', 'customer');
|
||||
$customerId2 = $this->createCustomer('customer2@example.com', 'customer');
|
||||
$customerId3 = $this->createCustomer('customer3@example.com', 'customer');
|
||||
$customerId1 = $this->tester->createCustomer('customer1@example.com', 'customer');
|
||||
$customerId2 = $this->tester->createCustomer('customer2@example.com', 'customer');
|
||||
$customerId3 = $this->tester->createCustomer('customer3@example.com', 'customer');
|
||||
|
||||
$this->orders[] = $this->createOrder($customerId1, Carbon::now()->subDays(3), 10);
|
||||
$this->orders[] = $this->createOrder($customerId1, Carbon::now(), 5);
|
||||
@ -147,16 +147,6 @@ class WooCommerceSingleOrderValueTest extends \MailPoetTest {
|
||||
return $dynamicSegmentFilter;
|
||||
}
|
||||
|
||||
private function createCustomer(string $email, string $role): int {
|
||||
global $wpdb;
|
||||
$userId = $this->tester->createWordPressUser($email, $role);
|
||||
$this->connection->executeQuery("
|
||||
INSERT INTO {$wpdb->prefix}wc_customer_lookup (customer_id, user_id, first_name, last_name, email)
|
||||
VALUES ({$userId}, {$userId}, 'First Name', 'Last Name', '{$email}')
|
||||
");
|
||||
return $userId;
|
||||
}
|
||||
|
||||
private function createOrder(int $customerId, Carbon $createdAt, int $orderTotal): int {
|
||||
$order = $this->tester->createWooCommerceOrder();
|
||||
$order->set_customer_id($customerId);
|
||||
@ -170,6 +160,7 @@ class WooCommerceSingleOrderValueTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after(): void {
|
||||
parent::_after();
|
||||
$this->cleanUp();
|
||||
}
|
||||
|
||||
@ -177,10 +168,6 @@ class WooCommerceSingleOrderValueTest extends \MailPoetTest {
|
||||
global $wpdb;
|
||||
$this->truncateEntity(SegmentEntity::class);
|
||||
$this->truncateEntity(SubscriberEntity::class);
|
||||
$emails = ['customer1@example.com', 'customer2@example.com', 'customer3@example.com'];
|
||||
foreach ($emails as $email) {
|
||||
$this->tester->deleteWordPressUser($email);
|
||||
}
|
||||
|
||||
if (is_array($this->orders)) {
|
||||
foreach ($this->orders as $orderId) {
|
||||
|
@ -177,6 +177,7 @@ class WooCommerceSubscriptionTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after(): void {
|
||||
parent::_after();
|
||||
$this->cleanUp();
|
||||
}
|
||||
|
||||
|
@ -34,9 +34,9 @@ class WooCommerceTotalSpentTest extends \MailPoetTest {
|
||||
$this->wp = $this->diContainer->get(WPFunctions::class);
|
||||
$this->cleanUp();
|
||||
|
||||
$customerId1 = $this->createCustomer('customer1@example.com', 'customer');
|
||||
$customerId2 = $this->createCustomer('customer2@example.com', 'customer');
|
||||
$customerId3 = $this->createCustomer('customer3@example.com', 'customer');
|
||||
$customerId1 = $this->tester->createCustomer('customer1@example.com', 'customer');
|
||||
$customerId2 = $this->tester->createCustomer('customer2@example.com', 'customer');
|
||||
$customerId3 = $this->tester->createCustomer('customer3@example.com', 'customer');
|
||||
|
||||
$this->orders[] = $this->createOrder($customerId1, Carbon::now()->subDays(3), 10);
|
||||
$this->orders[] = $this->createOrder($customerId1, Carbon::now(), 5);
|
||||
@ -151,16 +151,6 @@ class WooCommerceTotalSpentTest extends \MailPoetTest {
|
||||
return $dynamicSegmentFilter;
|
||||
}
|
||||
|
||||
private function createCustomer(string $email, string $role): int {
|
||||
global $wpdb;
|
||||
$userId = $this->tester->createWordPressUser($email, $role);
|
||||
$this->connection->executeQuery("
|
||||
INSERT INTO {$wpdb->prefix}wc_customer_lookup (customer_id, user_id, first_name, last_name, email)
|
||||
VALUES ({$userId}, {$userId}, 'First Name', 'Last Name', '{$email}')
|
||||
");
|
||||
return $userId;
|
||||
}
|
||||
|
||||
private function createOrder(int $customerId, Carbon $createdAt, int $orderTotal): int {
|
||||
$order = $this->tester->createWooCommerceOrder();
|
||||
$order->set_customer_id($customerId);
|
||||
@ -174,15 +164,12 @@ class WooCommerceTotalSpentTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after(): void {
|
||||
parent::_after();
|
||||
$this->cleanUp();
|
||||
}
|
||||
|
||||
private function cleanUp(): void {
|
||||
global $wpdb;
|
||||
$emails = ['customer1@example.com', 'customer2@example.com', 'customer3@example.com'];
|
||||
foreach ($emails as $email) {
|
||||
$this->tester->deleteWordPressUser($email);
|
||||
}
|
||||
|
||||
if (is_array($this->orders)) {
|
||||
foreach ($this->orders as $orderId) {
|
||||
|
@ -464,6 +464,7 @@ class BridgeTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
$this->diContainer->get(SettingsRepository::class)->truncate();
|
||||
}
|
||||
}
|
||||
|
@ -87,6 +87,7 @@ class UserFlagsControllerTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
$this->cleanup();
|
||||
WPFunctions::set(new WPFunctions);
|
||||
}
|
||||
|
@ -220,6 +220,7 @@ class SubscriberActivityTrackerTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
$this->cleanUp();
|
||||
$this->wp->wpSetCurrentUser($this->backupUserId);
|
||||
}
|
||||
|
@ -306,6 +306,7 @@ class ImportExportFactoryTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
$this->clearSubscribersCountCache();
|
||||
}
|
||||
}
|
||||
|
@ -429,7 +429,8 @@ class ImportExportRepositoryTest extends \MailPoetTest {
|
||||
}
|
||||
}
|
||||
|
||||
protected function _after() {
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
$this->cleanup();
|
||||
}
|
||||
|
||||
|
@ -265,6 +265,7 @@ class SubscriberActionsTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
$this->diContainer->get(SettingsRepository::class)->truncate();
|
||||
}
|
||||
}
|
||||
|
@ -144,6 +144,7 @@ class FormTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
wp_delete_post($this->post);
|
||||
$this->diContainer->get(SettingsRepository::class)->truncate();
|
||||
}
|
||||
|
@ -282,6 +282,7 @@ class SendingTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
ORM::raw_execute('TRUNCATE ' . Newsletter::$_table);
|
||||
ORM::raw_execute('TRUNCATE ' . ScheduledTask::$_table);
|
||||
ORM::raw_execute('TRUNCATE ' . ScheduledTaskSubscriber::$_table);
|
||||
|
@ -23,6 +23,7 @@ class FunctionsTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
WPFunctions::set(new WPFunctions);
|
||||
}
|
||||
}
|
||||
|
@ -102,5 +102,6 @@ class ConflictResolverTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ class HeadersAlreadySentNoticeTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
delete_transient(HeadersAlreadySentNotice::OPTION_NAME);
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@ class PHPVersionWarningsTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
delete_transient('dismissed-php-version-outdated-notice');
|
||||
}
|
||||
|
||||
|
@ -96,6 +96,7 @@ class FunctionsTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
global $content_width; // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
|
||||
$content_width = $this->contentWidth; // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ class HelperTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
$this->tester->deleteTestWooOrders();
|
||||
parent::_after();
|
||||
$this->wp->deleteOption('woocommerce_onboarding_profile');
|
||||
}
|
||||
|
||||
|
@ -298,6 +298,7 @@ class SubscriptionTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
// restore settings
|
||||
$this->settings->set('woocommerce', $this->originalSettings);
|
||||
}
|
||||
|
@ -244,6 +244,7 @@ class TransactionalEmailHooksTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
$this->entityManager
|
||||
->createQueryBuilder()
|
||||
->delete()
|
||||
|
@ -216,6 +216,11 @@ abstract class MailPoetTest extends \Codeception\TestCase\Test { // phpcs:ignore
|
||||
unregister_post_type('product');
|
||||
}
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
$this->tester->cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
function asCallable($fn) {
|
||||
|
@ -40,6 +40,7 @@ class ErrorResponseTest extends \MailPoetUnitTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
WPFunctions::set(new WPFunctions);
|
||||
}
|
||||
}
|
||||
|
@ -49,6 +49,7 @@ class MailerErrorTest extends \MailPoetUnitTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
WPFunctions::set(new WPFunctions);
|
||||
}
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ class PHPMailMapperTest extends \MailPoetUnitTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
WPFunctions::set(new WPFunctions);
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ class SMTPMapperTest extends \MailPoetUnitTest {
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
parent::_after();
|
||||
WPFunctions::set(new WPFunctions);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user