diff --git a/plugins/woocommerce/changelog/52433-dev-using-new-legacy-status-constants-in-tests b/plugins/woocommerce/changelog/52433-dev-using-new-legacy-status-constants-in-tests new file mode 100644 index 00000000000..38af4c0f5f8 --- /dev/null +++ b/plugins/woocommerce/changelog/52433-dev-using-new-legacy-status-constants-in-tests @@ -0,0 +1,4 @@ +Significance: minor +Type: dev + +Uses the newly introduced legacy order status constants in unit tests. \ No newline at end of file diff --git a/plugins/woocommerce/tests/legacy/unit-tests/admin/reports/class-wc-tests-admin-report.php b/plugins/woocommerce/tests/legacy/unit-tests/admin/reports/class-wc-tests-admin-report.php index 4b21d058eb3..e7c9ac83b12 100644 --- a/plugins/woocommerce/tests/legacy/unit-tests/admin/reports/class-wc-tests-admin-report.php +++ b/plugins/woocommerce/tests/legacy/unit-tests/admin/reports/class-wc-tests-admin-report.php @@ -5,6 +5,8 @@ * @package WooCommerce\Tests\Admin\Reports */ +use Automattic\WooCommerce\Enums\OrderInternalStatus; + /** * Tests for the WC_Admin_Report class. */ @@ -146,7 +148,7 @@ class WC_Tests_Admin_Report extends WC_Unit_Test_Case { ) ); - $this->assertEquals( 'wc-completed', $data->post_status ); + $this->assertEquals( OrderInternalStatus::COMPLETED, $data->post_status ); } /** diff --git a/plugins/woocommerce/tests/legacy/unit-tests/customer/crud.php b/plugins/woocommerce/tests/legacy/unit-tests/customer/crud.php index ffc37b660ba..486da55d4fc 100644 --- a/plugins/woocommerce/tests/legacy/unit-tests/customer/crud.php +++ b/plugins/woocommerce/tests/legacy/unit-tests/customer/crud.php @@ -1,5 +1,7 @@ assertEquals( 0, $customer->get_total_spent() ); - $order->update_status( 'wc-completed' ); + $order->update_status( OrderInternalStatus::COMPLETED ); $customer = new WC_Customer( $customer_id ); $this->assertEquals( 50, $customer->get_total_spent() ); $order->delete(); diff --git a/plugins/woocommerce/tests/legacy/unit-tests/order/class-wc-tests-order-functions.php b/plugins/woocommerce/tests/legacy/unit-tests/order/class-wc-tests-order-functions.php index c0b82221e59..fb541582ca0 100644 --- a/plugins/woocommerce/tests/legacy/unit-tests/order/class-wc-tests-order-functions.php +++ b/plugins/woocommerce/tests/legacy/unit-tests/order/class-wc-tests-order-functions.php @@ -6,6 +6,7 @@ */ use Automattic\Jetpack\Constants; +use Automattic\WooCommerce\Enums\OrderInternalStatus; /** * Class Functions. @@ -25,13 +26,13 @@ class WC_Tests_Order_Functions extends WC_Unit_Test_Case { $order_statuses = apply_filters( 'wc_order_statuses', array( - 'wc-pending' => _x( 'Pending payment', 'Order status', 'woocommerce' ), - 'wc-processing' => _x( 'Processing', 'Order status', 'woocommerce' ), - 'wc-on-hold' => _x( 'On hold', 'Order status', 'woocommerce' ), - 'wc-completed' => _x( 'Completed', 'Order status', 'woocommerce' ), - 'wc-cancelled' => _x( 'Cancelled', 'Order status', 'woocommerce' ), - 'wc-refunded' => _x( 'Refunded', 'Order status', 'woocommerce' ), - 'wc-failed' => _x( 'Failed', 'Order status', 'woocommerce' ), + OrderInternalStatus::PENDING => _x( 'Pending payment', 'Order status', 'woocommerce' ), + OrderInternalStatus::PROCESSING => _x( 'Processing', 'Order status', 'woocommerce' ), + OrderInternalStatus::ON_HOLD => _x( 'On hold', 'Order status', 'woocommerce' ), + OrderInternalStatus::COMPLETED => _x( 'Completed', 'Order status', 'woocommerce' ), + OrderInternalStatus::CANCELLED => _x( 'Cancelled', 'Order status', 'woocommerce' ), + OrderInternalStatus::REFUNDED => _x( 'Refunded', 'Order status', 'woocommerce' ), + OrderInternalStatus::FAILED => _x( 'Failed', 'Order status', 'woocommerce' ), ) ); @@ -44,7 +45,7 @@ class WC_Tests_Order_Functions extends WC_Unit_Test_Case { * @since 2.3.0 */ public function test_wc_is_order_status() { - $this->assertTrue( wc_is_order_status( 'wc-pending' ) ); + $this->assertTrue( wc_is_order_status( OrderInternalStatus::PENDING ) ); $this->assertFalse( wc_is_order_status( 'wc-another-status' ) ); } @@ -55,7 +56,7 @@ class WC_Tests_Order_Functions extends WC_Unit_Test_Case { */ public function test_wc_get_order_status_name() { - $this->assertEquals( _x( 'Pending payment', 'Order status', 'woocommerce' ), wc_get_order_status_name( 'wc-pending' ) ); + $this->assertEquals( _x( 'Pending payment', 'Order status', 'woocommerce' ), wc_get_order_status_name( OrderInternalStatus::PENDING ) ); $this->assertEquals( _x( 'Pending payment', 'Order status', 'woocommerce' ), wc_get_order_status_name( 'pending' ) ); } @@ -82,18 +83,18 @@ class WC_Tests_Order_Functions extends WC_Unit_Test_Case { $this->assertEquals( 0, wc_orders_count( 'unkown-status' ) ); // Invalid order type should return 0. - $this->assertEquals( 0, wc_orders_count( 'wc-pending', 'invalid-order-type' ) ); + $this->assertEquals( 0, wc_orders_count( OrderInternalStatus::PENDING, 'invalid-order-type' ) ); wp_cache_flush(); // Fake some datastores and order types for testing. $test_counts = array( 'order' => array( - array( 'wc-on-hold', 2 ), + array( OrderInternalStatus::ON_HOLD, 2 ), array( 'trash', 1 ), ), 'order-fake-type' => array( - array( 'wc-on-hold', 3 ), + array( OrderInternalStatus::ON_HOLD, 3 ), array( 'trash', 0 ), ), ); diff --git a/plugins/woocommerce/tests/legacy/unit-tests/rest-api/Tests/Version3/reports-orders-totals.php b/plugins/woocommerce/tests/legacy/unit-tests/rest-api/Tests/Version3/reports-orders-totals.php index 8c8cf76709a..55e7ad23319 100644 --- a/plugins/woocommerce/tests/legacy/unit-tests/rest-api/Tests/Version3/reports-orders-totals.php +++ b/plugins/woocommerce/tests/legacy/unit-tests/rest-api/Tests/Version3/reports-orders-totals.php @@ -6,6 +6,7 @@ * @since 3.5.0 */ +use Automattic\WooCommerce\Enums\OrderInternalStatus; use Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper; use Automattic\WooCommerce\RestApi\UnitTests\HPOSToggleTrait; @@ -81,9 +82,9 @@ class WC_Tests_API_Reports_Orders_Totals extends WC_REST_Unit_Test_Case { // Create some orders with HPOS enabled. $order_counts = array( - 'wc-pending' => 3, - 'wc-processing' => 2, - 'wc-on-hold' => 1, + OrderInternalStatus::PENDING => 3, + OrderInternalStatus::PROCESSING => 2, + OrderInternalStatus::ON_HOLD => 1, ); foreach ( $order_counts as $status => $count ) { for ( $i = 0; $i < $count; $i++ ) { diff --git a/plugins/woocommerce/tests/php/includes/class-wc-tracker-test.php b/plugins/woocommerce/tests/php/includes/class-wc-tracker-test.php index 3328cfdc0db..0a39ddf342d 100644 --- a/plugins/woocommerce/tests/php/includes/class-wc-tracker-test.php +++ b/plugins/woocommerce/tests/php/includes/class-wc-tracker-test.php @@ -5,6 +5,7 @@ * @package WooCommerce\Tests\WC_Tracker. */ +use Automattic\WooCommerce\Enums\OrderInternalStatus; use Automattic\WooCommerce\Internal\Features\FeaturesController; use Automattic\WooCommerce\Utilities\PluginUtil; @@ -166,7 +167,7 @@ class WC_Tracker_Test extends \WC_Unit_Test_Case { */ public function test_get_tracking_data_orders() { $dummy_product = WC_Helper_Product::create_simple_product(); - $status_entries = array( 'wc-processing', 'wc-completed', 'wc-refunded', 'wc-pending' ); + $status_entries = array( OrderInternalStatus::PROCESSING, OrderInternalStatus::COMPLETED, OrderInternalStatus::REFUNDED, OrderInternalStatus::PENDING ); $created_via_entries = array( 'api', 'checkout', 'admin' ); $payment_method_entries = array( 'paypal', 'stripe', 'cod' ); diff --git a/plugins/woocommerce/tests/php/includes/data-stores/class-wc-customer-data-store-test.php b/plugins/woocommerce/tests/php/includes/data-stores/class-wc-customer-data-store-test.php index 66b34cba504..e812ea0f346 100644 --- a/plugins/woocommerce/tests/php/includes/data-stores/class-wc-customer-data-store-test.php +++ b/plugins/woocommerce/tests/php/includes/data-stores/class-wc-customer-data-store-test.php @@ -1,6 +1,7 @@ 'pending' ); + return array( OrderInternalStatus::PENDING => OrderStatus::PENDING ); } /** @@ -103,10 +104,13 @@ class WC_Customer_Data_Store_CPT_Test extends WC_Unit_Test_Case { $sql = 'INSERT INTO ' . OrdersTableDataStore::get_orders_table_name() . " - ( id, customer_id, status, type ) + ( id, customer_id, status, type ) VALUES - ( 1, %d, 'wc-completed', 'shop_order' ), ( %d, %d, 'wc-completed', 'shop_order' ), ( 3, %d, 'wc-invalid-status', 'shop_order' ), - ( 4, %d, 'wc-completed', 'shop_order' ), ( 5, %d, 'wc-completed', 'shop_order' )"; + ( 1, %d, '" . OrderInternalStatus::COMPLETED . "', 'shop_order' ), + ( %d, %d, '" . OrderInternalStatus::COMPLETED . "', 'shop_order' ), + ( 3, %d, 'wc-invalid-status', 'shop_order' ), + ( 4, %d, '" . OrderInternalStatus::COMPLETED . "', 'shop_order' ), + ( 5, %d, '" . OrderInternalStatus::COMPLETED . "', 'shop_order' )"; $customer_1_id = $customer_1->get_id(); $customer_2_id = $customer_2->get_id(); @@ -191,10 +195,14 @@ class WC_Customer_Data_Store_CPT_Test extends WC_Unit_Test_Case { $sql = 'INSERT INTO ' . OrdersTableDataStore::get_orders_table_name() . " - ( id, customer_id, status ) + ( id, customer_id, status ) VALUES - ( 1, %d, 'wc-completed' ), ( 2, %d, 'wc-completed' ), ( 3, %d, 'wc-completed' ), ( 4, %d, 'wc-invalid-status' ), - ( 5, %d, 'wc-completed' ), ( 6, %d, 'wc-completed' )"; + ( 1, %d, '" . OrderInternalStatus::COMPLETED . "' ), + ( 2, %d, '" . OrderInternalStatus::COMPLETED . "' ), + ( 3, %d, '" . OrderInternalStatus::COMPLETED . "' ), + ( 4, %d, 'wc-invalid-status' ), + ( 5, %d, '" . OrderInternalStatus::COMPLETED . "' ), + ( 6, %d, '" . OrderInternalStatus::COMPLETED . "' )"; $customer_1_id = $customer_1->get_id(); $customer_2_id = $customer_2->get_id(); @@ -246,10 +254,14 @@ class WC_Customer_Data_Store_CPT_Test extends WC_Unit_Test_Case { $sql = 'INSERT INTO ' . OrdersTableDataStore::get_orders_table_name() . " - ( id, customer_id, status, total_amount ) + ( id, customer_id, status, total_amount ) VALUES - ( 1, %d, 'wc-completed', 10 ), ( 2, %d, 'wc-completed', 20 ), ( 3, %d, 'wc-completed', 30 ), ( 4, %d, 'wc-invalid-status', 40 ), - ( 5, %d, 'wc-completed', 200 ), ( 6, %d, 'wc-completed', 300 )"; + ( 1, %d, '" . OrderInternalStatus::COMPLETED . "', 10 ), + ( 2, %d, '" . OrderInternalStatus::COMPLETED . "', 20 ), + ( 3, %d, '" . OrderInternalStatus::COMPLETED . "', 30 ), + ( 4, %d, 'wc-invalid-status', 40 ), + ( 5, %d, '" . OrderInternalStatus::COMPLETED . "', 200 ), + ( 6, %d, '" . OrderInternalStatus::COMPLETED . "', 300 )"; $customer_1_id = $customer_1->get_id(); $customer_2_id = $customer_2->get_id(); diff --git a/plugins/woocommerce/tests/php/includes/wc-stock-functions-tests.php b/plugins/woocommerce/tests/php/includes/wc-stock-functions-tests.php index 3e8bbb7bed8..844c11db11b 100644 --- a/plugins/woocommerce/tests/php/includes/wc-stock-functions-tests.php +++ b/plugins/woocommerce/tests/php/includes/wc-stock-functions-tests.php @@ -5,6 +5,8 @@ * @package WooCommerce\Tests\Functions\Stock */ +use Automattic\WooCommerce\Enums\OrderInternalStatus; + /** * Class WC_Stock_Functions_Tests. */ @@ -24,7 +26,7 @@ class WC_Stock_Functions_Tests extends \WC_Unit_Test_Case { */ public $order_stock_restore_statuses = array( 'wc-cancelled', - 'wc-pending', + OrderInternalStatus::PENDING, ); /** diff --git a/plugins/woocommerce/tests/php/src/Internal/DataStores/Orders/DataSynchronizerTests.php b/plugins/woocommerce/tests/php/src/Internal/DataStores/Orders/DataSynchronizerTests.php index a73ed6dd123..fd3727ca563 100644 --- a/plugins/woocommerce/tests/php/src/Internal/DataStores/Orders/DataSynchronizerTests.php +++ b/plugins/woocommerce/tests/php/src/Internal/DataStores/Orders/DataSynchronizerTests.php @@ -4,6 +4,7 @@ declare( strict_types = 1 ); namespace Automattic\WooCommerce\Tests\Internal\DataStores\Orders; use Automattic\WooCommerce\Enums\OrderStatus; +use Automattic\WooCommerce\Enums\OrderInternalStatus; use Automattic\WooCommerce\Internal\BatchProcessing\BatchProcessingController; use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController; use Automattic\WooCommerce\Internal\DataStores\Orders\DataSynchronizer; @@ -202,7 +203,7 @@ class DataSynchronizerTests extends \HposTestCase { $order->set_status( OrderStatus::PENDING ); $order->save(); $this->assertEquals( - 'wc-pending', + OrderInternalStatus::PENDING, $wpdb->get_var( "SELECT status FROM $orders_table WHERE id = $order_id" ), //phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared 'When the order status is updated, the change should be observed by the DataSynhronizer and a matching update will take place in the COT table.' ); diff --git a/plugins/woocommerce/tests/php/src/Internal/DataStores/Orders/OrdersTableDataStoreTests.php b/plugins/woocommerce/tests/php/src/Internal/DataStores/Orders/OrdersTableDataStoreTests.php index 35d068edbc3..6863aa7c7ce 100644 --- a/plugins/woocommerce/tests/php/src/Internal/DataStores/Orders/OrdersTableDataStoreTests.php +++ b/plugins/woocommerce/tests/php/src/Internal/DataStores/Orders/OrdersTableDataStoreTests.php @@ -5,6 +5,7 @@ namespace Automattic\WooCommerce\Tests\Internal\DataStores\Orders; use Automattic\WooCommerce\Database\Migrations\CustomOrderTable\PostsToOrdersMigrationController; use Automattic\WooCommerce\Enums\OrderStatus; +use Automattic\WooCommerce\Enums\OrderInternalStatus; use Automattic\WooCommerce\Internal\CostOfGoodsSold\CogsAwareUnitTestSuiteTrait; use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController; use Automattic\WooCommerce\Internal\DataStores\Orders\DataSynchronizer; @@ -585,7 +586,7 @@ class OrdersTableDataStoreTests extends \HposTestCase { $this->sut->untrash_order( $order ); $this->assertEquals( OrderStatus::ON_HOLD, $order->get_status() ); - $this->assertEquals( 'wc-on-hold', get_post_status( $order_id ) ); + $this->assertEquals( OrderInternalStatus::ON_HOLD, get_post_status( $order_id ) ); $this->assertEmpty( $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$this->sut->get_meta_table_name()} WHERE order_id = %d AND meta_key LIKE '_wp_trash_meta_%'", $order_id ) ) ); $this->assertEmpty( $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key LIKE '_wp_trash_meta_%'", $order_id ) ) ); @@ -1198,9 +1199,9 @@ class OrdersTableDataStoreTests extends \HposTestCase { */ public function test_get_order_count(): void { $number_of_orders_by_status = array( - 'wc-completed' => 4, - 'wc-processing' => 2, - 'wc-pending' => 4, + OrderInternalStatus::COMPLETED => 4, + OrderInternalStatus::PROCESSING => 2, + OrderInternalStatus::PENDING => 4, ); foreach ( $number_of_orders_by_status as $order_status => $number_of_orders ) { @@ -1234,8 +1235,8 @@ class OrdersTableDataStoreTests extends \HposTestCase { // Create a few orders. $orders_by_status = array( - 'wc-completed' => 3, - 'wc-pending' => 2, + OrderInternalStatus::COMPLETED => 3, + OrderInternalStatus::PENDING => 2, ); $unpaid_ids = array(); foreach ( $orders_by_status as $order_status => $order_count ) { @@ -1253,7 +1254,7 @@ class OrdersTableDataStoreTests extends \HposTestCase { } // Confirm not all orders are unpaid. - $this->assertEquals( $orders_by_status['wc-completed'], $this->sut->get_order_count( 'wc-completed' ) ); + $this->assertEquals( $orders_by_status[ OrderInternalStatus::COMPLETED ], $this->sut->get_order_count( OrderInternalStatus::COMPLETED ) ); // Find unpaid orders. $this->assertEqualsCanonicalizing( $unpaid_ids, $this->sut->get_unpaid_orders( $now_ist ) ); @@ -1644,7 +1645,7 @@ class OrdersTableDataStoreTests extends \HposTestCase { foreach ( $orders_test_data as $i => $order_data ) { $order = new \WC_Order(); $this->switch_data_store( $order, $this->sut ); - $order->set_status( 'wc-completed' ); + $order->set_status( OrderInternalStatus::COMPLETED ); $order->set_shipping_city( 'The Universe' ); $order->set_billing_first_name( $order_data[0] ); $order->set_billing_last_name( $order_data[1] ); @@ -2477,7 +2478,7 @@ class OrdersTableDataStoreTests extends \HposTestCase { $db_row = $db_row_callback->call( $this->sut, $order, false ); - $this->assertEquals( 'wc-completed', $db_row['data']['status'] ); + $this->assertEquals( OrderInternalStatus::COMPLETED, $db_row['data']['status'] ); } /**