Improve tests
This commit is contained in:
parent
c6c6a1e4b3
commit
827d133cb2
|
@ -1768,7 +1768,7 @@ class WC_Cart extends WC_Legacy_Cart {
|
||||||
* @return string formatted price
|
* @return string formatted price
|
||||||
*/
|
*/
|
||||||
public function get_total_ex_tax() {
|
public function get_total_ex_tax() {
|
||||||
return apply_filters( 'woocommerce_cart_total_ex_tax', wc_price( max( 0, $this->get_total( 'edit' ) - $this->get_cart_contents_tax() - $this->get_shipping_tax() - $this->get_fee_tax() ) ) );
|
return apply_filters( 'woocommerce_cart_total_ex_tax', wc_price( max( 0, $this->get_total( 'edit' ) - $this->get_total_tax() ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -504,37 +504,50 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
|
||||||
* @since 2.3
|
* @since 2.3
|
||||||
*/
|
*/
|
||||||
public function test_get_total_ex_tax() {
|
public function test_get_total_ex_tax() {
|
||||||
|
global $wpdb;
|
||||||
|
|
||||||
// Set calc taxes option
|
// Set calc taxes option.
|
||||||
update_option( 'woocommerce_calc_taxes', 'yes' );
|
update_option( 'woocommerce_calc_taxes', 'yes' );
|
||||||
|
$tax_rate = array(
|
||||||
|
'tax_rate_country' => '',
|
||||||
|
'tax_rate_state' => '',
|
||||||
|
'tax_rate' => '10.0000',
|
||||||
|
'tax_rate_name' => 'TAX',
|
||||||
|
'tax_rate_priority' => '1',
|
||||||
|
'tax_rate_compound' => '0',
|
||||||
|
'tax_rate_shipping' => '1',
|
||||||
|
'tax_rate_order' => '1',
|
||||||
|
'tax_rate_class' => '',
|
||||||
|
);
|
||||||
|
WC_Tax::_insert_tax_rate( $tax_rate );
|
||||||
|
|
||||||
// Create dummy product
|
// Create dummy product.
|
||||||
$product = WC_Helper_Product::create_simple_product();
|
$product = WC_Helper_Product::create_simple_product();
|
||||||
|
|
||||||
// We need this to have the calculate_totals() method calculate totals
|
// We need this to have the calculate_totals() method calculate totals.
|
||||||
if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) {
|
if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) {
|
||||||
define( 'WOOCOMMERCE_CHECKOUT', true );
|
define( 'WOOCOMMERCE_CHECKOUT', true );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add product to cart
|
// Add 10 fee.
|
||||||
|
WC_Helper_Fee::add_cart_fee( 'taxed' );
|
||||||
|
|
||||||
|
// Add product to cart (10).
|
||||||
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
WC()->cart->add_to_cart( $product->get_id(), 1 );
|
||||||
|
|
||||||
// Calc total
|
// Check.
|
||||||
$total = WC()->cart->total - WC()->cart->tax_total - WC()->cart->shipping_tax_total;
|
$this->assertEquals( wc_price( 22 ), WC()->cart->get_total() );
|
||||||
if ( $total < 0 ) {
|
$this->assertEquals( wc_price( 20 ), WC()->cart->get_total_ex_tax() );
|
||||||
$total = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check
|
// Clean up the cart.
|
||||||
$this->assertEquals( apply_filters( 'woocommerce_cart_total_ex_tax', wc_price( $total ) ), WC()->cart->get_total_ex_tax() );
|
|
||||||
|
|
||||||
// Clean up the cart
|
|
||||||
WC()->cart->empty_cart();
|
WC()->cart->empty_cart();
|
||||||
|
|
||||||
// Clean up product
|
// Clean up product.
|
||||||
WC_Helper_Product::delete_product( $product->get_id() );
|
WC_Helper_Product::delete_product( $product->get_id() );
|
||||||
|
|
||||||
// Restore option
|
// Restore option.
|
||||||
|
$wpdb->query( "DELETE FROM {$wpdb->prefix}woocommerce_tax_rates" );
|
||||||
|
$wpdb->query( "DELETE FROM {$wpdb->prefix}woocommerce_tax_rate_locations" );
|
||||||
update_option( 'woocommerce_calc_taxes', 'no' );
|
update_option( 'woocommerce_calc_taxes', 'no' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue