diff --git a/tests/framework/product-helper.php b/tests/framework/product-helper.php index 3dab2ae0..f09e0e64 100644 --- a/tests/framework/product-helper.php +++ b/tests/framework/product-helper.php @@ -12,49 +12,28 @@ public static function create_product( $type = 'simple', $opts = array() ) { private static function create_simple_product( $opts = array() ) { $defaults = array( - 'price' => '10', - 'sku' => 'SIMPLE1', - 'tax_class' => '', - 'tax_status' => 'taxable', - 'downloadable' => 'no', - 'virtual' => 'no', + 'name' => 'Dummy Product', + 'price' => 10, + 'sku' => 'SIMPLE1', + 'manage_stock' => false, + 'tax_status' => 'taxable', + 'downloadable' => false, + 'virtual' => false, + 'stock_status' => 'instock', + 'weight' => '1.1', ); - $post = array( - 'post_title' => 'Dummy Product', - 'post_type' => 'product', - 'post_status' => 'publish', - ); - $post_meta = array_replace_recursive( $defaults, $opts ); - $post_meta['regular_price'] = $post_meta['price']; - - $post_id = wp_insert_post( $post ); - - register_taxonomy( - 'product_type', - 'product' - ); + $props = array_replace_recursive( $defaults, $opts ); + $props[ 'regular_price' ] = $props[ 'price' ]; + $product = new WC_Product_Simple(); + $product->set_props( $props ); - update_post_meta( $post_id, '_price', $post_meta['price'] ); - update_post_meta( $post_id, '_regular_price', $post_meta['regular_price'] ); - update_post_meta( $post_id, '_sale_price', '' ); - update_post_meta( $post_id, '_sku', $post_meta['sku'] ); - update_post_meta( $post_id, '_manage_stock', 'no' ); - update_post_meta( $post_id, '_tax_class', $post_meta['tax_class'] ); - update_post_meta( $post_id, '_tax_status', $post_meta['tax_status'] ); - update_post_meta( $post_id, '_downloadable', $post_meta['downloadable'] ); - update_post_meta( $post_id, '_virtual', $post_meta['virtual'] ); - update_post_meta( $post_id, '_stock_status', 'instock' ); - - wp_set_object_terms( $post_id, 'simple', 'product_type' ); - - $products = get_posts( array( - 'post_type' => 'product', - '_sku' => $post_meta['sku'], - ) ); + if ( ! empty( $opts[ 'tax_class' ] ) ) { + $product->set_tax_class( $opts[ 'tax_class' ] ); + } - $factory = new WC_Product_Factory(); - return $factory->get_product( $products[0]->ID ); + $product->save( ); + return wc_get_product( $product->get_id() ); } private static function create_subscription_product( $opts = array() ) { diff --git a/tests/framework/woocommerce-helper.php b/tests/framework/woocommerce-helper.php index 333b8879..29433836 100644 --- a/tests/framework/woocommerce-helper.php +++ b/tests/framework/woocommerce-helper.php @@ -33,6 +33,10 @@ public static function prepare_woocommerce() { // WooCommerce 3.2 checks for a valid class update_option( 'woocommerce_tax_classes', "Reduced rate\nZero Rate\nClothing Rate - 20010" ); + if ( version_compare( WC()->version, '3.7.0', '>=' ) ) { + WC_Tax::create_tax_class( 'Clothing Rate - 20010' ); + } + // Allow calculate_totals to run in specs for WooCommerce < 3.2 if ( ! defined( 'WOOCOMMERCE_CART' ) ) { define( 'WOOCOMMERCE_CART', true ); diff --git a/tests/specs/test-class-subscriptions.php b/tests/specs/test-class-subscriptions.php index f8cb5732..c444fd42 100644 --- a/tests/specs/test-class-subscriptions.php +++ b/tests/specs/test-class-subscriptions.php @@ -477,7 +477,7 @@ function test_correct_taxes_for_subscription_recurring_order_with_trial_and_sign TaxJar_Shipping_Helper::delete_simple_flat_rate(); } - + function test_correct_taxes_for_subscription_recurring_order_with_multiple_products() { wp_set_current_user( $this->user );