Add wc_get_order() tests + Order helper class

This commit is contained in:
JeroenSormani 2015-05-23 10:48:07 +02:00
parent be0f93f112
commit b95b22d144
3 changed files with 33 additions and 0 deletions

View File

@ -25,6 +25,8 @@ class WC_Order_Factory {
$the_order = $post;
} elseif ( is_numeric( $the_order ) ) {
$the_order = get_post( $the_order );
} elseif ( $the_order instanceof WC_Order ) {
$the_order = get_post( $the_order->id );
}
if ( ! $the_order || ! is_object( $the_order ) ) {

View File

@ -101,6 +101,7 @@ class WC_Unit_Tests_Bootstrap {
require_once( $this->tests_dir . '/framework/helpers/class-wc-helper-fee.php' );
require_once( $this->tests_dir . '/framework/helpers/class-wc-helper-shipping.php' );
require_once( $this->tests_dir . '/framework/helpers/class-wc-helper-customer.php' );
require_once( $this->tests_dir . '/framework/helpers/class-wc-helper-order.php' );
}
/**

View File

@ -68,4 +68,34 @@ class Functions extends \WC_Unit_Test_Case {
update_option( 'woocommerce_ship_to_destination', $default );
}
/**
* Test wc_get_order()
*
* @since 2.4.0
* @group test
*/
public function test_wc_get_order() {
$order = \WC_Helper_Order::create_order();
// Assert that $order is a WC_Order object
$this->assertInstanceOf( 'WC_Order', $order );
// Assert that wc_get_order() accepts a WC_Order object
$this->assertInstanceOf( 'WC_Order', wc_get_order( $order ) );
// Assert that wc_get_order() accepts a order post id.
$this->assertInstanceOf( 'WC_Order', wc_get_order( $order->id ) );
// Assert that a non-shop_order post returns false
$post = $this->factory->post->create_and_get( array( 'post_type' => 'post' ) );
$this->assertFalse( wc_get_order( $post->ID ) );
// Assert the return when $the_order args is false
$this->assertFalse( wc_get_order( false ) );
// Assert the return when $the_order args is a random (incorrect) id.
$this->assertFalse( wc_get_order( 123456 ) );
}
}