From c269c52f6829702c9937f7e3ef01212264207c4f Mon Sep 17 00:00:00 2001 From: claudiosmweb Date: Thu, 30 Oct 2014 11:29:59 -0200 Subject: [PATCH] Unit Tests: Added test_fixed_cart_discount method --- tests/unit-tests/cart.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/unit-tests/cart.php b/tests/unit-tests/cart.php index 1893ff47915..ff1aa9a62e9 100644 --- a/tests/unit-tests/cart.php +++ b/tests/unit-tests/cart.php @@ -483,4 +483,37 @@ class WC_Tests_Cart extends WC_Unit_Test_Case { } + /** + * Test fixed cart discount method + */ + public function test_fixed_cart_discount() { + + // Create product + $product = WC_Helper_Product::create_simple_product(); + update_post_meta( $product->id, '_price', '10' ); + update_post_meta( $product->id, '_regular_price', '10' ); + + // Create coupon + $coupon = WC_Helper_Coupon::create_coupon(); + update_post_meta( $coupon->id, 'coupon_amount', '5' ); + + // Add product to cart + WC()->cart->add_to_cart( $product->id, 1 ); + + // Add coupon + WC()->cart->add_discount( $coupon->code ); + + // Test if the cart total amount is equal 5 + $this->assertEquals( 5, WC()->cart->total ); + + // Clean up the cart + WC()->cart->empty_cart(); + + // Delete coupon + WC_Helper_Coupon::delete_coupon( $coupon->id ); + + // Delete product + WC_Helper_Product::delete_product( $product->id ); + } + }