woocommerce/tests/unit-tests/product/product-simple.php

324 lines
7.3 KiB
PHP
Raw Normal View History

2015-03-04 17:23:25 +00:00
<?php
2015-03-06 15:32:40 +00:00
2015-03-04 17:23:25 +00:00
/**
2015-11-03 13:31:20 +00:00
* Class Product_Simple.
2015-03-06 15:32:40 +00:00
* @package WooCommerce\Tests\Product
2015-03-04 17:23:25 +00:00
* @since 2.3
*/
class WC_Tests_Product_Simple extends WC_Unit_Test_Case {
2015-03-04 17:23:25 +00:00
/**
2015-11-03 13:31:20 +00:00
* Test add_to_cart_text().
2015-03-04 17:23:25 +00:00
*
* @since 2.3
*/
public function test_add_to_cart_text() {
// Create product
$product = WC_Helper_Product::create_simple_product();
2015-03-04 17:23:25 +00:00
$this->assertEquals( __( 'Add to cart', 'woocommerce' ), $product->add_to_cart_text() );
2015-03-04 17:23:25 +00:00
$product->stock_status = 'outofstock';
$this->assertEquals( __( 'Read more', 'woocommerce' ), $product->add_to_cart_text() );
2015-03-04 17:23:25 +00:00
// Delete product
WC_Helper_Product::delete_product( $product->id );
2015-03-04 17:23:25 +00:00
}
2015-03-05 16:32:53 +00:00
/**
2015-11-03 13:31:20 +00:00
* Test single_add_to_cart_text().
2015-03-05 16:32:53 +00:00
*
* @since 2.3
*/
public function test_single_add_to_cart_text() {
// Create product
$product = WC_Helper_Product::create_simple_product();
2015-03-05 16:32:53 +00:00
$this->assertEquals( __( 'Add to cart', 'woocommerce' ), $product->single_add_to_cart_text() );
2015-03-05 16:32:53 +00:00
// Delete product
WC_Helper_Product::delete_product( $product->id );
2015-03-05 16:32:53 +00:00
}
2015-03-04 17:23:25 +00:00
/**
2015-11-03 13:31:20 +00:00
* Test get_title().
2015-03-04 17:23:25 +00:00
*
* @since 2.3
*/
public function test_get_title() {
// Create product
$product = WC_Helper_Product::create_simple_product();
$this->assertEquals( 'Dummy Product', $product->get_title() );
2015-03-04 17:23:25 +00:00
// Delete product
WC_Helper_Product::delete_product( $product->id );
2015-03-04 17:23:25 +00:00
}
2015-03-05 16:32:53 +00:00
/**
2015-11-03 13:31:20 +00:00
* Test get_permalink().
2015-03-05 16:32:53 +00:00
*
* @since 2.3
*/
public function test_get_permalink() {
// Create product
$product = WC_Helper_Product::create_simple_product();
2015-03-05 16:32:53 +00:00
$this->assertEquals( get_permalink( $product->id ), $product->get_permalink() );
2015-03-05 16:32:53 +00:00
// Delete product
WC_Helper_Product::delete_product( $product->id );
2015-03-05 16:32:53 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Test get_sku().
2015-03-05 16:32:53 +00:00
*
* @since 2.3
*/
public function test_get_sku() {
// Create product
$product = WC_Helper_Product::create_simple_product();
2015-03-05 16:32:53 +00:00
$this->assertEquals( $product->sku, $product->get_sku() );
2015-03-05 16:32:53 +00:00
// Delete product
WC_Helper_Product::delete_product( $product->id );
2015-03-05 16:32:53 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Test get_stock_quantity().
2015-03-05 16:32:53 +00:00
*
* @since 2.3
*/
public function test_get_stock_quantity() {
// Create product
$product = WC_Helper_Product::create_simple_product();
2015-03-05 16:32:53 +00:00
$this->assertEmpty( $product->get_stock_quantity() );
2015-03-05 16:32:53 +00:00
$product->manage_stock = 'yes';
2015-03-05 16:32:53 +00:00
$this->assertEquals( 0, $product->get_stock_quantity() );
2015-03-05 16:32:53 +00:00
// Delete product
WC_Helper_Product::delete_product( $product->id );
2015-03-05 16:32:53 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Test get_total_stock().
2015-03-05 16:32:53 +00:00
*
* @since 2.3
*/
public function test_get_total_stock() {
// Create product
$product = WC_Helper_Product::create_simple_product();
2015-03-05 16:32:53 +00:00
$this->assertEmpty( $product->get_total_stock() );
2015-03-05 16:32:53 +00:00
$product->manage_stock = 'yes';
$this->assertEquals( 0, $product->get_total_stock() );
2015-03-05 16:32:53 +00:00
// Delete product
WC_Helper_Product::delete_product( $product->id );
2015-03-05 16:32:53 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Test set_stock().
2015-03-05 16:32:53 +00:00
*
* @since 2.3
*/
public function test_set_stock() {
// Create product
$product = WC_Helper_Product::create_simple_product();
2015-03-05 16:32:53 +00:00
$product->manage_stock = 'yes';
$this->assertEquals( 5, $product->set_stock( 5 ) );
$this->assertEquals( 2, $product->set_stock( 3, 'subtract' ) );
$this->assertEquals( 5, $product->set_stock( 3, 'add' ) );
2015-03-05 16:32:53 +00:00
// Delete product
WC_Helper_Product::delete_product( $product->id );
2015-03-05 16:32:53 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Test reduce_stock().
2015-03-05 16:32:53 +00:00
*
* @since 2.3
*/
public function test_reduce_stock() {
// Create product
$product = WC_Helper_Product::create_simple_product();
2015-03-05 16:32:53 +00:00
$product->manage_stock = 'yes';
$product->set_stock( 5 );
$this->assertEquals( 2, $product->reduce_stock( 3 ) );
2015-03-05 16:32:53 +00:00
// Delete product
WC_Helper_Product::delete_product( $product->id );
2015-03-05 16:32:53 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Test increase_stock().
2015-03-05 16:32:53 +00:00
*
* @since 2.3
*/
public function test_increase_stock() {
// Create product
$product = WC_Helper_Product::create_simple_product();
2015-03-05 16:32:53 +00:00
$product->manage_stock = 'yes';
$product->set_stock( 5 );
$this->assertEquals( 8, $product->increase_stock( 3 ) );
2015-03-05 16:32:53 +00:00
// Delete product
WC_Helper_Product::delete_product( $product->id );
2015-03-05 16:32:53 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Test is_type().
2015-03-05 16:32:53 +00:00
*
* @since 2.3
*/
public function test_is_type() {
// Create product
$product = WC_Helper_Product::create_simple_product();
2015-03-05 16:32:53 +00:00
$this->assertTrue( $product->is_type( 'simple' ) );
$this->assertFalse( $product->is_type( 'grouped' ) );
$this->assertFalse( $product->is_type( 'variable' ) );
$this->assertFalse( $product->is_type( 'external' ) );
2015-03-05 16:32:53 +00:00
// Delete product
WC_Helper_Product::delete_product( $product->id );
2015-03-05 16:32:53 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Test is_downloadable().
2015-03-05 16:32:53 +00:00
*
* @since 2.3
*/
public function test_is_downloadable() {
// Create product
$product = WC_Helper_Product::create_simple_product();
2015-03-05 16:32:53 +00:00
$this->assertEmpty( $product->is_downloadable() );
2015-03-05 16:32:53 +00:00
$product->downloadable = 'yes';
$this->assertTrue( $product->is_downloadable() );
2015-03-05 16:32:53 +00:00
$product->downloadable = 'no';
$this->assertFalse( $product->is_downloadable() );
2015-03-05 16:32:53 +00:00
// Delete product
WC_Helper_Product::delete_product( $product->id );
2015-03-05 16:32:53 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Test is_virtual().
2015-03-05 16:32:53 +00:00
*
* @since 2.3
*/
public function test_is_virtual() {
// Create product
$product = WC_Helper_Product::create_simple_product();
2015-03-05 16:32:53 +00:00
$this->assertEmpty( $product->is_virtual() );
2015-03-05 16:32:53 +00:00
$product->virtual = 'yes';
$this->assertTrue( $product->is_virtual() );
2015-03-05 16:32:53 +00:00
$product->virtual = 'no';
$this->assertFalse( $product->is_virtual() );
2015-03-05 16:32:53 +00:00
// Delete product
WC_Helper_Product::delete_product( $product->id );
2015-03-05 16:32:53 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Test needs_shipping().
2015-03-05 16:32:53 +00:00
*
* @since 2.3
*/
public function test_needs_shipping() {
// Create product
$product = WC_Helper_Product::create_simple_product();
2015-03-05 16:32:53 +00:00
$product->virtual = 'yes';
$this->assertFalse( $product->needs_shipping() );
2015-03-05 16:32:53 +00:00
$product->virtual = 'no';
$this->assertTrue( $product->needs_shipping() );
2015-03-05 16:32:53 +00:00
// Delete product
WC_Helper_Product::delete_product( $product->id );
2015-03-05 16:32:53 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Test is_sold_individually().
2015-03-05 16:32:53 +00:00
*
* @since 2.3
*/
public function test_is_sold_individually() {
// Create product
$product = WC_Helper_Product::create_simple_product();
2015-03-05 16:32:53 +00:00
$product->sold_individually = 'yes';
$this->assertTrue( $product->is_sold_individually() );
2015-03-05 16:32:53 +00:00
$product->sold_individually = 'no';
$this->assertFalse( $product->is_sold_individually() );
2015-03-05 16:32:53 +00:00
// Delete product
WC_Helper_Product::delete_product( $product->id );
2015-03-05 16:32:53 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Test backorders_allowed().
2015-03-05 16:32:53 +00:00
*
* @since 2.3
*/
public function test_backorders_allowed() {
// Create product
$product = WC_Helper_Product::create_simple_product();
2015-03-05 16:32:53 +00:00
$product->backorders = 'yes';
$this->assertTrue( $product->backorders_allowed() );
2015-03-05 16:32:53 +00:00
$product->backorders = 'notify';
$this->assertTrue( $product->backorders_allowed() );
2015-03-05 16:32:53 +00:00
$product->backorders = 'no';
$this->assertFalse( $product->backorders_allowed() );
2015-03-05 16:32:53 +00:00
// Delete product
WC_Helper_Product::delete_product( $product->id );
2015-03-05 16:32:53 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Test backorders_require_notification().
2015-03-05 16:32:53 +00:00
*
* @since 2.3
*/
public function test_backorders_require_notification() {
// Create product
$product = WC_Helper_Product::create_simple_product();
2015-03-05 16:32:53 +00:00
$product->backorders = 'notify';
$product->manage_stock = 'yes';
$this->assertTrue( $product->backorders_require_notification() );
2015-03-05 16:32:53 +00:00
$product->backorders = 'yes';
$this->assertFalse( $product->backorders_require_notification() );
2015-03-05 16:32:53 +00:00
$product->backorders = 'no';
$this->assertFalse( $product->backorders_require_notification() );
2015-03-05 16:32:53 +00:00
$product->backorders = 'yes';
$product->manage_stock = 'no';
$this->assertFalse( $product->backorders_require_notification() );
2015-03-05 16:32:53 +00:00
// Delete product
WC_Helper_Product::delete_product( $product->id );
2015-03-05 16:32:53 +00:00
}
2015-03-04 17:23:25 +00:00
}