Skip to content
This repository has been archived by the owner on Jun 15, 2022. It is now read-only.

Commit

Permalink
Merge a94d10b into 74318bd
Browse files Browse the repository at this point in the history
  • Loading branch information
stevegrunwell committed Dec 14, 2018
2 parents 74318bd + a94d10b commit b379129
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
6 changes: 6 additions & 0 deletions includes/class-woocommerce-custom-orders-table-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ public function migrate( $args = array(), $assoc_args = array() ) {
$order_id
) );
}

WP_CLI::debug( sprintf(
/* Translators: %1$d is the migrated order ID. */
__( 'Order ID %1$d has been migrated.', 'woocommerce-custom-orders-table' ),
$order_id
) );
}

$progress->tick();
Expand Down
51 changes: 51 additions & 0 deletions tests/test-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ public function init_cli() {
WP_CLI::reset();

$this->cli = new WooCommerce_Custom_Orders_Table_CLI();

// Reset the WP_CLI counts.
WP_CLI::$__logger = array();
WP_CLI::$__counts = array(
'debug' => 0,
'info' => 0,
'success' => 0,
'warning' => 0,
'error' => 0,
);
}

public function test_count() {
Expand Down Expand Up @@ -106,6 +116,14 @@ public function test_migrate_works_in_batches() {
$this->cli->assertReceivedMessage( 'Beginning batch #3 (2 orders/batch).', 'debug' );
}

public function test_migrate_warns_if_no_orders_need_migrating() {
$this->assertEquals( 0, $this->cli->count(), 'Expected no orders to need migration.' );

$this->cli->migrate();

$this->assertEquals( 1, WP_CLI::$__counts['warning'], 'Expected to see a warning if no orders require migration.' );
}

/**
* Trigger a database error in the same way as the test_populate_from_meta_handles_errors test.
*
Expand Down Expand Up @@ -175,6 +193,22 @@ public function test_migrate_handles_errors_with_wc_get_order() {
);
}

public function test_migrate_warns_if_no_orders_were_successfully_migrated() {
$this->toggle_use_custom_table( false );
$order = WC_Helper_Order::create_order();
$this->toggle_use_custom_table( true );

// For the first item, cause wc_get_order() to break due to a non-existent class.
add_filter( 'woocommerce_order_class', function ( $classname ) {
return 'SomeNonExistentClassName';
} );

$this->cli->migrate();

$this->assertNull( $this->get_order_row( $order->get_id() ) );
$this->assertEquals( 1, WP_CLI::$__counts['warning'], 'Expected to see a warning if no orders were migrated.' );
}

/**
* @ticket https://github.com/liquidweb/woocommerce-custom-orders-table/issues/45
*/
Expand Down Expand Up @@ -342,6 +376,14 @@ public function test_backfill() {
}
}

public function test_backfill_warns_if_no_orders_need_migrating() {
$this->assertEquals( 0, $this->cli->count(), 'Expected no orders to need migration.' );

$this->cli->backfill();

$this->assertEquals( 1, WP_CLI::$__counts['warning'], 'Expected to see a warning if no orders require migration.' );
}

public function test_backfill_when_an_order_has_been_deleted() {
$order1 = WC_Helper_Order::create_order();
$order2 = WC_Helper_Order::create_order();
Expand All @@ -355,6 +397,15 @@ public function test_backfill_when_an_order_has_been_deleted() {
$this->assertNotEmpty( get_post_meta( $order2->get_id(), '_billing_email', true ) );
}

public function test_backfill_if_no_orders_were_backfilled() {
$this->toggle_use_custom_table( false );
WC_Helper_Order::create_order();

$this->cli->backfill();

$this->assertEquals( 1, WP_CLI::$__counts['warning'], 'Expected to see a warning if no orders were backfilled.' );
}

/**
* Retrieve the array of skipped IDs from the CLI instance.
*
Expand Down
21 changes: 21 additions & 0 deletions tests/test-customer-data-store.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* Tests for the WC_Customer_Data_Store_Custom_Table class.
*
* @package WooCommerce_Custom_Orders_Table
* @author Liquid Web
*/

class CustomerDataStoreTest extends TestCase {

/**
* @testWith ["some-value", "wc-some-value"]
* ["wc-some-value", "wc-some-value"]
*/
public function test_prefix_wc_status( $value, $expected ) {
$this->assertSame(
$expected,
WC_Customer_Data_Store_Custom_Table::prefix_wc_status( $value )
);
}
}

0 comments on commit b379129

Please sign in to comment.