parent
d6b970a61d
commit
75e9f93891
|
@ -8,45 +8,6 @@ namespace WooCommerce\Tests\Product;
|
||||||
* @since 2.3
|
* @since 2.3
|
||||||
*/
|
*/
|
||||||
class Product_Simple extends \WC_Unit_Test_Case {
|
class Product_Simple extends \WC_Unit_Test_Case {
|
||||||
/**
|
|
||||||
* @var object
|
|
||||||
* @access private
|
|
||||||
*/
|
|
||||||
private $_product = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper method to get a product
|
|
||||||
*
|
|
||||||
* @since 2.3
|
|
||||||
* @access private
|
|
||||||
*/
|
|
||||||
private function _get_product() {
|
|
||||||
$this->_product = \WC_Helper_Product::create_simple_product();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper method to delete a product
|
|
||||||
*
|
|
||||||
* @since 2.3
|
|
||||||
* @access private
|
|
||||||
*/
|
|
||||||
private function _delete_product() {
|
|
||||||
// Delete the previously created product
|
|
||||||
\WC_Helper_Product::delete_product( $this->_product->id );
|
|
||||||
$this->_product = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clear out notices after each test
|
|
||||||
*
|
|
||||||
* @since 2.3
|
|
||||||
*/
|
|
||||||
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' );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test add_to_cart_text()
|
* Test add_to_cart_text()
|
||||||
|
@ -54,14 +15,16 @@ class Product_Simple extends \WC_Unit_Test_Case {
|
||||||
* @since 2.3
|
* @since 2.3
|
||||||
*/
|
*/
|
||||||
public function test_add_to_cart_text() {
|
public function test_add_to_cart_text() {
|
||||||
$this->_get_product();
|
// Create product
|
||||||
|
$product = \WC_Helper_Product::create_simple_product();
|
||||||
|
|
||||||
$this->assertEquals( __( 'Add to cart', 'woocommerce' ), $this->_product->add_to_cart_text() );
|
$this->assertEquals( __( 'Add to cart', 'woocommerce' ), $product->add_to_cart_text() );
|
||||||
|
|
||||||
$this->_product->stock_status = 'outofstock';
|
$product->stock_status = 'outofstock';
|
||||||
$this->assertEquals( __( 'Read More', 'woocommerce' ), $this->_product->add_to_cart_text() );
|
$this->assertEquals( __( 'Read More', 'woocommerce' ), $product->add_to_cart_text() );
|
||||||
|
|
||||||
$this->_delete_product();
|
// Delete product
|
||||||
|
\WC_Helper_Product::delete_product( $product->id );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -70,11 +33,13 @@ class Product_Simple extends \WC_Unit_Test_Case {
|
||||||
* @since 2.3
|
* @since 2.3
|
||||||
*/
|
*/
|
||||||
public function test_single_add_to_cart_text() {
|
public function test_single_add_to_cart_text() {
|
||||||
$this->_get_product();
|
// Create product
|
||||||
|
$product = \WC_Helper_Product::create_simple_product();
|
||||||
|
|
||||||
$this->assertEquals( __( 'Add to cart', 'woocommerce' ), $this->_product->single_add_to_cart_text() );
|
$this->assertEquals( __( 'Add to cart', 'woocommerce' ), $product->single_add_to_cart_text() );
|
||||||
|
|
||||||
$this->_delete_product();
|
// Delete product
|
||||||
|
\WC_Helper_Product::delete_product( $product->id );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -83,9 +48,13 @@ class Product_Simple extends \WC_Unit_Test_Case {
|
||||||
* @since 2.3
|
* @since 2.3
|
||||||
*/
|
*/
|
||||||
public function test_get_title() {
|
public function test_get_title() {
|
||||||
$this->_get_product();
|
// Create product
|
||||||
|
$product = \WC_Helper_Product::create_simple_product();
|
||||||
|
|
||||||
$this->assertEquals( 'Dummy Product', $this->_product->get_title() );
|
$this->assertEquals( 'Dummy Product', $product->get_title() );
|
||||||
|
|
||||||
|
// Delete product
|
||||||
|
\WC_Helper_Product::delete_product( $product->id );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -94,11 +63,13 @@ class Product_Simple extends \WC_Unit_Test_Case {
|
||||||
* @since 2.3
|
* @since 2.3
|
||||||
*/
|
*/
|
||||||
public function test_get_permalink() {
|
public function test_get_permalink() {
|
||||||
$this->_get_product();
|
// Create product
|
||||||
|
$product = \WC_Helper_Product::create_simple_product();
|
||||||
|
|
||||||
$this->assertEquals( get_permalink( $this->_product->id ), $this->_product->get_permalink() );
|
$this->assertEquals( get_permalink( $product->id ), $product->get_permalink() );
|
||||||
|
|
||||||
$this->_delete_product();
|
// Delete product
|
||||||
|
\WC_Helper_Product::delete_product( $product->id );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -107,11 +78,13 @@ class Product_Simple extends \WC_Unit_Test_Case {
|
||||||
* @since 2.3
|
* @since 2.3
|
||||||
*/
|
*/
|
||||||
public function test_get_sku() {
|
public function test_get_sku() {
|
||||||
$this->_get_product();
|
// Create product
|
||||||
|
$product = \WC_Helper_Product::create_simple_product();
|
||||||
|
|
||||||
$this->assertEquals( $this->_product->sku, $this->_product->get_sku() );
|
$this->assertEquals( $product->sku, $product->get_sku() );
|
||||||
|
|
||||||
$this->_delete_product();
|
// Delete product
|
||||||
|
\WC_Helper_Product::delete_product( $product->id );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -120,15 +93,17 @@ class Product_Simple extends \WC_Unit_Test_Case {
|
||||||
* @since 2.3
|
* @since 2.3
|
||||||
*/
|
*/
|
||||||
public function test_get_stock_quantity() {
|
public function test_get_stock_quantity() {
|
||||||
$this->_get_product();
|
// Create product
|
||||||
|
$product = \WC_Helper_Product::create_simple_product();
|
||||||
|
|
||||||
$this->assertEmpty( $this->_product->get_stock_quantity() );
|
$this->assertEmpty( $product->get_stock_quantity() );
|
||||||
|
|
||||||
$this->_product->manage_stock = 'yes';
|
$product->manage_stock = 'yes';
|
||||||
|
|
||||||
$this->assertEquals( 0, $this->_product->get_stock_quantity() );
|
$this->assertEquals( 0, $product->get_stock_quantity() );
|
||||||
|
|
||||||
$this->_delete_product();
|
// Delete product
|
||||||
|
\WC_Helper_Product::delete_product( $product->id );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -137,14 +112,16 @@ class Product_Simple extends \WC_Unit_Test_Case {
|
||||||
* @since 2.3
|
* @since 2.3
|
||||||
*/
|
*/
|
||||||
public function test_get_total_stock() {
|
public function test_get_total_stock() {
|
||||||
$this->_get_product();
|
// Create product
|
||||||
|
$product = \WC_Helper_Product::create_simple_product();
|
||||||
|
|
||||||
$this->assertEmpty( $this->_product->get_total_stock() );
|
$this->assertEmpty( $product->get_total_stock() );
|
||||||
|
|
||||||
$this->_product->manage_stock = 'yes';
|
$product->manage_stock = 'yes';
|
||||||
$this->assertEquals( 0, $this->_product->get_total_stock() );
|
$this->assertEquals( 0, $product->get_total_stock() );
|
||||||
|
|
||||||
$this->_delete_product();
|
// Delete product
|
||||||
|
\WC_Helper_Product::delete_product( $product->id );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -153,14 +130,16 @@ class Product_Simple extends \WC_Unit_Test_Case {
|
||||||
* @since 2.3
|
* @since 2.3
|
||||||
*/
|
*/
|
||||||
public function test_set_stock() {
|
public function test_set_stock() {
|
||||||
$this->_get_product();
|
// Create product
|
||||||
|
$product = \WC_Helper_Product::create_simple_product();
|
||||||
|
|
||||||
$this->_product->manage_stock = 'yes';
|
$product->manage_stock = 'yes';
|
||||||
$this->assertEquals( 5, $this->_product->set_stock( 5 ) );
|
$this->assertEquals( 5, $product->set_stock( 5 ) );
|
||||||
$this->assertEquals( 2, $this->_product->set_stock( 3, 'subtract' ) );
|
$this->assertEquals( 2, $product->set_stock( 3, 'subtract' ) );
|
||||||
$this->assertEquals( 5, $this->_product->set_stock( 3, 'add' ) );
|
$this->assertEquals( 5, $product->set_stock( 3, 'add' ) );
|
||||||
|
|
||||||
$this->_delete_product();
|
// Delete product
|
||||||
|
\WC_Helper_Product::delete_product( $product->id );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -169,13 +148,15 @@ class Product_Simple extends \WC_Unit_Test_Case {
|
||||||
* @since 2.3
|
* @since 2.3
|
||||||
*/
|
*/
|
||||||
public function test_reduce_stock() {
|
public function test_reduce_stock() {
|
||||||
$this->_get_product();
|
// Create product
|
||||||
|
$product = \WC_Helper_Product::create_simple_product();
|
||||||
|
|
||||||
$this->_product->manage_stock = 'yes';
|
$product->manage_stock = 'yes';
|
||||||
$this->_product->set_stock( 5 );
|
$product->set_stock( 5 );
|
||||||
$this->assertEquals( 2, $this->_product->reduce_stock( 3 ) );
|
$this->assertEquals( 2, $product->reduce_stock( 3 ) );
|
||||||
|
|
||||||
$this->_delete_product();
|
// Delete product
|
||||||
|
\WC_Helper_Product::delete_product( $product->id );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -184,13 +165,15 @@ class Product_Simple extends \WC_Unit_Test_Case {
|
||||||
* @since 2.3
|
* @since 2.3
|
||||||
*/
|
*/
|
||||||
public function test_increase_stock() {
|
public function test_increase_stock() {
|
||||||
$this->_get_product();
|
// Create product
|
||||||
|
$product = \WC_Helper_Product::create_simple_product();
|
||||||
|
|
||||||
$this->_product->manage_stock = 'yes';
|
$product->manage_stock = 'yes';
|
||||||
$this->_product->set_stock( 5 );
|
$product->set_stock( 5 );
|
||||||
$this->assertEquals( 8, $this->_product->increase_stock( 3 ) );
|
$this->assertEquals( 8, $product->increase_stock( 3 ) );
|
||||||
|
|
||||||
$this->_delete_product();
|
// Delete product
|
||||||
|
\WC_Helper_Product::delete_product( $product->id );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -199,14 +182,16 @@ class Product_Simple extends \WC_Unit_Test_Case {
|
||||||
* @since 2.3
|
* @since 2.3
|
||||||
*/
|
*/
|
||||||
public function test_is_type() {
|
public function test_is_type() {
|
||||||
$this->_get_product();
|
// Create product
|
||||||
|
$product = \WC_Helper_Product::create_simple_product();
|
||||||
|
|
||||||
$this->assertTrue( $this->_product->is_type( 'simple' ) );
|
$this->assertTrue( $product->is_type( 'simple' ) );
|
||||||
$this->assertFalse( $this->_product->is_type( 'grouped' ) );
|
$this->assertFalse( $product->is_type( 'grouped' ) );
|
||||||
$this->assertFalse( $this->_product->is_type( 'variable' ) );
|
$this->assertFalse( $product->is_type( 'variable' ) );
|
||||||
$this->assertFalse( $this->_product->is_type( 'external' ) );
|
$this->assertFalse( $product->is_type( 'external' ) );
|
||||||
|
|
||||||
$this->_delete_product();
|
// Delete product
|
||||||
|
\WC_Helper_Product::delete_product( $product->id );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -215,17 +200,19 @@ class Product_Simple extends \WC_Unit_Test_Case {
|
||||||
* @since 2.3
|
* @since 2.3
|
||||||
*/
|
*/
|
||||||
public function test_is_downloadable() {
|
public function test_is_downloadable() {
|
||||||
$this->_get_product();
|
// Create product
|
||||||
|
$product = \WC_Helper_Product::create_simple_product();
|
||||||
|
|
||||||
$this->assertEmpty( $this->_product->is_downloadable() );
|
$this->assertEmpty( $product->is_downloadable() );
|
||||||
|
|
||||||
$this->_product->downloadable = 'yes';
|
$product->downloadable = 'yes';
|
||||||
$this->assertTrue( $this->_product->is_downloadable() );
|
$this->assertTrue( $product->is_downloadable() );
|
||||||
|
|
||||||
$this->_product->downloadable = 'no';
|
$product->downloadable = 'no';
|
||||||
$this->assertFalse( $this->_product->is_downloadable() );
|
$this->assertFalse( $product->is_downloadable() );
|
||||||
|
|
||||||
$this->_delete_product();
|
// Delete product
|
||||||
|
\WC_Helper_Product::delete_product( $product->id );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -234,17 +221,19 @@ class Product_Simple extends \WC_Unit_Test_Case {
|
||||||
* @since 2.3
|
* @since 2.3
|
||||||
*/
|
*/
|
||||||
public function test_is_virtual() {
|
public function test_is_virtual() {
|
||||||
$this->_get_product();
|
// Create product
|
||||||
|
$product = \WC_Helper_Product::create_simple_product();
|
||||||
|
|
||||||
$this->assertEmpty( $this->_product->is_virtual() );
|
$this->assertEmpty( $product->is_virtual() );
|
||||||
|
|
||||||
$this->_product->virtual = 'yes';
|
$product->virtual = 'yes';
|
||||||
$this->assertTrue( $this->_product->is_virtual() );
|
$this->assertTrue( $product->is_virtual() );
|
||||||
|
|
||||||
$this->_product->virtual = 'no';
|
$product->virtual = 'no';
|
||||||
$this->assertFalse( $this->_product->is_virtual() );
|
$this->assertFalse( $product->is_virtual() );
|
||||||
|
|
||||||
$this->_delete_product();
|
// Delete product
|
||||||
|
\WC_Helper_Product::delete_product( $product->id );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -253,15 +242,17 @@ class Product_Simple extends \WC_Unit_Test_Case {
|
||||||
* @since 2.3
|
* @since 2.3
|
||||||
*/
|
*/
|
||||||
public function test_needs_shipping() {
|
public function test_needs_shipping() {
|
||||||
$this->_get_product();
|
// Create product
|
||||||
|
$product = \WC_Helper_Product::create_simple_product();
|
||||||
|
|
||||||
$this->_product->virtual = 'yes';
|
$product->virtual = 'yes';
|
||||||
$this->assertFalse( $this->_product->needs_shipping() );
|
$this->assertFalse( $product->needs_shipping() );
|
||||||
|
|
||||||
$this->_product->virtual = 'no';
|
$product->virtual = 'no';
|
||||||
$this->assertTrue( $this->_product->needs_shipping() );
|
$this->assertTrue( $product->needs_shipping() );
|
||||||
|
|
||||||
$this->_delete_product();
|
// Delete product
|
||||||
|
\WC_Helper_Product::delete_product( $product->id );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -270,15 +261,17 @@ class Product_Simple extends \WC_Unit_Test_Case {
|
||||||
* @since 2.3
|
* @since 2.3
|
||||||
*/
|
*/
|
||||||
public function test_is_sold_individually() {
|
public function test_is_sold_individually() {
|
||||||
$this->_get_product();
|
// Create product
|
||||||
|
$product = \WC_Helper_Product::create_simple_product();
|
||||||
|
|
||||||
$this->_product->sold_individually = 'yes';
|
$product->sold_individually = 'yes';
|
||||||
$this->assertTrue( $this->_product->is_sold_individually() );
|
$this->assertTrue( $product->is_sold_individually() );
|
||||||
|
|
||||||
$this->_product->sold_individually = 'no';
|
$product->sold_individually = 'no';
|
||||||
$this->assertFalse( $this->_product->is_sold_individually() );
|
$this->assertFalse( $product->is_sold_individually() );
|
||||||
|
|
||||||
$this->_delete_product();
|
// Delete product
|
||||||
|
\WC_Helper_Product::delete_product( $product->id );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -287,18 +280,20 @@ class Product_Simple extends \WC_Unit_Test_Case {
|
||||||
* @since 2.3
|
* @since 2.3
|
||||||
*/
|
*/
|
||||||
public function test_backorders_allowed() {
|
public function test_backorders_allowed() {
|
||||||
$this->_get_product();
|
// Create product
|
||||||
|
$product = \WC_Helper_Product::create_simple_product();
|
||||||
|
|
||||||
$this->_product->backorders = 'yes';
|
$product->backorders = 'yes';
|
||||||
$this->assertTrue( $this->_product->backorders_allowed() );
|
$this->assertTrue( $product->backorders_allowed() );
|
||||||
|
|
||||||
$this->_product->backorders = 'notify';
|
$product->backorders = 'notify';
|
||||||
$this->assertTrue( $this->_product->backorders_allowed() );
|
$this->assertTrue( $product->backorders_allowed() );
|
||||||
|
|
||||||
$this->_product->backorders = 'no';
|
$product->backorders = 'no';
|
||||||
$this->assertFalse( $this->_product->backorders_allowed() );
|
$this->assertFalse( $product->backorders_allowed() );
|
||||||
|
|
||||||
$this->_delete_product();
|
// Delete product
|
||||||
|
\WC_Helper_Product::delete_product( $product->id );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -307,22 +302,24 @@ class Product_Simple extends \WC_Unit_Test_Case {
|
||||||
* @since 2.3
|
* @since 2.3
|
||||||
*/
|
*/
|
||||||
public function test_backorders_require_notification() {
|
public function test_backorders_require_notification() {
|
||||||
$this->_get_product();
|
// Create product
|
||||||
|
$product = \WC_Helper_Product::create_simple_product();
|
||||||
|
|
||||||
$this->_product->backorders = 'notify';
|
$product->backorders = 'notify';
|
||||||
$this->_product->manage_stock = 'yes';
|
$product->manage_stock = 'yes';
|
||||||
$this->assertTrue( $this->_product->backorders_require_notification() );
|
$this->assertTrue( $product->backorders_require_notification() );
|
||||||
|
|
||||||
$this->_product->backorders = 'yes';
|
$product->backorders = 'yes';
|
||||||
$this->assertFalse( $this->_product->backorders_require_notification() );
|
$this->assertFalse( $product->backorders_require_notification() );
|
||||||
|
|
||||||
$this->_product->backorders = 'no';
|
$product->backorders = 'no';
|
||||||
$this->assertFalse( $this->_product->backorders_require_notification() );
|
$this->assertFalse( $product->backorders_require_notification() );
|
||||||
|
|
||||||
$this->_product->backorders = 'yes';
|
$product->backorders = 'yes';
|
||||||
$this->_product->manage_stock = 'no';
|
$product->manage_stock = 'no';
|
||||||
$this->assertFalse( $this->_product->backorders_require_notification() );
|
$this->assertFalse( $product->backorders_require_notification() );
|
||||||
|
|
||||||
$this->_delete_product();
|
// Delete product
|
||||||
|
\WC_Helper_Product::delete_product( $product->id );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue