From eefdfac91d5214f577cf5a85618cbdb7ea6757b9 Mon Sep 17 00:00:00 2001 From: Nicola Mustone Date: Thu, 5 Mar 2015 17:32:45 +0100 Subject: [PATCH 1/2] delete product if not empty --- tests/unit-tests/product-functions.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/unit-tests/product-functions.php b/tests/unit-tests/product-functions.php index 19324fc0982..1c6817e2993 100644 --- a/tests/unit-tests/product-functions.php +++ b/tests/unit-tests/product-functions.php @@ -18,6 +18,10 @@ class WC_Tests_Product_Functions extends WC_Unit_Test_Case { * @access private */ private function _get_product() { + if ( ! is_null( $this->_product ) ) { + $this->_delete_product(); + } + $this->_product = WC_Helper_Product::create_simple_product(); } From d20047430bfbb1b867fbaf04019d203e89b1f810 Mon Sep 17 00:00:00 2001 From: Nicola Mustone Date: Thu, 5 Mar 2015 17:32:53 +0100 Subject: [PATCH 2/2] more tests --- tests/unit-tests/product-simple.php | 253 ++++++++++++++++++++++++++++ 1 file changed, 253 insertions(+) diff --git a/tests/unit-tests/product-simple.php b/tests/unit-tests/product-simple.php index 94d9659bdf5..c44b9745b77 100644 --- a/tests/unit-tests/product-simple.php +++ b/tests/unit-tests/product-simple.php @@ -41,6 +41,8 @@ class WC_Tests_Product_Simple extends WC_Unit_Test_Case { public function tearDown() { remove_all_filters( 'woocommerce_product_add_to_cart_text' ); + remove_all_filters( 'woocommerce_product_single_add_to_cart_text' ); + remove_all_filters( 'woocommerce_product_needs_shipping' ); } /** @@ -59,6 +61,19 @@ class WC_Tests_Product_Simple extends WC_Unit_Test_Case { $this->_delete_product(); } + /** + * Test single_add_to_cart_text() + * + * @since 2.3 + */ + public function test_single_add_to_cart_text() { + $this->_get_product(); + + $this->assertEquals( __( 'Add to cart', 'woocommerce' ), $this->_product->single_add_to_cart_text() ); + + $this->_delete_product(); + } + /** * Test get_title() * @@ -69,4 +84,242 @@ class WC_Tests_Product_Simple extends WC_Unit_Test_Case { $this->assertEquals( 'Dummy Product', $this->_product->get_title() ); } + + /** + * Test get_permalink() + * + * @since 2.3 + */ + public function test_get_permalink() { + $this->_get_product(); + + $this->assertEquals( get_permalink( $this->_product->id ), $this->_product->get_permalink() ); + + $this->_delete_product(); + } + + /** + * Test get_sku() + * + * @since 2.3 + */ + public function test_get_sku() { + $this->_get_product(); + + $this->assertEquals( $this->_product->sku, $this->_product->get_sku() ); + + $this->_delete_product(); + } + + /** + * Test get_stock_quantity() + * + * @since 2.3 + */ + public function test_get_stock_quantity() { + $this->_get_product(); + + $this->assertEmpty( $this->_product->get_stock_quantity() ); + + $this->_product->manage_stock = 'yes'; + + $this->assertEquals( 0, $this->_product->get_stock_quantity() ); + + $this->_delete_product(); + } + + /** + * Test get_total_stock() + * + * @since 2.3 + */ + public function test_get_total_stock() { + $this->_get_product(); + + $this->assertEmpty( $this->_product->get_total_stock() ); + + $this->_product->manage_stock = 'yes'; + $this->assertEquals( 0, $this->_product->get_total_stock() ); + + $this->_delete_product(); + } + + /** + * Test set_stock() + * + * @since 2.3 + */ + public function test_set_stock() { + $this->_get_product(); + + $this->_product->manage_stock = 'yes'; + $this->assertEquals( 5, $this->_product->set_stock( 5 ) ); + $this->assertEquals( 2, $this->_product->set_stock( 3, 'subtract' ) ); + $this->assertEquals( 5, $this->_product->set_stock( 3, 'add' ) ); + + $this->_delete_product(); + } + + /** + * Test reduce_stock() + * + * @since 2.3 + */ + public function test_reduce_stock() { + $this->_get_product(); + + $this->_product->manage_stock = 'yes'; + $this->_product->set_stock( 5 ); + $this->assertEquals( 2, $this->_product->reduce_stock( 3 ) ); + + $this->_delete_product(); + } + + /** + * Test increase_stock() + * + * @since 2.3 + */ + public function test_increase_stock() { + $this->_get_product(); + + $this->_product->manage_stock = 'yes'; + $this->_product->set_stock( 5 ); + $this->assertEquals( 8, $this->_product->increase_stock( 3 ) ); + + $this->_delete_product(); + } + + /** + * Test is_type() + * + * @since 2.3 + */ + public function test_is_type() { + $this->_get_product(); + + $this->assertTrue( $this->_product->is_type( 'simple' ) ); + $this->assertFalse( $this->_product->is_type( 'grouped' ) ); + $this->assertFalse( $this->_product->is_type( 'variable' ) ); + $this->assertFalse( $this->_product->is_type( 'external' ) ); + + $this->_delete_product(); + } + + /** + * Test is_downloadable() + * + * @since 2.3 + */ + public function test_is_downloadable() { + $this->_get_product(); + + $this->assertEmpty( $this->_product->is_downloadable() ); + + $this->_product->downloadable = 'yes'; + $this->assertTrue( $this->_product->is_downloadable() ); + + $this->_product->downloadable = 'no'; + $this->assertFalse( $this->_product->is_downloadable() ); + + $this->_delete_product(); + } + + /** + * Test is_virtual() + * + * @since 2.3 + */ + public function test_is_virtual() { + $this->_get_product(); + + $this->assertEmpty( $this->_product->is_virtual() ); + + $this->_product->virtual = 'yes'; + $this->assertTrue( $this->_product->is_virtual() ); + + $this->_product->virtual = 'no'; + $this->assertFalse( $this->_product->is_virtual() ); + + $this->_delete_product(); + } + + /** + * Test needs_shipping() + * + * @since 2.3 + */ + public function test_needs_shipping() { + $this->_get_product(); + + $this->_product->virtual = 'yes'; + $this->assertFalse( $this->_product->needs_shipping() ); + + $this->_product->virtual = 'no'; + $this->assertTrue( $this->_product->needs_shipping() ); + + $this->_delete_product(); + } + + /** + * Test is_sold_individually() + * + * @since 2.3 + */ + public function test_is_sold_individually() { + $this->_get_product(); + + $this->_product->sold_individually = 'yes'; + $this->assertTrue( $this->_product->is_sold_individually() ); + + $this->_product->sold_individually = 'no'; + $this->assertFalse( $this->_product->is_sold_individually() ); + + $this->_delete_product(); + } + + /** + * Test backorders_allowed() + * + * @since 2.3 + */ + public function test_backorders_allowed() { + $this->_get_product(); + + $this->_product->backorders = 'yes'; + $this->assertTrue( $this->_product->backorders_allowed() ); + + $this->_product->backorders = 'notify'; + $this->assertTrue( $this->_product->backorders_allowed() ); + + $this->_product->backorders = 'no'; + $this->assertFalse( $this->_product->backorders_allowed() ); + + $this->_delete_product(); + } + + /** + * Test backorders_require_notification() + * + * @since 2.3 + */ + public function test_backorders_require_notification() { + $this->_get_product(); + + $this->_product->backorders = 'notify'; + $this->_product->manage_stock = 'yes'; + $this->assertTrue( $this->_product->backorders_require_notification() ); + + $this->_product->backorders = 'yes'; + $this->assertFalse( $this->_product->backorders_require_notification() ); + + $this->_product->backorders = 'no'; + $this->assertFalse( $this->_product->backorders_require_notification() ); + + $this->_product->backorders = 'yes'; + $this->_product->manage_stock = 'no'; + $this->assertFalse( $this->_product->backorders_require_notification() ); + + $this->_delete_product(); + } }