-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #201 from ConvertKit/fix-sync-past-orders-hpos-dis…
…abled Fix Sync Past Orders when HPOS Disabled
- Loading branch information
Showing
6 changed files
with
557 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
tests/acceptance/sync-past-orders/SyncPastOrdersHPOSCLICest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
<?php | ||
/** | ||
* Tests for Sync Past Orders functionality using WP-CLI with WooCommerce's | ||
* High Performance Order Storage (HPOS) system. | ||
* | ||
* @since 1.7.1 | ||
*/ | ||
class SyncPastOrdersHPOSCLICest | ||
{ | ||
/** | ||
* Run common actions before running the test functions in this class. | ||
* | ||
* @since 1.7.1 | ||
* | ||
* @param AcceptanceTester $I Tester. | ||
*/ | ||
public function _before(AcceptanceTester $I) | ||
{ | ||
// Activate Plugin. | ||
$I->activateWooCommerceAndConvertKitPlugins($I); | ||
|
||
// Enable HPOS. | ||
$I->setupWooCommerceHPOS($I); | ||
|
||
// Setup WooCommerce Plugin. | ||
$I->setupWooCommercePlugin($I); | ||
|
||
// Setup ConvertKit for WooCommerce Plugin. | ||
$I->setupConvertKitPlugin($I); | ||
|
||
// Activate Custom Order Numbers Plugin. | ||
$I->activateThirdPartyPlugin($I, 'custom-order-numbers-for-woocommerce'); | ||
|
||
// Setup Custom Order Numbers Plugin. | ||
$I->setupCustomOrderNumbersPlugin($I); | ||
|
||
// Delete all existing WooCommerce Orders from the database. | ||
$I->wooCommerceDeleteAllOrders($I); | ||
} | ||
|
||
/** | ||
* Test that the CLI command returns the expected console output when | ||
* attempting to sync past orders to ConvertKit Purchase Data, and no | ||
* WooCommerce Orders exist. | ||
* | ||
* @since 1.7.1 | ||
* | ||
* @param AcceptanceTester $I Tester. | ||
*/ | ||
public function testSyncPastOrdersWhenNoOrdersExist(AcceptanceTester $I) | ||
{ | ||
$I->cli([ 'ckwc-sync-past-orders' ]); | ||
$I->seeInShellOutput('No outstanding Orders to send to Kit'); | ||
} | ||
|
||
/** | ||
* Test that the CLI command returns the expected console output when | ||
* attempting to sync past orders to ConvertKit Purchase Data, and | ||
* WooCommerce Orders exist. | ||
* | ||
* @since 1.7.1 | ||
* | ||
* @param AcceptanceTester $I Tester. | ||
*/ | ||
public function testSyncPastOrders(AcceptanceTester $I) | ||
{ | ||
// Create Product and Checkout for this test, not sending the Order | ||
// to ConvertKit. | ||
$result = $I->wooCommerceCreateProductAndCheckoutWithConfig($I); | ||
|
||
// Remove prefix from Order ID, as CLI will not show the Custom Order Number Prefix. | ||
$orderIDParts = explode( '-', $result['order_id'] ); | ||
$orderID = $orderIDParts[ count($orderIDParts) - 1 ]; | ||
|
||
// Run CLI command. | ||
$I->cli([ 'ckwc-sync-past-orders' ]); | ||
$I->seeInShellOutput('WooCommerce Order ID #' . $orderID . ' added to Kit Purchase Data successfully. Kit Purchase ID: #'); | ||
|
||
// Confirm that the Order was added to ConvertKit. | ||
$I->apiCheckPurchaseExists($I, $result['order_id'], $result['email_address'], $result['product_id']); | ||
} | ||
|
||
/** | ||
* Test that the CLI command returns the expected console output when | ||
* attempting to sync past orders to ConvertKit Purchase Data using | ||
* the --limit argument, and WooCommerce Orders exist. | ||
* | ||
* @since 1.7.1 | ||
* | ||
* @param AcceptanceTester $I Tester. | ||
*/ | ||
public function testSyncPastOrdersWithLimitArgument(AcceptanceTester $I) | ||
{ | ||
// Create Product and Checkout for this test, not sending the Order | ||
// to ConvertKit. | ||
$results = [ | ||
$I->wooCommerceCreateProductAndCheckoutWithConfig($I), | ||
$I->wooCommerceCreateProductAndCheckoutWithConfig($I), | ||
]; | ||
|
||
// Run CLI command with --limit=1 to send each Order individually. | ||
foreach (array_reverse($results) as $result) { | ||
// Remove prefix from Order ID, as CLI will not show the Custom Order Number Prefix. | ||
$orderIDParts = explode( '-', $result['order_id'] ); | ||
$orderID = $orderIDParts[ count($orderIDParts) - 1 ]; | ||
|
||
// Run CLI command. | ||
$I->cli([ 'ckwc-sync-past-orders', '--limit=1' ]); | ||
$I->seeInShellOutput('WooCommerce Order ID #' . $orderID . ' added to Kit Purchase Data successfully. Kit Purchase ID: #'); | ||
|
||
// Confirm that the Order was added to ConvertKit. | ||
$I->apiCheckPurchaseExists($I, $result['order_id'], $result['email_address'], $result['product_id']); | ||
} | ||
} | ||
|
||
/** | ||
* Deactivate and reset Plugin(s) after each test, if the test passes. | ||
* We don't use _after, as this would provide a screenshot of the Plugin | ||
* deactivation and not the true test error. | ||
* | ||
* @since 1.4.4 | ||
* | ||
* @param AcceptanceTester $I Tester. | ||
*/ | ||
public function _passed(AcceptanceTester $I) | ||
{ | ||
$I->deactivateThirdPartyPlugin($I, 'custom-order-numbers-for-woocommerce'); | ||
$I->deactivateWooCommerceAndConvertKitPlugins($I); | ||
$I->resetConvertKitPlugin($I); | ||
} | ||
} |
Oops, something went wrong.