diff --git a/plugins/woocommerce-admin/includes/class-wc-admin-reports-interval.php b/plugins/woocommerce-admin/includes/class-wc-admin-reports-interval.php index 0ee5ec2316e..27e576e6065 100644 --- a/plugins/woocommerce-admin/includes/class-wc-admin-reports-interval.php +++ b/plugins/woocommerce-admin/includes/class-wc-admin-reports-interval.php @@ -170,11 +170,29 @@ class WC_Admin_Reports_Interval { switch ( $interval ) { case 'hour': - $diff_timestamp = (int) $end_datetime->format( 'U' ) - (int) $start_datetime->format( 'U' ); - return (int) floor( ( (int) $diff_timestamp ) / HOUR_IN_SECONDS ) + 1; + $end_timestamp = (int) $end_datetime->format( 'U' ); + $start_timestamp = (int) $start_datetime->format( 'U' ); + $addendum = 0; + $end_min_sec = $end_timestamp % HOUR_IN_SECONDS; + $start_min_sec = $start_timestamp % HOUR_IN_SECONDS; + if ( $end_min_sec < $start_min_sec ) { + $addendum = 1; + } + $diff_timestamp = $end_timestamp - $start_timestamp; + + return (int) floor( ( (int) $diff_timestamp ) / HOUR_IN_SECONDS ) + 1 + $addendum; case 'day': - $diff_timestamp = (int) $end_datetime->format( 'U' ) - (int) $start_datetime->format( 'U' ); - return (int) floor( ( (int) $diff_timestamp ) / DAY_IN_SECONDS ) + 1; + $end_timestamp = (int) $end_datetime->format( 'U' ); + $start_timestamp = (int) $start_datetime->format( 'U' ); + $addendum = 0; + $end_hour_min_sec = $end_timestamp % DAY_IN_SECONDS; + $start_hour_min_sec = $start_timestamp % DAY_IN_SECONDS; + if ( $end_hour_min_sec < $start_hour_min_sec ) { + $addendum = 1; + } + $diff_timestamp = $end_timestamp - $start_timestamp; + + return (int) floor( ( (int) $diff_timestamp ) / DAY_IN_SECONDS ) + 1 + $addendum; case 'week': // TODO: optimize? approximately day count / 7, but year end is tricky, a week can have fewer days. $week_count = 0; diff --git a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-data-store.php b/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-data-store.php index 4b770373ba6..834229c059b 100644 --- a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-data-store.php +++ b/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-data-store.php @@ -297,13 +297,15 @@ class WC_Admin_Reports_Data_Store { $new_end_date = clone $new_start_date; for ( $i = 0; $i < $intervals_query['per_page']; $i++ ) { if ( $new_end_date > $latest_end_date ) { - $new_end_date = $latest_end_date; - $end_iteration = 0; break; } $new_end_date = WC_Admin_Reports_Interval::iterate( $new_end_date, $query_args['interval'] ); $end_iteration ++; } + if ( $new_end_date > $latest_end_date ) { + $new_end_date = $latest_end_date; + $end_iteration = 0; + } if ( $end_iteration ) { $new_end_date_timestamp = (int) $new_end_date->format( 'U' ) - 1; $new_end_date->setTimestamp( $new_end_date_timestamp ); @@ -326,13 +328,15 @@ class WC_Admin_Reports_Data_Store { $new_start_date = clone $new_end_date; for ( $i = 0; $i < $intervals_query['per_page']; $i++ ) { if ( $new_start_date < $earliest_start_date ) { - $new_start_date = $earliest_start_date; - $start_iteration = 0; break; } $new_start_date = WC_Admin_Reports_Interval::iterate( $new_start_date, $query_args['interval'], true ); $start_iteration ++; } + if ( $new_start_date < $earliest_start_date ) { + $new_start_date = $earliest_start_date; + $start_iteration = 0; + } if ( $start_iteration ) { // TODO: is this correct? should it only be added if iterate runs? other two iterate instances, too? $new_start_date_timestamp = (int) $new_start_date->format( 'U' ) + 1; diff --git a/plugins/woocommerce-admin/tests/api/reports-interval.php b/plugins/woocommerce-admin/tests/api/reports-interval.php index 3334e5b2721..566153a0796 100644 --- a/plugins/woocommerce-admin/tests/api/reports-interval.php +++ b/plugins/woocommerce-admin/tests/api/reports-interval.php @@ -419,14 +419,28 @@ class WC_Tests_Reports_Interval_Stats extends WC_Unit_Test_Case { 'year' => 1, ), ), - // 23:59:59 h:m:s interval -> 24 hours, 1 for the rest + // 8.0186111 hours interval length -> 10 hours, 2 days, 1 for the rest + array( + 'start' => '2019-01-16T16:59:00Z', + 'end' => '2019-01-17T01:00:07Z', + 'week_start' => 1, + 'intervals' => array( + 'hour' => 10, + 'day' => 2, + 'week' => 1, + 'month' => 1, + 'quarter' => 1, + 'year' => 1, + ), + ), + // 23:59:59 h:m:s interval -> 24 hours, 2 days, 1 for the rest array( 'start' => '2017-12-24T11:00:00Z', 'end' => '2017-12-25T10:59:59Z', 'week_start' => 1, 'intervals' => array( 'hour' => 24, - 'day' => 1, + 'day' => 2, 'week' => 2, 'month' => 1, 'quarter' => 1, @@ -475,42 +489,42 @@ class WC_Tests_Reports_Interval_Stats extends WC_Unit_Test_Case { 'year' => 1, ), ), - // 1 month + 14 hour interval spanning 2 months in 1 quarter -> 735 hours, 31 days, 6 iso weeks, 2 months + // 1 month + 14 hour interval spanning 2 months in 1 quarter -> 735 hours, 32 days, 6 iso weeks, 2 months array( 'start' => '2017-11-24T11:00:00Z', 'end' => '2017-12-25T01:00:00Z', 'week_start' => 1, 'intervals' => array( - 'hour' => 30 * 24 + 14 + 1, // 30 full days + 14 full hours + 1 second from next hour - 'day' => 31, + 'hour' => 30 * 24 + 13 + 2, // 30 full days + 13 full hours on Nov 24 + 2 hours on Dec 25 + 'day' => 32, 'week' => 6, 'month' => 2, 'quarter' => 1, 'year' => 1, ), ), - // 1 month interval spanning 2 months and 2 quarters, 1 year -> 720 hours, 30 days, 6 iso weeks, 2 months, 2 q, 1 y + // 1 month interval spanning 2 months and 2 quarters, 1 year -> 720 hours, 31 days, 6 iso weeks, 2 months, 2 q, 1 y array( 'start' => '2017-09-24T11:00:00Z', 'end' => '2017-10-24T10:59:59Z', 'week_start' => 1, 'intervals' => array( 'hour' => 30 * 24, - 'day' => 30, // Sept has 30 days. + 'day' => 31, // Sept has 30 days, but need to include interval for half of Sept 24 and interval for half of Oct 24. 'week' => 6, 'month' => 2, 'quarter' => 2, 'year' => 1, ), ), - // 1 month interval spanning 2 months and 2 quarters, 2 years -> 744 hours, 30 days, 5 iso weeks, 2 months, 2 quarters, 2 years + // 1 month interval spanning 2 months and 2 quarters, 2 years -> 744 hours, 32 days, 6 iso weeks, 2 months, 2 quarters, 2 years array( 'start' => '2017-12-24T11:00:00Z', 'end' => '2018-01-24T10:59:59Z', 'week_start' => 1, 'intervals' => array( 'hour' => 31 * 24, - 'day' => 31, // Dec has 31 days. + 'day' => 32, // Dec has 31 days, plus 1 interval for half day at the end. 'week' => 6, 'month' => 2, 'quarter' => 2, @@ -587,7 +601,7 @@ class WC_Tests_Reports_Interval_Stats extends WC_Unit_Test_Case { foreach ( $test_settings as $setting ) { update_option( 'start_of_week', $setting['week_start'] ); foreach ( $setting['intervals'] as $interval => $exp_value ) { - $this->assertEquals( $exp_value, WC_Admin_Reports_Interval::intervals_between( $setting['start'], $setting['end'], $interval ), "FDoW: {$setting['week_start']}; Start: {$setting['start']}; End: {$setting['end']}; Interval: {$interval}" ); + $this->assertEquals( $exp_value, WC_Admin_Reports_Interval::intervals_between( $setting['start'], $setting['end'], $interval ), "First Day of Week: {$setting['week_start']}; Start: {$setting['start']}; End: {$setting['end']}; Interval: {$interval}" ); } } } 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}" ); }