From 1215da6355eca0e342b7e0681647c66b3d758e2c Mon Sep 17 00:00:00 2001 From: claudiulodro Date: Tue, 22 Aug 2017 14:06:33 -0700 Subject: [PATCH] WC_Cart_Fees tests --- tests/unit-tests/cart/cart-fees.php | 59 +++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 tests/unit-tests/cart/cart-fees.php diff --git a/tests/unit-tests/cart/cart-fees.php b/tests/unit-tests/cart/cart-fees.php new file mode 100644 index 00000000000..b3cea7952d8 --- /dev/null +++ b/tests/unit-tests/cart/cart-fees.php @@ -0,0 +1,59 @@ +cart ); + + // Test add_fee. + $args = array( + 'name' => 'testfee', + 'amount' => 10, + ); + $cart_fees->add_fee( $args ); + $applied_fees = $cart_fees->get_fees(); + $this->assertEquals( 'testfee', $applied_fees['testfee']->name ); + $this->assertEquals( 10, $applied_fees['testfee']->amount ); + $this->assertEquals( 1, count( $applied_fees ) ); + + // Test remove_all_fees. + $cart_fees->remove_all_fees(); + $this->assertEquals( array(), $cart_fees->get_fees() ); + + // Test set_fees. + $args = array( + array( + 'name' => 'newfee', + 'amount' => -5, + ), + array( + 'name' => 'newfee2', + 'amount' => 10, + 'tax_class' => 'Reduced rate', + 'taxable' => true + ), + ); + $cart_fees->set_fees( $args ); + $applied_fees = $cart_fees->get_fees(); + $this->assertEquals( -5, $applied_fees['newfee']->amount ); + $this->assertEquals( 'Reduced rate', $applied_fees['newfee2']->tax_class ); + $this->assertEquals( 2, count( $applied_fees ) ); + + // Clean up. + WC()->cart->empty_cart(); + + // Test fees are removed when cart is emptied. + $this->assertEquals( array(), $cart_fees->get_fees() ); + } +}