From 75484c6d43ed9165929155c6c9bfc01cf0daa7f1 Mon Sep 17 00:00:00 2001 From: Barry Kooij Date: Sat, 25 Oct 2014 00:27:14 +0200 Subject: [PATCH] Unit Tests: split cart check methods. --- tests/unit-tests/cart.php | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/tests/unit-tests/cart.php b/tests/unit-tests/cart.php index 7ecad6f1a45..e39790cf248 100644 --- a/tests/unit-tests/cart.php +++ b/tests/unit-tests/cart.php @@ -122,6 +122,29 @@ class WC_Tests_Cart extends WC_Unit_Test_Case { WC_Helper_Product::delete_product( $product->id ); } + /** + * Check if we can add a trashed product to the cart + */ + public function test_add_to_cart_trashed() { + // Create dummy product + $product = WC_Helper_Product::create_simple_product(); + + // Trash product + wp_trash_post( $product->id ); + + // Refetch product, to be sure + $product = wc_get_product($product->id); + + // Add product to cart + $this->assertFalse(WC()->cart->add_to_cart( $product->id, 1 )); + + // Clean up the cart + WC()->cart->empty_cart(); + + // Clean up product + WC_Helper_Product::delete_product( $product->id ); + } + /** * Test add to cart variable product * @@ -294,8 +317,6 @@ class WC_Tests_Cart extends WC_Unit_Test_Case { */ public function test_check_cart_item_validity() { - $this->markTestSkipped( 'Skipping as it fails on Travis.' ); - // Create dummy product $product = WC_Helper_Product::create_simple_product(); @@ -305,18 +326,6 @@ class WC_Tests_Cart extends WC_Unit_Test_Case { // Check cart validity, should pass $this->assertTrue( WC()->cart->check_cart_item_validity() ); - // Trash product - wp_trash_post( $product->id ); - - // Clean up the cart - WC()->cart->empty_cart(); - - // Re-add item to cart - WC()->cart->add_to_cart( $product->id, 1 ); - - // Check cart validity, should fail - $this->assertIsWPError( WC()->cart->check_cart_item_validity() ); - // Clean up the cart WC()->cart->empty_cart();