From 42261ed77f1a6dc77395e5d693c8a0f43e0ea30f Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Mon, 12 Jun 2023 17:59:32 -0300 Subject: [PATCH] Ensure order ordering in order filter unit test (#38680) * Ensure order ordering in order filter unit test * remove unused variable, fix spacing --------- Co-authored-by: Ron Rennick --- .../changelog/fix-unit-test-test_query_filters | 4 ++++ .../DataStores/Orders/OrdersTableQueryTests.php | 13 +++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 plugins/woocommerce/changelog/fix-unit-test-test_query_filters diff --git a/plugins/woocommerce/changelog/fix-unit-test-test_query_filters b/plugins/woocommerce/changelog/fix-unit-test-test_query_filters new file mode 100644 index 00000000000..974053a0a76 --- /dev/null +++ b/plugins/woocommerce/changelog/fix-unit-test-test_query_filters @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Ensure order ordering in order filter unit test diff --git a/plugins/woocommerce/tests/php/src/Internal/DataStores/Orders/OrdersTableQueryTests.php b/plugins/woocommerce/tests/php/src/Internal/DataStores/Orders/OrdersTableQueryTests.php index 5c8d306a50a..4faa27ce521 100644 --- a/plugins/woocommerce/tests/php/src/Internal/DataStores/Orders/OrdersTableQueryTests.php +++ b/plugins/woocommerce/tests/php/src/Internal/DataStores/Orders/OrdersTableQueryTests.php @@ -181,6 +181,7 @@ class OrdersTableQueryTests extends WC_Unit_Test_Case { */ public function test_query_filters() { $order1 = new \WC_Order(); + $order1->set_date_created( time() - HOUR_IN_SECONDS ); $order1->save(); $order2 = new \WC_Order(); @@ -198,10 +199,10 @@ class OrdersTableQueryTests extends WC_Unit_Test_Case { $this->assertCount( 0, wc_get_orders( array() ) ); remove_all_filters( 'woocommerce_orders_table_query_clauses' ); - // Force a query that sorts orders by id DESC (as opposed to the default date ASC) if a query arg is present. - $filter_callback = function( $clauses, $query, $query_args ) use ( $order1 ) { + // Force a query that sorts orders by id ASC (as opposed to the default date DESC) if a query arg is present. + $filter_callback = function( $clauses, $query, $query_args ) { if ( ! empty( $query_args['my_custom_arg'] ) ) { - $clauses['orderby'] = $query->get_table_name( 'orders' ) . '.id DESC'; + $clauses['orderby'] = $query->get_table_name( 'orders' ) . '.id ASC'; } return $clauses; @@ -211,7 +212,8 @@ class OrdersTableQueryTests extends WC_Unit_Test_Case { $this->assertEquals( wc_get_orders( array( - 'return' => 'ids', + 'return' => 'ids', + 'my_custom_arg' => true, ) ), array( @@ -222,8 +224,7 @@ class OrdersTableQueryTests extends WC_Unit_Test_Case { $this->assertEquals( wc_get_orders( array( - 'return' => 'ids', - 'my_custom_arg' => true, + 'return' => 'ids', ) ), array(