Update tests

This commit is contained in:
claudiulodro 2017-04-27 14:46:00 -07:00
parent 059389c684
commit 11c7722eff
4 changed files with 60 additions and 29 deletions

View File

@ -646,6 +646,7 @@ class WC_Order_Data_Store_CPT extends Abstract_WC_Order_Data_Store_CPT implement
$key_mapping = array(
'customer_id' => 'customer_user',
'status' => 'post_status',
);
foreach( $key_mapping as $query_key => $db_key ) {
@ -656,7 +657,8 @@ class WC_Order_Data_Store_CPT extends Abstract_WC_Order_Data_Store_CPT implement
}
$wp_query_args = parent::get_wp_query_args( $query_vars );
if ( ! isset( $wp_query_args['date_query' ) ) {
if ( ! isset( $wp_query_args['date_query'] ) ) {
$wp_query_args['date_query'] = array();
}
if ( ! isset( $wp_query_args['meta_query'] ) ) {

View File

@ -67,28 +67,6 @@ class WC_Tests_Data_Store extends WC_Unit_Test_Case {
$this->assertEquals( 'WC_Dummy_Data_Store_CPT', $store->get_current_class_name() );
}
/**
* Test converting WP_Object_Query query vars to WP_Query args.
*
* @since 3.1.0
*/
function test_get_wp_query_args() {
$store = new WC_Data_Store_WP();
$query = new WC_Mock_WC_Object_Query( array(
'parent__in' => array( 1 ),
'status' => 'publish',
'somethingelse' => 'value',
'ignored' => '',
) );
$args = $store->get_wp_query_args( $query->query_vars );
$this->assertEquals( array( 1 ), $args['post_parent__in'] );
$this->assertEquals( 'publish', $args['post_status'] );
$this->assertEquals( 'value', $args['somethingelse'] );
$this->assertFalse( isset( $args['ignored'] ) );
}
/* Helper Functions. */
/**

View File

@ -15,7 +15,7 @@ class WC_Tests_WC_Object_Query extends WC_Unit_Test_Case {
function test_default_query() {
$query = new WC_Mock_WC_Object_Query();
$this->assertNotEmpty( $query->query_vars );
$this->assertNotEmpty( $query->get_query_vars() );
$this->assertEquals( '', $query->get( 'parent' ) );
$this->assertEquals( 'date', $query->get( 'orderby' ) );
}
@ -27,12 +27,12 @@ class WC_Tests_WC_Object_Query extends WC_Unit_Test_Case {
*/
function test_query_with_args() {
$args = array(
'per_page' => 15
'limit' => 15
);
$query = new WC_Mock_WC_Object_Query( $args );
$this->assertEquals( 15, $query->get( 'per_page' ) );
$query->set( 'per_page', 20 );
$this->assertEquals( 20, $query->get( 'per_page' ) );
$this->assertEquals( 15, $query->get( 'limit' ) );
$query->set( 'limit', 20 );
$this->assertEquals( 20, $query->get( 'limit' ) );
}
}

View File

@ -56,11 +56,62 @@ class WC_Tests_WC_Order_Query extends WC_Unit_Test_Case {
$this->assertEquals( 2, count( $results ) );
// Limit to one result.
$query->set( 'per_page', 1 );
$query->set( 'limit', 1 );
$results = $query->get_orders();
$this->assertEquals( 1, count( $results ) );
}
/**
* Test querying by order date properties.
*
* @since 3.1
*/
public function test_order_query_date_queries() {
$now = current_time( 'mysql', true );
$now_stamp = strtotime( $now );
$past = date( DATE_ISO8601, $now_stamp - 1000 );
$future = date( DATE_ISO8601, $now_stamp + 1000 );
$order = new WC_Order();
$order->set_date_completed( $now_stamp );
$order->save();
// 'date_created_after' should get orders created after the specified time.
$query = new WC_Order_Query( array(
'date_created_after' => $past
) );
$orders = $query->get_orders();
$this->assertEquals( 1, count( $orders ) );
// 'date_created_after' should exclude orders created before the specified time.
$query->set( 'date_created_after', $future );
$orders = $query->get_orders();
$this->assertEquals( 0, count( $orders ) );
// 'date_created_before' should get orders created before the specified time.
$query = new WC_Order_Query( array(
'date_created_before' => $future
) );
$orders = $query->get_orders();
$this->assertEquals( 1, count( $orders ) );
// 'date_created_before' should get orders created before the specified time.
$query->set( 'date_created_before', $future );
$orders = $query->get_orders();
$this->assertEquals( 1, count( $orders ) );
// Test with some metadata-stored date params.
$query = new WC_Order_Query( array(
'date_completed_after' => $past
) );
$orders = $query->get_orders();
$this->assertEquals( 1, count( $orders ) );
$query->set( 'date_completed_after', $future );
$orders = $query->get_orders();
$this->assertEquals( 0, count( $orders ) );
}
/**
* Test the query var mapping customer_id => customer_user.
*