Update tests to use subtotal as a basis for the discounts.

This commit is contained in:
Mike Jolley 2018-02-27 18:57:28 +00:00
parent a6431c86d3
commit 6b722e1120
1 changed files with 24 additions and 15 deletions

View File

@ -19,7 +19,7 @@ class WC_Tests_Order_Coupons extends WC_Unit_Test_Case {
public function setUp() {
$this->delete_objects();
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1'; // @codingStandardsIgnoreLine.
update_option( 'woocommerce_default_customer_address', 'base' );
update_option( 'woocommerce_tax_based_on', 'base' );
@ -29,13 +29,13 @@ class WC_Tests_Order_Coupons extends WC_Unit_Test_Case {
update_post_meta( $product->get_id(), '_price', '1000' );
$product = wc_get_product( $product->get_id() );
$coupon = new WC_Coupon;
$coupon = new WC_Coupon();
$coupon->set_code( 'test-coupon-1' );
$coupon->set_amount( 1.00 );
$coupon->set_discount_type( 'fixed_cart' );
$coupon->save();
$coupon2 = new WC_Coupon;
$coupon2 = new WC_Coupon();
$coupon2->set_code( 'test-coupon-2' );
$coupon2->set_amount( 20 );
$coupon2->set_discount_type( 'percent' );
@ -159,7 +159,7 @@ class WC_Tests_Order_Coupons extends WC_Unit_Test_Case {
/**
* Test: test_remove_coupon_from_order
*/
function test_remove_coupon_from_order() {
public function test_remove_coupon_from_order() {
update_option( 'woocommerce_prices_include_tax', 'yes' );
update_option( 'woocommerce_calc_taxes', 'yes' );
$this->setUp();
@ -199,7 +199,7 @@ class WC_Tests_Order_Coupons extends WC_Unit_Test_Case {
/**
* Test: test_add_coupon_to_order
*/
function test_add_coupon_to_order() {
public function test_add_coupon_to_order() {
update_option( 'woocommerce_prices_include_tax', 'yes' );
update_option( 'woocommerce_calc_taxes', 'yes' );
$this->setUp();
@ -207,14 +207,22 @@ class WC_Tests_Order_Coupons extends WC_Unit_Test_Case {
$order_id = $this->objects['order']->get_id();
$order = wc_get_order( $order_id );
$this->assertEquals( '799', $order->get_total(), $order->get_total() );
/**
* Discount should be based on subtotal unless coupons apply sequencially.
*
* Coupon will therefore discount 200. Compare the total without tax so we can compare the ex tax price and avoid rounding mishaps.
*/
$order->apply_coupon( 'test-coupon-2' );
$this->assertEquals( '639.2', $order->get_total(), $order->get_total() );
$this->assertEquals( 401, round( $order->get_total_discount( false ), 2 ), $order->get_total_discount( false ) );
$this->assertEquals( 598.99, $order->get_total(), $order->get_total() );
}
/**
* Test: test_remove_coupon_from_order_ex_tax
*/
function test_remove_coupon_from_order_ex_tax() {
public function test_remove_coupon_from_order_ex_tax() {
update_option( 'woocommerce_prices_include_tax', 'no' );
update_option( 'woocommerce_calc_taxes', 'yes' );
$this->setUp();
@ -254,7 +262,7 @@ class WC_Tests_Order_Coupons extends WC_Unit_Test_Case {
/**
* Test: test_add_coupon_to_order_ex_tax
*/
function test_add_coupon_to_order_ex_tax() {
public function test_add_coupon_to_order_ex_tax() {
update_option( 'woocommerce_prices_include_tax', 'no' );
update_option( 'woocommerce_calc_taxes', 'yes' );
$this->setUp();
@ -263,13 +271,14 @@ class WC_Tests_Order_Coupons extends WC_Unit_Test_Case {
$order = wc_get_order( $order_id );
$order->apply_coupon( 'test-coupon-2' );
$this->assertEquals( '703.12', $order->get_total(), $order->get_total() );
$this->assertEquals( 401, $order->get_discount_total(), $order->get_discount_total() );
$this->assertEquals( ( 1000 - 401 ) * 1.1, $order->get_total(), $order->get_total() );
}
/**
* Test: test_remove_coupon_from_order_no_tax
*/
function test_remove_coupon_from_order_no_tax() {
public function test_remove_coupon_from_order_no_tax() {
update_option( 'woocommerce_prices_include_tax', 'no' );
update_option( 'woocommerce_calc_taxes', 'no' );
$this->setUp();
@ -309,7 +318,7 @@ class WC_Tests_Order_Coupons extends WC_Unit_Test_Case {
/**
* Test: test_add_coupon_to_order_no_tax
*/
function test_add_coupon_to_order_no_tax() {
public function test_add_coupon_to_order_no_tax() {
update_option( 'woocommerce_prices_include_tax', 'no' );
update_option( 'woocommerce_calc_taxes', 'no' );
$this->setUp();
@ -318,13 +327,13 @@ class WC_Tests_Order_Coupons extends WC_Unit_Test_Case {
$order = wc_get_order( $order_id );
$order->apply_coupon( 'test-coupon-2' );
$this->assertEquals( '639.2', $order->get_total(), $order->get_total() );
$this->assertEquals( '599', $order->get_total(), $order->get_total() );
}
/**
* Test: test_remove_coupon_from_order_no_tax
*/
function test_remove_coupon_from_order_no_tax_inc_prices_on() {
public function test_remove_coupon_from_order_no_tax_inc_prices_on() {
update_option( 'woocommerce_prices_include_tax', 'yes' );
update_option( 'woocommerce_calc_taxes', 'no' );
$this->setUp();
@ -364,7 +373,7 @@ class WC_Tests_Order_Coupons extends WC_Unit_Test_Case {
/**
* Test: test_add_coupon_to_order_no_tax
*/
function test_add_coupon_to_order_no_tax_inc_prices_on() {
public function test_add_coupon_to_order_no_tax_inc_prices_on() {
update_option( 'woocommerce_prices_include_tax', 'yes' );
update_option( 'woocommerce_calc_taxes', 'no' );
$this->setUp();
@ -373,6 +382,6 @@ class WC_Tests_Order_Coupons extends WC_Unit_Test_Case {
$order = wc_get_order( $order_id );
$order->apply_coupon( 'test-coupon-2' );
$this->assertEquals( '639.2', $order->get_total(), $order->get_total() );
$this->assertEquals( '599', $order->get_total(), $order->get_total() );
}
}