From d61a4dd5bdfb1cfe7e4da96abbf430d868cfb374 Mon Sep 17 00:00:00 2001 From: Peter Fabian Date: Fri, 25 Jan 2019 00:06:59 +0100 Subject: [PATCH] Updated tests to be more stable around hour end. --- .../class-wc-tests-reports-orders-stats.php | 586 +++++++++--------- 1 file changed, 298 insertions(+), 288 deletions(-) diff --git a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-orders-stats.php b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-orders-stats.php index dedbc8809a0..0c594768993 100644 --- a/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-orders-stats.php +++ b/plugins/woocommerce-admin/tests/reports/class-wc-tests-reports-orders-stats.php @@ -143,6 +143,7 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { */ public function test_populate_and_query_multiple_intervals() { global $wpdb; + WC_Helper_Reports::reset_stats_dbs(); // 2 different products. $product_1_price = 25; @@ -185,6 +186,10 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { $customer_2 = WC_Helper_Customer::create_customer( 'cust_2', 'pwd_2', 'user_2@mail.com' ); $order_1_time = time(); + // One more order needs to fit into the same hour, but also be one second later than this one, so in case it's very end of the hour, shift order 1 one second towards past. + if ( 59 === $order_1_time % MINUTE_IN_SECONDS ) { + $order_1_time--; + } $order_2_time = $order_1_time; $this_['hour'] = array( 1, 2 ); @@ -324,20 +329,23 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { $data_store = new WC_Admin_Reports_Orders_Stats_Data_Store(); // Tests for before & after set to current hour. - $current_hour = new DateTime(); - $current_hour->setTimestamp( $order_1_time ); - $current_hour_minutes = (int) $current_hour->format( 'i' ); - $current_hour->setTimestamp( $order_1_time - $current_hour_minutes * MINUTE_IN_SECONDS ); + $current_hour_start = new DateTime(); + $current_hour_start->setTimestamp( $order_1_time ); + $current_hour_minutes = (int) $current_hour_start->format( 'i' ); + $current_hour_start->setTimestamp( $order_1_time - $current_hour_minutes * MINUTE_IN_SECONDS ); - $now = new DateTime(); + $current_hour_end = new DateTime(); + $current_hour_end->setTimestamp( $order_1_time ); + $order_1_seconds = (int) $current_hour_end->format( 'U' ) % HOUR_IN_SECONDS; + $current_hour_end->setTimestamp( $order_1_time + ( HOUR_IN_SECONDS - $order_1_seconds ) - 1 ); // All orders, no filters. // 72 orders in one batch (3 products * 3 coupon options * 2 order statuses * 2 customers * 2 orders), 4 items of each product per order // 24 orders without coupons, 48 with coupons: 24 with $1 coupon and 24 with $2 coupon. // shipping is $10 per order. $query_args = array( - 'after' => $current_hour->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $now->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), 'interval' => 'hour', ); @@ -377,11 +385,11 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { ), 'intervals' => array( array( - 'interval' => $current_hour->format( 'Y-m-d H' ), - 'date_start' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_start_gmt' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_end' => $now->format( 'Y-m-d H:i:s' ), - 'date_end_gmt' => $now->format( 'Y-m-d H:i:s' ), + 'interval' => $current_hour_start->format( 'Y-m-d H' ), + 'date_start' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_start_gmt' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_end' => $current_hour_end->format( 'Y-m-d H:i:s' ), + 'date_end_gmt' => $current_hour_end->format( 'Y-m-d H:i:s' ), 'subtotals' => array( 'orders_count' => $orders_count, 'num_items_sold' => $num_items_sold, @@ -402,13 +410,13 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'pages' => 1, 'page_no' => 1, ); - $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'No filters' ); + $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Query args: ' . print_r( $query_args, true ) . "; query: {$wpdb->last_query}" ); // * Order status filter // ** Status is, positive filter for 2 statuses, i.e. all orders. $query_args = array( - 'after' => $current_hour->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $now->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), 'interval' => 'hour', 'status_is' => array( $order_status_1, @@ -416,12 +424,12 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { ), ); - $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Status is, positive filter for 2 statuses' ); + $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Query args: ' . print_r( $query_args, true ) . "; query: {$wpdb->last_query}" ); // ** Status is, positive filter for 1 status -> half orders. $query_args = array( - 'after' => $current_hour->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $now->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), 'interval' => 'hour', 'status_is' => array( $order_status_1, @@ -464,11 +472,11 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { ), 'intervals' => array( array( - 'interval' => $current_hour->format( 'Y-m-d H' ), - 'date_start' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_start_gmt' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_end' => $now->format( 'Y-m-d H:i:s' ), - 'date_end_gmt' => $now->format( 'Y-m-d H:i:s' ), + 'interval' => $current_hour_start->format( 'Y-m-d H' ), + 'date_start' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_start_gmt' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_end' => $current_hour_end->format( 'Y-m-d H:i:s' ), + 'date_end_gmt' => $current_hour_end->format( 'Y-m-d H:i:s' ), 'subtotals' => array( 'orders_count' => $orders_count, 'num_items_sold' => $num_items_sold, @@ -489,12 +497,12 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'pages' => 1, 'page_no' => 1, ); - $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Status is, positive filter for 1 status' ); + $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Query args: ' . print_r( $query_args, true ) . "; query: {$wpdb->last_query}" ); // ** Status is not, negative filter for 1 status -> half orders. $query_args = array( - 'after' => $current_hour->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $now->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), 'interval' => 'hour', 'status_is_not' => array( $order_status_2, @@ -537,11 +545,11 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { ), 'intervals' => array( array( - 'interval' => $current_hour->format( 'Y-m-d H' ), - 'date_start' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_start_gmt' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_end' => $now->format( 'Y-m-d H:i:s' ), - 'date_end_gmt' => $now->format( 'Y-m-d H:i:s' ), + 'interval' => $current_hour_start->format( 'Y-m-d H' ), + 'date_start' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_start_gmt' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_end' => $current_hour_end->format( 'Y-m-d H:i:s' ), + 'date_end_gmt' => $current_hour_end->format( 'Y-m-d H:i:s' ), 'subtotals' => array( 'orders_count' => $orders_count, 'num_items_sold' => $num_items_sold, @@ -562,12 +570,12 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'pages' => 1, 'page_no' => 1, ); - $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Status is not, negative filter for 1 status ' ); + $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Query args: ' . print_r( $query_args, true ) . "; query: {$wpdb->last_query}" ); // ** Status is not, negative filter for 2 statuses -> no orders. $query_args = array( - 'after' => $current_hour->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $now->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), 'interval' => 'hour', 'status_is_not' => array( $order_status_1, @@ -593,11 +601,11 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { ), 'intervals' => array( array( - 'interval' => $current_hour->format( 'Y-m-d H' ), - 'date_start' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_start_gmt' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_end' => $now->format( 'Y-m-d H:i:s' ), - 'date_end_gmt' => $now->format( 'Y-m-d H:i:s' ), + 'interval' => $current_hour_start->format( 'Y-m-d H' ), + 'date_start' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_start_gmt' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_end' => $current_hour_end->format( 'Y-m-d H:i:s' ), + 'date_end_gmt' => $current_hour_end->format( 'Y-m-d H:i:s' ), 'subtotals' => array( 'orders_count' => 0, 'num_items_sold' => 0, @@ -618,12 +626,12 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'pages' => 1, 'page_no' => 1, ); - $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Status is not, negative filter for 2 statuses' ); + $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Query args: ' . print_r( $query_args, true ) . "; query: {$wpdb->last_query}" ); // ** Status is + Status is not, positive filter for 2 statuses, negative for 1 -> half of orders. $query_args = array( - 'after' => $current_hour->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $now->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), 'interval' => 'hour', 'status_is' => array( $order_status_1, @@ -670,11 +678,11 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { ), 'intervals' => array( array( - 'interval' => $current_hour->format( 'Y-m-d H' ), - 'date_start' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_start_gmt' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_end' => $now->format( 'Y-m-d H:i:s' ), - 'date_end_gmt' => $now->format( 'Y-m-d H:i:s' ), + 'interval' => $current_hour_start->format( 'Y-m-d H' ), + 'date_start' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_start_gmt' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_end' => $current_hour_end->format( 'Y-m-d H:i:s' ), + 'date_end_gmt' => $current_hour_end->format( 'Y-m-d H:i:s' ), 'subtotals' => array( 'orders_count' => $orders_count, 'num_items_sold' => $num_items_sold, @@ -695,13 +703,13 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'pages' => 1, 'page_no' => 1, ); - $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Status is + Status is not, positive filter for 2 statuses, negative for 1' ); + $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Query args: ' . print_r( $query_args, true ) . "; query: {$wpdb->last_query}" ); // * Product filter // ** Product includes, positive filter for 2 products, i.e. 2 orders out of 3. $query_args = array( - 'after' => $current_hour->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $now->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), 'interval' => 'hour', 'product_includes' => array( $product_1->get_id(), @@ -743,11 +751,11 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { ), 'intervals' => array( array( - 'interval' => $current_hour->format( 'Y-m-d H' ), - 'date_start' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_start_gmt' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_end' => $now->format( 'Y-m-d H:i:s' ), - 'date_end_gmt' => $now->format( 'Y-m-d H:i:s' ), + 'interval' => $current_hour_start->format( 'Y-m-d H' ), + 'date_start' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_start_gmt' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_end' => $current_hour_end->format( 'Y-m-d H:i:s' ), + 'date_end_gmt' => $current_hour_end->format( 'Y-m-d H:i:s' ), 'subtotals' => array( 'orders_count' => $orders_count, 'num_items_sold' => $num_items_sold, @@ -768,12 +776,12 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'pages' => 1, 'page_no' => 1, ); - $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Product includes, positive filter for 2 products: ' . $wpdb->last_query ); + $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Query args: ' . print_r( $query_args, true ) . "; query: {$wpdb->last_query}" ); // ** Product includes, positive filter for 1 product, 1/3 of orders $query_args = array( - 'after' => $current_hour->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $now->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), 'interval' => 'hour', 'product_includes' => array( $product_3->get_id(), @@ -813,11 +821,11 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { ), 'intervals' => array( array( - 'interval' => $current_hour->format( 'Y-m-d H' ), - 'date_start' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_start_gmt' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_end' => $now->format( 'Y-m-d H:i:s' ), - 'date_end_gmt' => $now->format( 'Y-m-d H:i:s' ), + 'interval' => $current_hour_start->format( 'Y-m-d H' ), + 'date_start' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_start_gmt' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_end' => $current_hour_end->format( 'Y-m-d H:i:s' ), + 'date_end_gmt' => $current_hour_end->format( 'Y-m-d H:i:s' ), 'subtotals' => array( 'orders_count' => $orders_count, 'num_items_sold' => $num_items_sold, @@ -838,12 +846,12 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'pages' => 1, 'page_no' => 1, ); - $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Product includes, positive filter for 1 product: ' . $wpdb->last_query ); + $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Query args: ' . print_r( $query_args, true ) . "; query: {$wpdb->last_query}" ); // ** Product excludes, negative filter for 1 product, 2/3 of orders. $query_args = array( - 'after' => $current_hour->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $now->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), 'interval' => 'hour', 'product_excludes' => array( $product_1->get_id(), @@ -884,11 +892,11 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { ), 'intervals' => array( array( - 'interval' => $current_hour->format( 'Y-m-d H' ), - 'date_start' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_start_gmt' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_end' => $now->format( 'Y-m-d H:i:s' ), - 'date_end_gmt' => $now->format( 'Y-m-d H:i:s' ), + 'interval' => $current_hour_start->format( 'Y-m-d H' ), + 'date_start' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_start_gmt' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_end' => $current_hour_end->format( 'Y-m-d H:i:s' ), + 'date_end_gmt' => $current_hour_end->format( 'Y-m-d H:i:s' ), 'subtotals' => array( 'orders_count' => $orders_count, 'num_items_sold' => $num_items_sold, @@ -909,12 +917,12 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'pages' => 1, 'page_no' => 1, ); - $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Product includes, negative filter for 1 product: ' . $wpdb->last_query ); + $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Query args: ' . print_r( $query_args, true ) . "; query: {$wpdb->last_query}" ); // ** Product excludes, negative filter for 2 products, 1/3 of orders $query_args = array( - 'after' => $current_hour->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $now->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), 'interval' => 'hour', 'product_excludes' => array( $product_1->get_id(), @@ -954,11 +962,11 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { ), 'intervals' => array( array( - 'interval' => $current_hour->format( 'Y-m-d H' ), - 'date_start' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_start_gmt' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_end' => $now->format( 'Y-m-d H:i:s' ), - 'date_end_gmt' => $now->format( 'Y-m-d H:i:s' ), + 'interval' => $current_hour_start->format( 'Y-m-d H' ), + 'date_start' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_start_gmt' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_end' => $current_hour_end->format( 'Y-m-d H:i:s' ), + 'date_end_gmt' => $current_hour_end->format( 'Y-m-d H:i:s' ), 'subtotals' => array( 'orders_count' => $orders_count, 'num_items_sold' => $num_items_sold, @@ -979,12 +987,12 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'pages' => 1, 'page_no' => 1, ); - $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Product includes, negative filter for 2 product: ' . $wpdb->last_query ); + $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Query args: ' . print_r( $query_args, true ) . "; query: {$wpdb->last_query}" ); // ** Product includes + product excludes, positive filter for 2 products, negative for 1 -> 1/3 of orders, only orders with product 2 and product 2 + product 4 $query_args = array( - 'after' => $current_hour->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $now->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), 'interval' => 'hour', 'product_includes' => array( $product_1->get_id(), @@ -1027,11 +1035,11 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { ), 'intervals' => array( array( - 'interval' => $current_hour->format( 'Y-m-d H' ), - 'date_start' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_start_gmt' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_end' => $now->format( 'Y-m-d H:i:s' ), - 'date_end_gmt' => $now->format( 'Y-m-d H:i:s' ), + 'interval' => $current_hour_start->format( 'Y-m-d H' ), + 'date_start' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_start_gmt' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_end' => $current_hour_end->format( 'Y-m-d H:i:s' ), + 'date_end_gmt' => $current_hour_end->format( 'Y-m-d H:i:s' ), 'subtotals' => array( 'orders_count' => $orders_count, 'num_items_sold' => $num_items_sold, @@ -1052,13 +1060,13 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'pages' => 1, 'page_no' => 1, ); - $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Product includes, negative filter for 2 product: ' . $wpdb->last_query ); + $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Query args: ' . print_r( $query_args, true ) . "; query: {$wpdb->last_query}" ); // * Coupon filters // ** Coupon includes, positive filter for 2 coupons, i.e. 2/3 of orders. $query_args = array( - 'after' => $current_hour->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $now->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), 'interval' => 'hour', 'coupon_includes' => array( $coupon_1->get_id(), @@ -1102,11 +1110,11 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { ), 'intervals' => array( array( - 'interval' => $current_hour->format( 'Y-m-d H' ), - 'date_start' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_start_gmt' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_end' => $now->format( 'Y-m-d H:i:s' ), - 'date_end_gmt' => $now->format( 'Y-m-d H:i:s' ), + 'interval' => $current_hour_start->format( 'Y-m-d H' ), + 'date_start' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_start_gmt' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_end' => $current_hour_end->format( 'Y-m-d H:i:s' ), + 'date_end_gmt' => $current_hour_end->format( 'Y-m-d H:i:s' ), 'subtotals' => array( 'orders_count' => $orders_count, 'num_items_sold' => $num_items_sold, @@ -1127,12 +1135,12 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'pages' => 1, 'page_no' => 1, ); - $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Product includes, negative filter for 2 product: ' . $wpdb->last_query ); + $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Query args: ' . print_r( $query_args, true ) . "; query: {$wpdb->last_query}" ); // ** Coupon includes, positive filter for 1 coupon, 1/3 of orders $query_args = array( - 'after' => $current_hour->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $now->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), 'interval' => 'hour', 'coupon_includes' => array( $coupon_1->get_id(), @@ -1174,11 +1182,11 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { ), 'intervals' => array( array( - 'interval' => $current_hour->format( 'Y-m-d H' ), - 'date_start' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_start_gmt' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_end' => $now->format( 'Y-m-d H:i:s' ), - 'date_end_gmt' => $now->format( 'Y-m-d H:i:s' ), + 'interval' => $current_hour_start->format( 'Y-m-d H' ), + 'date_start' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_start_gmt' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_end' => $current_hour_end->format( 'Y-m-d H:i:s' ), + 'date_end_gmt' => $current_hour_end->format( 'Y-m-d H:i:s' ), 'subtotals' => array( 'orders_count' => $orders_count, 'num_items_sold' => $num_items_sold, @@ -1199,12 +1207,12 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'pages' => 1, 'page_no' => 1, ); - $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Product includes, negative filter for 2 product: ' . $wpdb->last_query ); + $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Query args: ' . print_r( $query_args, true ) . "; query: {$wpdb->last_query}" ); // ** Coupon excludes, negative filter for 1 coupon, 2/3 of orders $query_args = array( - 'after' => $current_hour->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $now->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), 'interval' => 'hour', 'coupon_excludes' => array( $coupon_1->get_id(), @@ -1246,11 +1254,11 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { ), 'intervals' => array( array( - 'interval' => $current_hour->format( 'Y-m-d H' ), - 'date_start' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_start_gmt' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_end' => $now->format( 'Y-m-d H:i:s' ), - 'date_end_gmt' => $now->format( 'Y-m-d H:i:s' ), + 'interval' => $current_hour_start->format( 'Y-m-d H' ), + 'date_start' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_start_gmt' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_end' => $current_hour_end->format( 'Y-m-d H:i:s' ), + 'date_end_gmt' => $current_hour_end->format( 'Y-m-d H:i:s' ), 'subtotals' => array( 'orders_count' => $orders_count, 'num_items_sold' => $num_items_sold, @@ -1271,12 +1279,12 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'pages' => 1, 'page_no' => 1, ); - $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Product includes, negative filter for 2 product: ' . $wpdb->last_query ); + $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Query args: ' . print_r( $query_args, true ) . "; query: {$wpdb->last_query}" ); // ** Coupon excludes, negative filter for 2 coupons, 1/3 of orders $query_args = array( - 'after' => $current_hour->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $now->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), 'interval' => 'hour', 'coupon_excludes' => array( $coupon_1->get_id(), @@ -1320,11 +1328,11 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { ), 'intervals' => array( array( - 'interval' => $current_hour->format( 'Y-m-d H' ), - 'date_start' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_start_gmt' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_end' => $now->format( 'Y-m-d H:i:s' ), - 'date_end_gmt' => $now->format( 'Y-m-d H:i:s' ), + 'interval' => $current_hour_start->format( 'Y-m-d H' ), + 'date_start' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_start_gmt' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_end' => $current_hour_end->format( 'Y-m-d H:i:s' ), + 'date_end_gmt' => $current_hour_end->format( 'Y-m-d H:i:s' ), 'subtotals' => array( 'orders_count' => $orders_count, 'num_items_sold' => $num_items_sold, @@ -1345,12 +1353,12 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'pages' => 1, 'page_no' => 1, ); - $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Product includes, negative filter for 2 product: ' . $wpdb->last_query ); + $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Query args: ' . print_r( $query_args, true ) . "; query: {$wpdb->last_query}" ); // ** Coupon includes + coupon excludes, positive filter for 2 coupon, negative for 1, 1/3 orders $query_args = array( - 'after' => $current_hour->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $now->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), 'interval' => 'hour', 'coupon_includes' => array( $coupon_1->get_id(), @@ -1397,11 +1405,11 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { ), 'intervals' => array( array( - 'interval' => $current_hour->format( 'Y-m-d H' ), - 'date_start' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_start_gmt' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_end' => $now->format( 'Y-m-d H:i:s' ), - 'date_end_gmt' => $now->format( 'Y-m-d H:i:s' ), + 'interval' => $current_hour_start->format( 'Y-m-d H' ), + 'date_start' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_start_gmt' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_end' => $current_hour_end->format( 'Y-m-d H:i:s' ), + 'date_end_gmt' => $current_hour_end->format( 'Y-m-d H:i:s' ), 'subtotals' => array( 'orders_count' => $orders_count, 'num_items_sold' => $num_items_sold, @@ -1422,13 +1430,13 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'pages' => 1, 'page_no' => 1, ); - $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Product includes, negative filter for 2 product: ' . $wpdb->last_query ); + $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Query args: ' . print_r( $query_args, true ) . "; query: {$wpdb->last_query}" ); // * Customer filters // ** Customer new $query_args = array( - 'after' => $current_hour->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $now->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), 'interval' => 'hour', 'customer' => 'new', ); @@ -1465,11 +1473,11 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { ), 'intervals' => array( array( - 'interval' => $current_hour->format( 'Y-m-d H' ), - 'date_start' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_start_gmt' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_end' => $now->format( 'Y-m-d H:i:s' ), - 'date_end_gmt' => $now->format( 'Y-m-d H:i:s' ), + 'interval' => $current_hour_start->format( 'Y-m-d H' ), + 'date_start' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_start_gmt' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_end' => $current_hour_end->format( 'Y-m-d H:i:s' ), + 'date_end_gmt' => $current_hour_end->format( 'Y-m-d H:i:s' ), 'subtotals' => array( 'orders_count' => $orders_count, 'num_items_sold' => $num_items_sold, @@ -1490,18 +1498,19 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'pages' => 1, 'page_no' => 1, ); - $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Product includes, negative filter for 2 product: ' . $wpdb->last_query ); + $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Query args: ' . print_r( $query_args, true ) . "; query: {$wpdb->last_query}" ); // ** Customer returning $returning_order = WC_Helper_Order::create_order( $customer_1->get_id(), $product ); $returning_order->set_status( 'completed' ); $returning_order->set_shipping_total( 10 ); $returning_order->set_total( 110 ); // $25x4 products + $10 shipping. + $returning_order->set_date_created( $order_1_time + 1 ); // This is guaranteed to belong to the same hour by the adjustment to $order_1_time. $returning_order->save(); $query_args = array( - 'after' => date( 'Y-m-d H:i:s', $orders[0]->get_date_created()->getOffsetTimestamp() + 1 ), // Date after initial order to get a returning customer. - 'before' => $now->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), // I don't think this makes sense.... date( 'Y-m-d H:i:s', $orders[0]->get_date_created()->getOffsetTimestamp() + 1 ), // Date after initial order to get a returning customer. + 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), 'interval' => 'hour', 'customer' => 'returning', ); @@ -1535,11 +1544,11 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { ), 'intervals' => array( array( - 'interval' => $current_hour->format( 'Y-m-d H' ), - 'date_start' => date( 'Y-m-d H:i:s', $orders[0]->get_date_created()->getOffsetTimestamp() + 1 ), - 'date_start_gmt' => date( 'Y-m-d H:i:s', $orders[0]->get_date_created()->getOffsetTimestamp() + 1 ), - 'date_end' => $now->format( 'Y-m-d H:i:s' ), - 'date_end_gmt' => $now->format( 'Y-m-d H:i:s' ), + 'interval' => $current_hour_start->format( 'Y-m-d H' ), + 'date_start' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'date_start_gmt' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'date_end' => $current_hour_end->format( 'Y-m-d H:i:s' ), + 'date_end_gmt' => $current_hour_end->format( 'Y-m-d H:i:s' ), 'subtotals' => array( 'orders_count' => $orders_count, 'num_items_sold' => $num_items_sold, @@ -1560,14 +1569,15 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'pages' => 1, 'page_no' => 1, ); - $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Orders from returning customers: ' . $wpdb->last_query ); + + $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Query args: ' . print_r( $query_args, true ) . "; query: {$wpdb->last_query};" ); wp_delete_post( $returning_order->get_id(), true ); // Combinations: match all // status_is + product_includes. $query_args = array( - 'after' => $current_hour->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $now->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), 'interval' => 'hour', 'status_is' => array( $order_status_1, @@ -1609,11 +1619,11 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { ), 'intervals' => array( array( - 'interval' => $current_hour->format( 'Y-m-d H' ), - 'date_start' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_start_gmt' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_end' => $now->format( 'Y-m-d H:i:s' ), - 'date_end_gmt' => $now->format( 'Y-m-d H:i:s' ), + 'interval' => $current_hour_start->format( 'Y-m-d H' ), + 'date_start' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_start_gmt' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_end' => $current_hour_end->format( 'Y-m-d H:i:s' ), + 'date_end_gmt' => $current_hour_end->format( 'Y-m-d H:i:s' ), 'subtotals' => array( 'orders_count' => $orders_count, 'num_items_sold' => $num_items_sold, @@ -1634,12 +1644,12 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'pages' => 1, 'page_no' => 1, ); - $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'No filters' ); + $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Query args: ' . print_r( $query_args, true ) . "; query: {$wpdb->last_query}" ); // status_is + coupon_includes. $query_args = array( - 'after' => $current_hour->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $now->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), 'interval' => 'hour', 'status_is' => array( $order_status_1, @@ -1685,11 +1695,11 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { ), 'intervals' => array( array( - 'interval' => $current_hour->format( 'Y-m-d H' ), - 'date_start' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_start_gmt' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_end' => $now->format( 'Y-m-d H:i:s' ), - 'date_end_gmt' => $now->format( 'Y-m-d H:i:s' ), + 'interval' => $current_hour_start->format( 'Y-m-d H' ), + 'date_start' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_start_gmt' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_end' => $current_hour_end->format( 'Y-m-d H:i:s' ), + 'date_end_gmt' => $current_hour_end->format( 'Y-m-d H:i:s' ), 'subtotals' => array( 'orders_count' => $orders_count, 'num_items_sold' => $num_items_sold, @@ -1710,12 +1720,12 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'pages' => 1, 'page_no' => 1, ); - $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'No filters' ); + $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Query args: ' . print_r( $query_args, true ) . "; query: {$wpdb->last_query}" ); // product_includes + coupon_includes. $query_args = array( - 'after' => $current_hour->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $now->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), 'interval' => 'hour', 'product_includes' => array( $product_1->get_id(), @@ -1757,11 +1767,11 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { ), 'intervals' => array( array( - 'interval' => $current_hour->format( 'Y-m-d H' ), - 'date_start' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_start_gmt' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_end' => $now->format( 'Y-m-d H:i:s' ), - 'date_end_gmt' => $now->format( 'Y-m-d H:i:s' ), + 'interval' => $current_hour_start->format( 'Y-m-d H' ), + 'date_start' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_start_gmt' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_end' => $current_hour_end->format( 'Y-m-d H:i:s' ), + 'date_end_gmt' => $current_hour_end->format( 'Y-m-d H:i:s' ), 'subtotals' => array( 'orders_count' => $orders_count, 'num_items_sold' => $num_items_sold, @@ -1782,12 +1792,12 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'pages' => 1, 'page_no' => 1, ); - $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'No filters' ); + $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Query args: ' . print_r( $query_args, true ) . "; query: {$wpdb->last_query}" ); // status_is + product_includes + coupon_includes. $query_args = array( - 'after' => $current_hour->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $now->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), 'interval' => 'hour', 'status_is' => array( $order_status_1, @@ -1832,11 +1842,11 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { ), 'intervals' => array( array( - 'interval' => $current_hour->format( 'Y-m-d H' ), - 'date_start' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_start_gmt' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_end' => $now->format( 'Y-m-d H:i:s' ), - 'date_end_gmt' => $now->format( 'Y-m-d H:i:s' ), + 'interval' => $current_hour_start->format( 'Y-m-d H' ), + 'date_start' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_start_gmt' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_end' => $current_hour_end->format( 'Y-m-d H:i:s' ), + 'date_end_gmt' => $current_hour_end->format( 'Y-m-d H:i:s' ), 'subtotals' => array( 'orders_count' => $orders_count, 'num_items_sold' => $num_items_sold, @@ -1857,12 +1867,12 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'pages' => 1, 'page_no' => 1, ); - $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'No filters' ); + $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Query args: ' . print_r( $query_args, true ) . "; query: {$wpdb->last_query}" ); // status_is + status_is_not + product_includes. $query_args = array( - 'after' => $current_hour->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $now->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), 'interval' => 'hour', 'status_is' => array( $order_status_1, @@ -1911,11 +1921,11 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { ), 'intervals' => array( array( - 'interval' => $current_hour->format( 'Y-m-d H' ), - 'date_start' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_start_gmt' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_end' => $now->format( 'Y-m-d H:i:s' ), - 'date_end_gmt' => $now->format( 'Y-m-d H:i:s' ), + 'interval' => $current_hour_start->format( 'Y-m-d H' ), + 'date_start' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_start_gmt' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_end' => $current_hour_end->format( 'Y-m-d H:i:s' ), + 'date_end_gmt' => $current_hour_end->format( 'Y-m-d H:i:s' ), 'subtotals' => array( 'orders_count' => $orders_count, 'num_items_sold' => $num_items_sold, @@ -1936,12 +1946,12 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'pages' => 1, 'page_no' => 1, ); - $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'No filters' ); + $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Query args: ' . print_r( $query_args, true ) . "; query: {$wpdb->last_query}" ); // status_is + status_is_not + product_includes + product_excludes. $query_args = array( - 'after' => $current_hour->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $now->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), 'interval' => 'hour', 'status_is' => array( $order_status_1, @@ -1991,11 +2001,11 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { ), 'intervals' => array( array( - 'interval' => $current_hour->format( 'Y-m-d H' ), - 'date_start' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_start_gmt' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_end' => $now->format( 'Y-m-d H:i:s' ), - 'date_end_gmt' => $now->format( 'Y-m-d H:i:s' ), + 'interval' => $current_hour_start->format( 'Y-m-d H' ), + 'date_start' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_start_gmt' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_end' => $current_hour_end->format( 'Y-m-d H:i:s' ), + 'date_end_gmt' => $current_hour_end->format( 'Y-m-d H:i:s' ), 'subtotals' => array( 'orders_count' => $orders_count, 'num_items_sold' => $num_items_sold, @@ -2016,12 +2026,12 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'pages' => 1, 'page_no' => 1, ); - $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'No filters' ); + $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Query args: ' . print_r( $query_args, true ) . "; query: {$wpdb->last_query}" ); // status_is + status_is_not + product_includes + product_excludes + coupon_includes. $query_args = array( - 'after' => $current_hour->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $now->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), 'interval' => 'hour', 'status_is' => array( $order_status_1, @@ -2073,11 +2083,11 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { ), 'intervals' => array( array( - 'interval' => $current_hour->format( 'Y-m-d H' ), - 'date_start' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_start_gmt' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_end' => $now->format( 'Y-m-d H:i:s' ), - 'date_end_gmt' => $now->format( 'Y-m-d H:i:s' ), + 'interval' => $current_hour_start->format( 'Y-m-d H' ), + 'date_start' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_start_gmt' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_end' => $current_hour_end->format( 'Y-m-d H:i:s' ), + 'date_end_gmt' => $current_hour_end->format( 'Y-m-d H:i:s' ), 'subtotals' => array( 'orders_count' => $orders_count, 'num_items_sold' => $num_items_sold, @@ -2098,12 +2108,12 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'pages' => 1, 'page_no' => 1, ); - $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'No filters' ); + $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Query args: ' . print_r( $query_args, true ) . "; query: {$wpdb->last_query}" ); // status_is + status_is_not + product_includes + product_excludes + coupon_includes + coupon_excludes. $query_args = array( - 'after' => $current_hour->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $now->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), 'interval' => 'hour', 'status_is' => array( $order_status_1, @@ -2159,11 +2169,11 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { ), 'intervals' => array( array( - 'interval' => $current_hour->format( 'Y-m-d H' ), - 'date_start' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_start_gmt' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_end' => $now->format( 'Y-m-d H:i:s' ), - 'date_end_gmt' => $now->format( 'Y-m-d H:i:s' ), + 'interval' => $current_hour_start->format( 'Y-m-d H' ), + 'date_start' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_start_gmt' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_end' => $current_hour_end->format( 'Y-m-d H:i:s' ), + 'date_end_gmt' => $current_hour_end->format( 'Y-m-d H:i:s' ), 'subtotals' => array( 'orders_count' => $orders_count, 'num_items_sold' => $num_items_sold, @@ -2184,13 +2194,13 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'pages' => 1, 'page_no' => 1, ); - $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'No filters' ); + $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Query args: ' . print_r( $query_args, true ) . "; query: {$wpdb->last_query}" ); // Combinations: match any // status_is + status_is_not, all orders. $query_args = array( - 'after' => $current_hour->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $now->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), 'interval' => 'hour', 'match' => 'any', 'status_is' => array( @@ -2237,11 +2247,11 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { ), 'intervals' => array( array( - 'interval' => $current_hour->format( 'Y-m-d H' ), - 'date_start' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_start_gmt' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_end' => $now->format( 'Y-m-d H:i:s' ), - 'date_end_gmt' => $now->format( 'Y-m-d H:i:s' ), + 'interval' => $current_hour_start->format( 'Y-m-d H' ), + 'date_start' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_start_gmt' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_end' => $current_hour_end->format( 'Y-m-d H:i:s' ), + 'date_end_gmt' => $current_hour_end->format( 'Y-m-d H:i:s' ), 'subtotals' => array( 'orders_count' => $orders_count, 'num_items_sold' => $num_items_sold, @@ -2262,12 +2272,12 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'pages' => 1, 'page_no' => 1, ); - $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'No filters' ); + $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Query args: ' . print_r( $query_args, true ) . "; query: {$wpdb->last_query}" ); // status_is OR product_includes. $query_args = array( - 'after' => $current_hour->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $now->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), 'interval' => 'hour', 'match' => 'any', 'status_is' => array( @@ -2314,11 +2324,11 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { ), 'intervals' => array( array( - 'interval' => $current_hour->format( 'Y-m-d H' ), - 'date_start' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_start_gmt' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_end' => $now->format( 'Y-m-d H:i:s' ), - 'date_end_gmt' => $now->format( 'Y-m-d H:i:s' ), + 'interval' => $current_hour_start->format( 'Y-m-d H' ), + 'date_start' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_start_gmt' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_end' => $current_hour_end->format( 'Y-m-d H:i:s' ), + 'date_end_gmt' => $current_hour_end->format( 'Y-m-d H:i:s' ), 'subtotals' => array( 'orders_count' => $orders_count, 'num_items_sold' => $num_items_sold, @@ -2339,12 +2349,12 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'pages' => 1, 'page_no' => 1, ); - $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'No filters' ); + $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Query args: ' . print_r( $query_args, true ) . "; query: {$wpdb->last_query}" ); // status_is OR coupon_includes. $query_args = array( - 'after' => $current_hour->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $now->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), 'interval' => 'hour', 'match' => 'any', 'status_is' => array( @@ -2391,11 +2401,11 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { ), 'intervals' => array( array( - 'interval' => $current_hour->format( 'Y-m-d H' ), - 'date_start' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_start_gmt' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_end' => $now->format( 'Y-m-d H:i:s' ), - 'date_end_gmt' => $now->format( 'Y-m-d H:i:s' ), + 'interval' => $current_hour_start->format( 'Y-m-d H' ), + 'date_start' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_start_gmt' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_end' => $current_hour_end->format( 'Y-m-d H:i:s' ), + 'date_end_gmt' => $current_hour_end->format( 'Y-m-d H:i:s' ), 'subtotals' => array( 'orders_count' => $orders_count, 'num_items_sold' => $num_items_sold, @@ -2416,12 +2426,12 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'pages' => 1, 'page_no' => 1, ); - $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'No filters' ); + $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Query args: ' . print_r( $query_args, true ) . "; query: {$wpdb->last_query}" ); // status_is OR coupon_excludes. $query_args = array( - 'after' => $current_hour->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $now->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), 'interval' => 'hour', 'match' => 'any', 'status_is' => array( @@ -2468,11 +2478,11 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { ), 'intervals' => array( array( - 'interval' => $current_hour->format( 'Y-m-d H' ), - 'date_start' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_start_gmt' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_end' => $now->format( 'Y-m-d H:i:s' ), - 'date_end_gmt' => $now->format( 'Y-m-d H:i:s' ), + 'interval' => $current_hour_start->format( 'Y-m-d H' ), + 'date_start' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_start_gmt' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_end' => $current_hour_end->format( 'Y-m-d H:i:s' ), + 'date_end_gmt' => $current_hour_end->format( 'Y-m-d H:i:s' ), 'subtotals' => array( 'orders_count' => $orders_count, 'num_items_sold' => $num_items_sold, @@ -2493,12 +2503,12 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'pages' => 1, 'page_no' => 1, ); - $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'No filters' ); + $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Query args: ' . print_r( $query_args, true ) . "; query: {$wpdb->last_query}" ); // product_includes OR coupon_includes. $query_args = array( - 'after' => $current_hour->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $now->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), 'interval' => 'hour', 'match' => 'any', 'product_includes' => array( @@ -2545,11 +2555,11 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { ), 'intervals' => array( array( - 'interval' => $current_hour->format( 'Y-m-d H' ), - 'date_start' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_start_gmt' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_end' => $now->format( 'Y-m-d H:i:s' ), - 'date_end_gmt' => $now->format( 'Y-m-d H:i:s' ), + 'interval' => $current_hour_start->format( 'Y-m-d H' ), + 'date_start' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_start_gmt' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_end' => $current_hour_end->format( 'Y-m-d H:i:s' ), + 'date_end_gmt' => $current_hour_end->format( 'Y-m-d H:i:s' ), 'subtotals' => array( 'orders_count' => $orders_count, 'num_items_sold' => $num_items_sold, @@ -2570,12 +2580,12 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'pages' => 1, 'page_no' => 1, ); - $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'No filters' ); + $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Query args: ' . print_r( $query_args, true ) . "; query: {$wpdb->last_query}" ); // status_is OR product_includes OR coupon_includes. $query_args = array( - 'after' => $current_hour->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $now->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), 'interval' => 'hour', 'match' => 'any', 'status_is' => array( @@ -2625,11 +2635,11 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { ), 'intervals' => array( array( - 'interval' => $current_hour->format( 'Y-m-d H' ), - 'date_start' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_start_gmt' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_end' => $now->format( 'Y-m-d H:i:s' ), - 'date_end_gmt' => $now->format( 'Y-m-d H:i:s' ), + 'interval' => $current_hour_start->format( 'Y-m-d H' ), + 'date_start' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_start_gmt' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_end' => $current_hour_end->format( 'Y-m-d H:i:s' ), + 'date_end_gmt' => $current_hour_end->format( 'Y-m-d H:i:s' ), 'subtotals' => array( 'orders_count' => $orders_count, 'num_items_sold' => $num_items_sold, @@ -2650,12 +2660,12 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'pages' => 1, 'page_no' => 1, ); - $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'No filters' ); + $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Query args: ' . print_r( $query_args, true ) . "; query: {$wpdb->last_query}" ); // status_is OR status_is_not OR product_includes. $query_args = array( - 'after' => $current_hour->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $now->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), 'interval' => 'hour', 'match' => 'any', 'status_is' => array( @@ -2708,11 +2718,11 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { ), 'intervals' => array( array( - 'interval' => $current_hour->format( 'Y-m-d H' ), - 'date_start' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_start_gmt' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_end' => $now->format( 'Y-m-d H:i:s' ), - 'date_end_gmt' => $now->format( 'Y-m-d H:i:s' ), + 'interval' => $current_hour_start->format( 'Y-m-d H' ), + 'date_start' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_start_gmt' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_end' => $current_hour_end->format( 'Y-m-d H:i:s' ), + 'date_end_gmt' => $current_hour_end->format( 'Y-m-d H:i:s' ), 'subtotals' => array( 'orders_count' => $orders_count, 'num_items_sold' => $num_items_sold, @@ -2733,12 +2743,12 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'pages' => 1, 'page_no' => 1, ); - $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'No filters' ); + $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Query args: ' . print_r( $query_args, true ) . "; query: {$wpdb->last_query}" ); // status_is OR status_is_not OR product_includes OR product_excludes. $query_args = array( - 'after' => $current_hour->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $now->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), 'interval' => 'hour', 'match' => 'any', 'status_is' => array( @@ -2791,11 +2801,11 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { ), 'intervals' => array( array( - 'interval' => $current_hour->format( 'Y-m-d H' ), - 'date_start' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_start_gmt' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_end' => $now->format( 'Y-m-d H:i:s' ), - 'date_end_gmt' => $now->format( 'Y-m-d H:i:s' ), + 'interval' => $current_hour_start->format( 'Y-m-d H' ), + 'date_start' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_start_gmt' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_end' => $current_hour_end->format( 'Y-m-d H:i:s' ), + 'date_end_gmt' => $current_hour_end->format( 'Y-m-d H:i:s' ), 'subtotals' => array( 'orders_count' => $orders_count, 'num_items_sold' => $num_items_sold, @@ -2816,12 +2826,12 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'pages' => 1, 'page_no' => 1, ); - $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'No filters' ); + $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Query args: ' . print_r( $query_args, true ) . "; query: {$wpdb->last_query}" ); // status_is OR status_is_not OR product_includes OR product_excludes OR coupon_includes. $query_args = array( - 'after' => $current_hour->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $now->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), 'interval' => 'hour', 'match' => 'any', 'status_is' => array( @@ -2877,11 +2887,11 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { ), 'intervals' => array( array( - 'interval' => $current_hour->format( 'Y-m-d H' ), - 'date_start' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_start_gmt' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_end' => $now->format( 'Y-m-d H:i:s' ), - 'date_end_gmt' => $now->format( 'Y-m-d H:i:s' ), + 'interval' => $current_hour_start->format( 'Y-m-d H' ), + 'date_start' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_start_gmt' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_end' => $current_hour_end->format( 'Y-m-d H:i:s' ), + 'date_end_gmt' => $current_hour_end->format( 'Y-m-d H:i:s' ), 'subtotals' => array( 'orders_count' => $orders_count, 'num_items_sold' => $num_items_sold, @@ -2902,12 +2912,12 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'pages' => 1, 'page_no' => 1, ); - $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'No filters' ); + $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Query args: ' . print_r( $query_args, true ) . "; query: {$wpdb->last_query}" ); // status_is OR status_is_not OR product_includes OR product_excludes OR coupon_includes OR coupon_excludes. $query_args = array( - 'after' => $current_hour->format( WC_Admin_Reports_Interval::$sql_datetime_format ), - 'before' => $now->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'after' => $current_hour_start->format( WC_Admin_Reports_Interval::$sql_datetime_format ), + 'before' => $current_hour_end->format( WC_Admin_Reports_Interval::$sql_datetime_format ), 'interval' => 'hour', 'match' => 'any', 'status_is' => array( @@ -2966,11 +2976,11 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { ), 'intervals' => array( array( - 'interval' => $current_hour->format( 'Y-m-d H' ), - 'date_start' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_start_gmt' => $current_hour->format( 'Y-m-d H:i:s' ), - 'date_end' => $now->format( 'Y-m-d H:i:s' ), - 'date_end_gmt' => $now->format( 'Y-m-d H:i:s' ), + 'interval' => $current_hour_start->format( 'Y-m-d H' ), + 'date_start' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_start_gmt' => $current_hour_start->format( 'Y-m-d H:i:s' ), + 'date_end' => $current_hour_end->format( 'Y-m-d H:i:s' ), + 'date_end_gmt' => $current_hour_end->format( 'Y-m-d H:i:s' ), 'subtotals' => array( 'orders_count' => $orders_count, 'num_items_sold' => $num_items_sold, @@ -2991,7 +3001,7 @@ class WC_Tests_Reports_Orders_Stats extends WC_Unit_Test_Case { 'pages' => 1, 'page_no' => 1, ); - $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'No filters' ); + $this->assertEquals( $expected_stats, json_decode( json_encode( $data_store->get_data( $query_args ) ), true ), 'Query args: ' . print_r( $query_args, true ) . "; query: {$wpdb->last_query}" ); }