Skip to content

Commit

Permalink
Merge pull request #182 from taxjar/INT-1658-Specs-Fix
Browse files Browse the repository at this point in the history
Fixes for Test Suite
  • Loading branch information
dallendalton authored Mar 23, 2021
2 parents d97f952 + 7e6572f commit 5d76ced
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 43 deletions.
1 change: 1 addition & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function install_wc() {
update_option( 'woocommerce_status_options', array( 'uninstall_data' => 1 ) );
include $this->plugin_dir . 'woocommerce/uninstall.php';

do_action( 'wp_enqueue_scripts' );
WC_Install::install();

// Reload capabilities after install, see https://core.trac.wordpress.org/ticket/28374
Expand Down
62 changes: 22 additions & 40 deletions tests/framework/product-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,56 +38,38 @@ private static function create_simple_product( $opts = array() ) {

private static function create_subscription_product( $opts = array() ) {
$defaults = array(
'price' => '19.99',
'sku' => 'SUBSCRIPTION1',
'tax_class' => '',
'tax_status' => 'taxable',
'downloadable' => 'no',
'virtual' => 'yes',
'name' => 'Dummy Product',
'price' => '19.99',
'sku' => 'SUBSCRIPTION1',
'manage_stock' => false,
'tax_status' => 'taxable',
'downloadable' => false,
'virtual' => false,
'stock_status' => 'instock',
'weight' => '1.1',
'interval' => 1,
'period' => 'month',
'sign_up_fee' => 0,
'trial_length' => 1,
'trial_period' => 'month',
);

$post = array(
'post_title' => 'Dummy Subscription',
'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',
'subscription'
);

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' );
$props = array_replace_recursive( $defaults, $opts );
$props[ 'regular_price' ] = $props[ 'price' ];
$product = new WC_Product_Subscription();
$product->set_props( $props );
$product->save();
$product_id = $product->get_id();

// Subscription meta
update_post_meta( $post_id, '_subscription_price', $post_meta['price'] );
update_post_meta( $post_id, '_subscription_period_interval', $post_meta['interval'] );
update_post_meta( $post_id, '_subscription_period', $post_meta['period'] );
update_post_meta( $post_id, '_subscription_sign_up_fee', $post_meta['sign_up_fee'] );
update_post_meta( $post_id, '_subscription_trial_length', $post_meta['trial_length'] );
update_post_meta( $post_id, '_subscription_trial_period', $post_meta['trial_period'] );

wp_set_object_terms( $post_id, 'subscription', 'product_type' );
update_post_meta( $product_id, '_subscription_price', $props['price'] );
update_post_meta( $product_id, '_subscription_period_interval', $props['interval'] );
update_post_meta( $product_id, '_subscription_period', $props['period'] );
update_post_meta( $product_id, '_subscription_sign_up_fee', $props['sign_up_fee'] );
update_post_meta( $product_id, '_subscription_trial_length', $props['trial_length'] );
update_post_meta( $product_id, '_subscription_trial_period', $props['trial_period'] );

return new WC_Product_Subscription( $post_id );
return new WC_Product_Subscription( $product_id );
}

}
6 changes: 3 additions & 3 deletions tests/specs/test-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ function test_taxes_with_different_shipping_and_item_rates() {
WC()->cart->calculate_totals();

foreach ( WC()->cart->get_cart() as $cart_item_key => $item ) {
$this->assertEquals( $item['line_tax'], 0.36, '', 0.01 );
$this->assertEquals( $item['line_tax'], 0.58, '', 0.01 );
}

$this->assertEquals( WC()->cart->get_shipping_tax(), 0.63, '', 0.01 );
$this->assertEquals( WC()->cart->get_total_tax(), 0.99, '', 0.01 );
$this->assertEquals( WC()->cart->get_shipping_tax(), 0.69, '', 0.01 );
$this->assertEquals( WC()->cart->get_total_tax(), 1.27, '', 0.01 );
}

function test_correct_taxes_with_exempt_shipping() {
Expand Down

0 comments on commit 5d76ced

Please sign in to comment.