diff --git a/mailpoet/tests/_support/IntegrationTester.php b/mailpoet/tests/_support/IntegrationTester.php index c27915dbf7..f093cead89 100644 --- a/mailpoet/tests/_support/IntegrationTester.php +++ b/mailpoet/tests/_support/IntegrationTester.php @@ -1,5 +1,10 @@ explode('@', $email)[0], @@ -42,4 +49,33 @@ class IntegrationTester extends \Codeception\Actor { wp_delete_user($user->ID); } } + + public function createWooCommerceOrder(): \WC_Order { + $helper = ContainerWrapper::getInstance()->get(Helper::class); + $order = $helper->wcCreateOrder([]); + $this->wooOrderIds[] = $order->get_id(); + + return $order; + } + + public function updateWooOrderStats(int $orderId): void { + if (!class_exists('Automattic\WooCommerce\Admin\API\Reports\Orders\Stats\DataStore')) { + return; + } + DataStore::sync_order($orderId); + } + + public function deleteTestWooOrders() { + $helper = ContainerWrapper::getInstance()->get(Helper::class); + foreach ($this->wooOrderIds as $wooOrderId) { + $order = $helper->wcGetOrder($wooOrderId); + if ($order instanceof \WC_Order) { + $order->delete(true); + } + } + } + + public function uniqueId($length = 10): string { + return Security::generateRandomString($length); + } }