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 <ronald.rennick@automattic.com>
This commit is contained in:
Ron Rennick 2023-06-12 17:59:32 -03:00 committed by GitHub
parent 90e4ddbf29
commit 42261ed77f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 6 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Ensure order ordering in order filter unit test

View File

@ -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(