No tax tests

This commit is contained in:
Mike Jolley 2017-08-29 12:32:02 +01:00
parent dc9c14d574
commit fb64e77f24
1 changed files with 83 additions and 16 deletions

View File

@ -17,11 +17,10 @@ class WC_Tests_Order_Coupons extends WC_Unit_Test_Case {
* Setup an order.
*/
public function setUp() {
$this->objects = array();
$this->delete_objects();
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
update_option( 'woocommerce_calc_taxes', 'yes' );
update_option( 'woocommerce_default_customer_address', 'base' );
update_option( 'woocommerce_tax_based_on', 'base' );
@ -54,7 +53,7 @@ class WC_Tests_Order_Coupons extends WC_Unit_Test_Case {
$coupon_item_1 = new WC_Order_Item_Coupon();
$coupon_item_2 = new WC_Order_Item_Coupon();
if ( get_option( 'woocommerce_prices_include_tax', 'no' ) === 'yes' ) {
if ( get_option( 'woocommerce_prices_include_tax', 'no' ) === 'yes' && get_option( 'woocommerce_calc_taxes', 'no' ) === 'yes' ) {
$product_item->set_props( array(
'product' => $product,
'quantity' => 1,
@ -123,19 +122,34 @@ class WC_Tests_Order_Coupons extends WC_Unit_Test_Case {
*/
public function tearDown() {
update_option( 'woocommerce_calc_taxes', 'no' );
update_option( 'woocommerce_prices_include_tax', 'no' );
$this->delete_objects();
}
foreach ( $this->objects['coupons'] as $object ) {
$object->delete( true );
/**
* delete objects.
*/
protected function delete_objects() {
if ( isset( $this->objects['coupons'] ) ) {
foreach ( $this->objects['coupons'] as $object ) {
$object->delete( true );
}
}
foreach ( $this->objects['products'] as $object ) {
$object->delete( true );
if ( isset( $this->objects['products'] ) ) {
foreach ( $this->objects['products'] as $object ) {
$object->delete( true );
}
}
$this->objects['order']->delete( true );
if ( isset( $this->objects['order'] ) ) {
$this->objects['order']->delete( true );
}
foreach ( $this->objects['tax_rate_ids'] as $tax_rate_id ) {
WC_Tax::_delete_tax_rate( $tax_rate_id );
if ( isset( $this->objects['tax_rate_ids'] ) ) {
foreach ( $this->objects['tax_rate_ids'] as $tax_rate_id ) {
WC_Tax::_delete_tax_rate( $tax_rate_id );
}
}
$this->objects = array();
@ -147,7 +161,7 @@ class WC_Tests_Order_Coupons extends WC_Unit_Test_Case {
*/
function test_remove_coupon_from_order() {
update_option( 'woocommerce_prices_include_tax', 'yes' );
$this->tearDown();
update_option( 'woocommerce_calc_taxes', 'yes' );
$this->setUp();
$order_id = $this->objects['order']->get_id();
@ -166,7 +180,6 @@ class WC_Tests_Order_Coupons extends WC_Unit_Test_Case {
$this->assertEquals( '1000', $order->get_total(), $order->get_total() );
// Reset.
$this->tearDown();
$this->setUp();
$order_id = $this->objects['order']->get_id();
@ -188,7 +201,7 @@ class WC_Tests_Order_Coupons extends WC_Unit_Test_Case {
*/
function test_add_coupon_to_order() {
update_option( 'woocommerce_prices_include_tax', 'yes' );
$this->tearDown();
update_option( 'woocommerce_calc_taxes', 'yes' );
$this->setUp();
$order_id = $this->objects['order']->get_id();
@ -203,7 +216,7 @@ class WC_Tests_Order_Coupons extends WC_Unit_Test_Case {
*/
function test_remove_coupon_from_order_ex_tax() {
update_option( 'woocommerce_prices_include_tax', 'no' );
$this->tearDown();
update_option( 'woocommerce_calc_taxes', 'yes' );
$this->setUp();
$order_id = $this->objects['order']->get_id();
@ -222,7 +235,6 @@ class WC_Tests_Order_Coupons extends WC_Unit_Test_Case {
$this->assertEquals( '1100', $order->get_total(), $order->get_total() );
// Reset.
$this->tearDown();
$this->setUp();
$order_id = $this->objects['order']->get_id();
@ -244,7 +256,7 @@ class WC_Tests_Order_Coupons extends WC_Unit_Test_Case {
*/
function test_add_coupon_to_order_ex_tax() {
update_option( 'woocommerce_prices_include_tax', 'no' );
$this->tearDown();
update_option( 'woocommerce_calc_taxes', 'yes' );
$this->setUp();
$order_id = $this->objects['order']->get_id();
@ -253,4 +265,59 @@ class WC_Tests_Order_Coupons extends WC_Unit_Test_Case {
$order->apply_coupon( 'test-coupon-2' );
$this->assertEquals( '703.12', $order->get_total(), $order->get_total() );
}
/**
* Test: test_remove_coupon_from_order_no_tax
*/
function test_remove_coupon_from_order_no_tax() {
update_option( 'woocommerce_prices_include_tax', 'no' );
update_option( 'woocommerce_calc_taxes', 'no' );
$this->setUp();
$order_id = $this->objects['order']->get_id();
$order = wc_get_order( $order_id );
// Check it's expected.
$this->assertEquals( 'shop_order', $order->get_type() );
$this->assertEquals( '799', $order->get_total(), $order->get_total() );
// Remove the virtual coupon. Total should be 999.
$order->remove_coupon( 'this-is-a-virtal-coupon' );
$this->assertEquals( '999', $order->get_total(), $order->get_total() );
// Remove the other coupon. Total should be 1000.
$order->remove_coupon( 'test-coupon-1' );
$this->assertEquals( '1000', $order->get_total(), $order->get_total() );
// Reset.
$this->setUp();
$order_id = $this->objects['order']->get_id();
$order = wc_get_order( $order_id );
// Check it's expected.
$this->assertEquals( 'shop_order', $order->get_type() );
$this->assertEquals( '799', $order->get_total(), $order->get_total() );
// Do the above tests in reverse.
$order->remove_coupon( 'test-coupon-1' );
$this->assertEquals( '800', $order->get_total(), $order->get_total() );
$order->remove_coupon( 'this-is-a-virtal-coupon' );
$this->assertEquals( '1000', $order->get_total(), $order->get_total() );
}
/**
* Test: test_add_coupon_to_order_no_tax
*/
function test_add_coupon_to_order_no_tax() {
update_option( 'woocommerce_prices_include_tax', 'no' );
update_option( 'woocommerce_calc_taxes', 'no' );
$this->setUp();
$order_id = $this->objects['order']->get_id();
$order = wc_get_order( $order_id );
$order->apply_coupon( 'test-coupon-2' );
$this->assertEquals( '639.2', $order->get_total(), $order->get_total() );
}
}