Tests
This commit is contained in:
parent
f58829a316
commit
5fc0142ba0
|
@ -32,13 +32,14 @@ class WC_Helper_Product {
|
||||||
*
|
*
|
||||||
* @return WC_Product_Simple
|
* @return WC_Product_Simple
|
||||||
*/
|
*/
|
||||||
public static function create_simple_product() {
|
public static function create_simple_product( $parent = 0 ) {
|
||||||
|
|
||||||
// Create the product
|
// Create the product
|
||||||
$product = wp_insert_post( array(
|
$product = wp_insert_post( array(
|
||||||
'post_title' => 'Dummy Product',
|
'post_title' => 'Dummy Product',
|
||||||
'post_type' => 'product',
|
'post_type' => 'product',
|
||||||
'post_status' => 'publish',
|
'post_status' => 'publish',
|
||||||
|
'post_parent' => $parent,
|
||||||
) );
|
) );
|
||||||
update_post_meta( $product, '_price', '10' );
|
update_post_meta( $product, '_price', '10' );
|
||||||
update_post_meta( $product, '_regular_price', '10' );
|
update_post_meta( $product, '_regular_price', '10' );
|
||||||
|
@ -72,6 +73,29 @@ class WC_Helper_Product {
|
||||||
update_post_meta( $product, '_regular_price', '10' );
|
update_post_meta( $product, '_regular_price', '10' );
|
||||||
update_post_meta( $product, '_sale_price', '' );
|
update_post_meta( $product, '_sale_price', '' );
|
||||||
update_post_meta( $product, '_sku', 'DUMMY EXTERNAL SKU' );
|
update_post_meta( $product, '_sku', 'DUMMY EXTERNAL SKU' );
|
||||||
|
update_post_meta( $product, '_product_url', 'http://woocommerce.com' );
|
||||||
|
update_post_meta( $product, '_button_text', 'Buy external product' );
|
||||||
|
|
||||||
|
return new WC_Product_External( $product );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create grouped product.
|
||||||
|
*
|
||||||
|
* @since 2.7.0
|
||||||
|
*
|
||||||
|
* @return WC_Product_Grouped
|
||||||
|
*/
|
||||||
|
public static function create_grouped_product() {
|
||||||
|
// Create the product
|
||||||
|
$product = wp_insert_post( array(
|
||||||
|
'post_title' => 'Dummy Grouped Product',
|
||||||
|
'post_type' => 'product',
|
||||||
|
'post_status' => 'publish',
|
||||||
|
) );
|
||||||
|
$simple_product_1 = self::create_simple_product( $product->ID );
|
||||||
|
$simple_product_2 = self::create_simple_product( $product->ID );
|
||||||
|
update_post_meta( $product, '_sku', 'DUMMY GROUPED SKU' );
|
||||||
update_post_meta( $product, '_manage_stock', 'no' );
|
update_post_meta( $product, '_manage_stock', 'no' );
|
||||||
update_post_meta( $product, '_tax_status', 'taxable' );
|
update_post_meta( $product, '_tax_status', 'taxable' );
|
||||||
update_post_meta( $product, '_downloadable', 'no' );
|
update_post_meta( $product, '_downloadable', 'no' );
|
||||||
|
@ -79,10 +103,7 @@ class WC_Helper_Product {
|
||||||
update_post_meta( $product, '_visibility', 'visible' );
|
update_post_meta( $product, '_visibility', 'visible' );
|
||||||
update_post_meta( $product, '_stock_status', 'instock' );
|
update_post_meta( $product, '_stock_status', 'instock' );
|
||||||
|
|
||||||
update_post_meta( $product, '_product_url', 'http://woocommerce.com' );
|
return new WC_Product_Grouped( $product );
|
||||||
update_post_meta( $product, '_button_text', 'Buy external product' );
|
|
||||||
|
|
||||||
return new WC_Product_External( $product );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -115,6 +115,69 @@ class WC_Tests_Product_CRUD extends WC_Unit_Test_Case {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test creating a new grouped product.
|
||||||
|
*
|
||||||
|
* @since 2.7.0
|
||||||
|
*/
|
||||||
|
function test_grouped_product_create() {
|
||||||
|
$simple_product = WC_Helper_Product::create_simple_product();
|
||||||
|
$product = new WC_Product_Grouped;
|
||||||
|
$product->set_children( array( $simple_product->get_id() ) );
|
||||||
|
$product->set_name( 'My Grouped Product' );
|
||||||
|
$product->create();
|
||||||
|
$read_product = new WC_Product_Grouped( $product->get_id() );
|
||||||
|
$this->assertEquals( 'My Grouped Product', $read_product->get_name() );
|
||||||
|
$this->assertEquals( array( $simple_product->get_id() ), $read_product->get_children() );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test getting / reading an grouped product.
|
||||||
|
*
|
||||||
|
* @since 2.7.0
|
||||||
|
*/
|
||||||
|
function test_grouped_product_read() {
|
||||||
|
$product = WC_Helper_Product::create_grouped_product();
|
||||||
|
$product = new WC_Product_Grouped( $product->get_id() );
|
||||||
|
$this->assertEquals( 'Dummy Grouped Product', $read_product->get_name() );
|
||||||
|
$this->assertEquals( 2, count( $product->get_children() ) );
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Test updating an grouped product.
|
||||||
|
*
|
||||||
|
* @since 2.7.0
|
||||||
|
*/
|
||||||
|
function test_grouped_product_update() {
|
||||||
|
$product = WC_Helper_Product::create_grouped_product();
|
||||||
|
$simple_product = WC_Helper_Product::create_simple_product();
|
||||||
|
$this->assertEquals( 'My Grouped Product', $product->get_name() );
|
||||||
|
$this->assertEquals( array( $simple_product->get_id() ), $product->get_children() );
|
||||||
|
$children = $product->get_children();
|
||||||
|
$children[] = $simple_product->get_id();
|
||||||
|
$product->set_children( $children );
|
||||||
|
$product->set_name( 'My Grouped Product 2' );
|
||||||
|
$product->save();
|
||||||
|
// Reread from database
|
||||||
|
$product = new WC_Product_Grouped( $product->get_id() );
|
||||||
|
$this->assertEquals( 3, count( $product->get_children() ) );
|
||||||
|
$this->assertEquals( 'My Grouped Product 2', $read_product->get_name() );
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Test grouped product setters and getters
|
||||||
|
*
|
||||||
|
* @since 2.7.0
|
||||||
|
*/
|
||||||
|
public function test_grouped_product_getters_and_setters() {
|
||||||
|
$getters_and_setters = array(
|
||||||
|
'children' => array( 1, 2, 3 ),
|
||||||
|
);
|
||||||
|
$product = new WC_Product_Grouped;
|
||||||
|
foreach ( $getters_and_setters as $function => $value ) {
|
||||||
|
$product->{"set_{$function}"}( $value );
|
||||||
|
$this->assertEquals( $value, $product->{"get_{$function}"}(), $function );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test creating a new external product.
|
* Test creating a new external product.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue