Skip to content
This repository was archived by the owner on Jun 15, 2022. It is now read-only.

Commit 7d3c80b

Browse files
committed
Add tests for WC_Order_Data_Store_Custom_Table::create()
1 parent 574d7af commit 7d3c80b

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

tests/test-data-store.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88

99
class DataStoreTest extends TestCase {
1010

11+
/**
12+
* Fire the necessary actions to bootstrap WordPress.
13+
*
14+
* @before
15+
*/
16+
public function init() {
17+
do_action( 'init' );
18+
}
19+
1120
/**
1221
* Remove any closures that have been assigned to filters.
1322
*
@@ -17,6 +26,20 @@ public function remove_filter_callbacks() {
1726
remove_all_filters( 'woocommerce_shop_order_search_fields' );
1827
}
1928

29+
public function test_create() {
30+
$instance = new WC_Order_Data_Store_Custom_Table();
31+
$order = $this->factory()->order->create_and_get();
32+
$order_key = 'my_custom_order_key';
33+
34+
add_filter( 'woocommerce_generate_order_key', function () use ( $order_key ) {
35+
return $order_key;
36+
} );
37+
38+
$instance->create( $order );
39+
40+
$this->assertEquals( 'wc_' . $order_key, $order->get_order_key() );
41+
}
42+
2043
public function test_get_order_count() {
2144
$orders = $this->factory()->order->create_many( 5, array(
2245
'post_status' => 'wc-pending',
@@ -107,7 +130,7 @@ public function test_search_orders_only_checks_post_meta_if_specified() {
107130
* @dataProvider order_type_provider()
108131
*/
109132
public function test_get_order_type( $order_type ) {
110-
$order = $this->factory()->order->create_and_get( array(
133+
$order = $this->factory()->order->create( array(
111134
'post_type' => $order_type,
112135
) );
113136

tests/test-tools/class-wp-unittest-factory-for-order.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,8 @@ function __construct( $factory = null ) {
2121
'post_type' => 'shop_order',
2222
);
2323
}
24+
25+
function get_object_by_id( $order_id ) {
26+
return wc_get_order( $order_id );
27+
}
2428
}

tests/test-tools/class-wp-unittest-factory-for-product.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,8 @@ function __construct( $factory = null ) {
2222
'post_type' => 'post',
2323
);
2424
}
25+
26+
function get_object_by_id( $product_id ) {
27+
return wc_get_product( $product_id );
28+
}
2529
}

0 commit comments

Comments
 (0)