Some phpcs
This commit is contained in:
parent
5513dc4546
commit
a878b0cde5
|
@ -125,15 +125,19 @@ class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT imple
|
|||
$children = get_transient( $children_transient_name );
|
||||
|
||||
if ( empty( $children ) || ! is_array( $children ) || ! isset( $children['all'] ) || ! isset( $children['visible'] ) || $force_read ) {
|
||||
$all_args = $visible_only_args = array(
|
||||
$all_args = array(
|
||||
'post_parent' => $product->get_id(),
|
||||
'post_type' => 'product_variation',
|
||||
'orderby' => array( 'menu_order' => 'ASC', 'ID' => 'ASC' ),
|
||||
'orderby' => array(
|
||||
'menu_order' => 'ASC',
|
||||
'ID' => 'ASC',
|
||||
),
|
||||
'fields' => 'ids',
|
||||
'post_status' => array( 'publish', 'private' ),
|
||||
'numberposts' => -1,
|
||||
);
|
||||
|
||||
$visible_only_args = $all_args;
|
||||
$visible_only_args['post_status'] = 'publish';
|
||||
|
||||
if ( 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ) ) {
|
||||
|
|
|
@ -1454,7 +1454,7 @@ function wc_update_330_product_stock_status() {
|
|||
INNER JOIN $wpdb->postmeta t3
|
||||
ON t2.post_id = t3.post_id
|
||||
AND t3.meta_key = '_backorders' AND ( t3.meta_value = 'yes' OR t3.meta_value = 'notify' )
|
||||
", $min_stock_amount ) );
|
||||
", $min_stock_amount ) ); // WPCS: db call ok, unprepared SQL ok, cache ok.
|
||||
|
||||
if ( empty( $post_ids ) ) {
|
||||
return;
|
||||
|
@ -1466,8 +1466,8 @@ function wc_update_330_product_stock_status() {
|
|||
$wpdb->query( "
|
||||
UPDATE $wpdb->postmeta
|
||||
SET meta_value = 'onbackorder'
|
||||
WHERE meta_key = '_stock_status' AND post_id IN ( " . implode( ',', $post_ids ) . " )
|
||||
" );
|
||||
WHERE meta_key = '_stock_status' AND post_id IN ( " . implode( ',', $post_ids ) . ' )
|
||||
' ); // WPCS: db call ok, unprepared SQL ok, cache ok.
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,13 @@
|
|||
<?php
|
||||
/**
|
||||
* Unit tests for the product data methods.
|
||||
*
|
||||
* @package WooCommerce\Tests\Product
|
||||
*/
|
||||
|
||||
/**
|
||||
* Data Functions.
|
||||
*
|
||||
* @package WooCommerce\Tests\Product
|
||||
* @since 3.0.0
|
||||
*/
|
||||
|
@ -8,13 +15,14 @@ class WC_Tests_Product_Data extends WC_Unit_Test_Case {
|
|||
|
||||
/**
|
||||
* Test product setters and getters
|
||||
*
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public function test_product_getters_and_setters() {
|
||||
global $wpdb;
|
||||
|
||||
$attributes = array();
|
||||
$attribute = new WC_Product_Attribute();
|
||||
$attribute = new WC_Product_Attribute();
|
||||
$attribute->set_id( 0 );
|
||||
$attribute->set_name( 'Test Attribute' );
|
||||
$attribute->set_options( array( 'Fish', 'Fingers' ) );
|
||||
|
@ -57,7 +65,8 @@ class WC_Tests_Product_Data extends WC_Unit_Test_Case {
|
|||
'download_expiry' => -1,
|
||||
'download_limit' => 5,
|
||||
'attributes' => $attributes,
|
||||
);
|
||||
);
|
||||
|
||||
$product = new WC_Product();
|
||||
foreach ( $getters_and_setters as $function => $value ) {
|
||||
$product->{"set_{$function}"}( $value );
|
||||
|
@ -72,85 +81,86 @@ class WC_Tests_Product_Data extends WC_Unit_Test_Case {
|
|||
$this->assertEquals( $product->get_date_on_sale_from()->getTimestamp(), 1475798400 );
|
||||
$this->assertEquals( $product->get_date_on_sale_to()->getTimestamp(), 1477267200 );
|
||||
|
||||
$image_url = media_sideload_image( "https://cldup.com/Dr1Bczxq4q.png", $product->get_id(), '', 'src' );
|
||||
$image_url = media_sideload_image( 'https://cldup.com/Dr1Bczxq4q.png', $product->get_id(), '', 'src' );
|
||||
$image_id = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE guid='%s';", $image_url ) );
|
||||
$product->set_image_id( $image_id[0] );
|
||||
$product->save();
|
||||
$this->assertEquals( $image_id[0], $product->get_image_id() );
|
||||
$product->delete( true );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the onbackorder stock status.
|
||||
*
|
||||
* @since 3.3.0
|
||||
*/
|
||||
public function test_product_backorder_stock_status() {
|
||||
$product = new WC_Product();
|
||||
$product->set_stock_status( 'onbackorder' );
|
||||
$this->assertEquals( 'onbackorder', $product->get_stock_status() );
|
||||
/**
|
||||
* Test the onbackorder stock status.
|
||||
*
|
||||
* @since 3.3.0
|
||||
*/
|
||||
public function test_product_backorder_stock_status() {
|
||||
$product = new WC_Product();
|
||||
$product->set_stock_status( 'onbackorder' );
|
||||
$this->assertEquals( 'onbackorder', $product->get_stock_status() );
|
||||
|
||||
$product->save();
|
||||
$product = new WC_Product( $product->get_id() );
|
||||
$this->assertEquals( 'onbackorder', $product->get_stock_status() );
|
||||
}
|
||||
$product->save();
|
||||
$product = new WC_Product( $product->get_id() );
|
||||
$this->assertEquals( 'onbackorder', $product->get_stock_status() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the automatic stock status transitions done on product save.
|
||||
*
|
||||
* @since 3.3.0
|
||||
*/
|
||||
public function test_product_auto_stock_status() {
|
||||
$product = new WC_Product();
|
||||
/**
|
||||
* Test the automatic stock status transitions done on product save.
|
||||
*
|
||||
* @since 3.3.0
|
||||
*/
|
||||
public function test_product_auto_stock_status() {
|
||||
$product = new WC_Product();
|
||||
|
||||
// Product should not have quantity and stock status should not be updated automatically if not managing stock.
|
||||
$product->set_manage_stock( false );
|
||||
$product->set_stock_quantity( 5 );
|
||||
$product->set_stock_status( 'instock' );
|
||||
$product->save();
|
||||
$this->assertEquals( '', $product->get_stock_quantity() );
|
||||
$this->assertEquals( 'instock', $product->get_stock_status() );
|
||||
$product->set_stock_status( 'outofstock' );
|
||||
$product->save();
|
||||
$this->assertEquals( 'outofstock', $product->get_stock_status() );
|
||||
// Product should not have quantity and stock status should not be updated automatically if not managing stock.
|
||||
$product->set_manage_stock( false );
|
||||
$product->set_stock_quantity( 5 );
|
||||
$product->set_stock_status( 'instock' );
|
||||
$product->save();
|
||||
$this->assertEquals( '', $product->get_stock_quantity() );
|
||||
$this->assertEquals( 'instock', $product->get_stock_status() );
|
||||
$product->set_stock_status( 'outofstock' );
|
||||
$product->save();
|
||||
$this->assertEquals( 'outofstock', $product->get_stock_status() );
|
||||
|
||||
$product->set_manage_stock( true );
|
||||
$product->set_manage_stock( true );
|
||||
|
||||
// Product should be out of stock if managing orders, no backorders allowed, and quantity too low.
|
||||
$product->set_stock_quantity( 0 );
|
||||
$product->set_stock_status( 'instock' );
|
||||
$product->set_backorders( 'no' );
|
||||
$product->save();
|
||||
$this->assertEquals( 0, $product->get_stock_quantity() );
|
||||
$this->assertEquals( 'outofstock', $product->get_stock_status() );
|
||||
// Product should be out of stock if managing orders, no backorders allowed, and quantity too low.
|
||||
$product->set_stock_quantity( 0 );
|
||||
$product->set_stock_status( 'instock' );
|
||||
$product->set_backorders( 'no' );
|
||||
$product->save();
|
||||
$this->assertEquals( 0, $product->get_stock_quantity() );
|
||||
$this->assertEquals( 'outofstock', $product->get_stock_status() );
|
||||
|
||||
// Product should be on backorder if managing orders, backorders allowed, and quantity too low.
|
||||
$product->set_stock_quantity( 0 );
|
||||
$product->set_stock_status( 'instock' );
|
||||
$product->set_backorders( 'yes' );
|
||||
$product->save();
|
||||
$this->assertEquals( 0, $product->get_stock_quantity() );
|
||||
$this->assertEquals( 'onbackorder', $product->get_stock_status() );
|
||||
// Product should be on backorder if managing orders, backorders allowed, and quantity too low.
|
||||
$product->set_stock_quantity( 0 );
|
||||
$product->set_stock_status( 'instock' );
|
||||
$product->set_backorders( 'yes' );
|
||||
$product->save();
|
||||
$this->assertEquals( 0, $product->get_stock_quantity() );
|
||||
$this->assertEquals( 'onbackorder', $product->get_stock_status() );
|
||||
|
||||
// Product should go to in stock if backordered and inventory increases.
|
||||
$product->set_stock_quantity( 5 );
|
||||
$product->set_stock_status( 'onbackorder' );
|
||||
$product->set_backorders( 'notify' );
|
||||
$product->save();
|
||||
$this->assertEquals( 5, $product->get_stock_quantity() );
|
||||
$this->assertEquals( 'instock', $product->get_stock_status() );
|
||||
// Product should go to in stock if backordered and inventory increases.
|
||||
$product->set_stock_quantity( 5 );
|
||||
$product->set_stock_status( 'onbackorder' );
|
||||
$product->set_backorders( 'notify' );
|
||||
$product->save();
|
||||
$this->assertEquals( 5, $product->get_stock_quantity() );
|
||||
$this->assertEquals( 'instock', $product->get_stock_status() );
|
||||
|
||||
// Product should go to in stock if out of stock and inventory increases.
|
||||
$product->set_stock_quantity( 3 );
|
||||
$product->set_stock_status( 'outofstock' );
|
||||
$product->set_backorders( 'no' );
|
||||
$product->save();
|
||||
$this->assertEquals( 3, $product->get_stock_quantity() );
|
||||
$this->assertEquals( 'instock', $product->get_stock_status() );
|
||||
}
|
||||
// Product should go to in stock if out of stock and inventory increases.
|
||||
$product->set_stock_quantity( 3 );
|
||||
$product->set_stock_status( 'outofstock' );
|
||||
$product->set_backorders( 'no' );
|
||||
$product->save();
|
||||
$this->assertEquals( 3, $product->get_stock_quantity() );
|
||||
$this->assertEquals( 'instock', $product->get_stock_status() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test product term setters and getters
|
||||
*
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public function test_product_term_getters_and_setters() {
|
||||
|
@ -164,7 +174,9 @@ class WC_Tests_Product_Data extends WC_Unit_Test_Case {
|
|||
'tag_ids' => array( $test_tag_1['term_id'], $test_tag_2['term_id'] ),
|
||||
'category_ids' => array( $test_cat_1['term_id'], $test_cat_2['term_id'] ),
|
||||
);
|
||||
$product = new WC_Product_Simple;
|
||||
|
||||
$product = new WC_Product_Simple();
|
||||
|
||||
foreach ( $getters_and_setters as $function => $value ) {
|
||||
$product->{"set_{$function}"}( $value );
|
||||
}
|
||||
|
@ -179,33 +191,37 @@ class WC_Tests_Product_Data extends WC_Unit_Test_Case {
|
|||
*
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public function test_grouped_product_getters_and_setters() {
|
||||
public function test_grouped_product_getters_and_setters() {
|
||||
$getters_and_setters = array(
|
||||
'children' => array( 1, 2, 3 ),
|
||||
);
|
||||
$product = new WC_Product_Grouped;
|
||||
|
||||
$product = new WC_Product_Grouped();
|
||||
|
||||
foreach ( $getters_and_setters as $function => $value ) {
|
||||
$product->{"set_{$function}"}( $value );
|
||||
$this->assertEquals( $value, $product->{"get_{$function}"}(), $function );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test external product setters and getters
|
||||
*
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public function test_external_product_getters_and_setters() {
|
||||
$time = time();
|
||||
$getters_and_setters = array(
|
||||
'button_text' => 'Test Button Text',
|
||||
'product_url' => 'https://wordpress.org',
|
||||
);
|
||||
$product = new WC_Product_External;
|
||||
foreach ( $getters_and_setters as $function => $value ) {
|
||||
$product->{"set_{$function}"}( $value );
|
||||
$this->assertEquals( $value, $product->{"get_{$function}"}(), $function );
|
||||
}
|
||||
}
|
||||
public function test_external_product_getters_and_setters() {
|
||||
$time = time();
|
||||
|
||||
$getters_and_setters = array(
|
||||
'button_text' => 'Test Button Text',
|
||||
'product_url' => 'https://wordpress.org',
|
||||
);
|
||||
|
||||
$product = new WC_Product_External();
|
||||
|
||||
foreach ( $getters_and_setters as $function => $value ) {
|
||||
$product->{"set_{$function}"}( $value );
|
||||
$this->assertEquals( $value, $product->{"get_{$function}"}(), $function );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
<?php
|
||||
/**
|
||||
* Unit tests for the WC_Product_Variable class.
|
||||
*
|
||||
* @package WooCommerce\Tests\Product
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class WC_Tests_Product_Variable.
|
||||
*
|
||||
* @package WooCommerce\Tests\Product
|
||||
*/
|
||||
class WC_Tests_Product_Variable extends WC_Unit_Test_Case {
|
||||
|
||||
|
@ -15,61 +18,61 @@ class WC_Tests_Product_Variable extends WC_Unit_Test_Case {
|
|||
$product_id = $product->save();
|
||||
$prices = $product->get_variation_prices();
|
||||
|
||||
$this->assertArrayHasKey( 'regular_price', $prices );
|
||||
$this->assertArrayHasKey( 'sale_price', $prices );
|
||||
$this->assertArrayHasKey( 'price', $prices );
|
||||
$this->assertArrayHasKey( 'regular_price', $prices );
|
||||
$this->assertArrayHasKey( 'sale_price', $prices );
|
||||
$this->assertArrayHasKey( 'price', $prices );
|
||||
$this->assertTrue( $product_id > 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the automatic stock status transitions done on variable product save.
|
||||
*
|
||||
* @since 3.3.0
|
||||
*/
|
||||
/**
|
||||
* Test the automatic stock status transitions done on variable product save.
|
||||
*
|
||||
* @since 3.3.0
|
||||
*/
|
||||
public function test_variable_product_auto_stock_status() {
|
||||
$product = new WC_Product_Variable();
|
||||
|
||||
// Product should not have quantity and stock status should be based on children stock status if not managing stock.
|
||||
$product->set_manage_stock( false );
|
||||
$product->set_stock_quantity( 5 );
|
||||
$product->set_stock_status( 'instock' );
|
||||
$product->save();
|
||||
$this->assertEquals( '', $product->get_stock_quantity() );
|
||||
$this->assertEquals( 'outofstock', $product->get_stock_status() );
|
||||
// Product should not have quantity and stock status should be based on children stock status if not managing stock.
|
||||
$product->set_manage_stock( false );
|
||||
$product->set_stock_quantity( 5 );
|
||||
$product->set_stock_status( 'instock' );
|
||||
$product->save();
|
||||
$this->assertEquals( '', $product->get_stock_quantity() );
|
||||
$this->assertEquals( 'outofstock', $product->get_stock_status() );
|
||||
|
||||
$product->set_manage_stock( true );
|
||||
$product->set_manage_stock( true );
|
||||
|
||||
// Product should be out of stock if managing orders, no backorders allowed, and quantity too low.
|
||||
$product->set_stock_quantity( 0 );
|
||||
$product->set_stock_status( 'instock' );
|
||||
$product->set_backorders( 'no' );
|
||||
$product->save();
|
||||
$this->assertEquals( 0, $product->get_stock_quantity() );
|
||||
$this->assertEquals( 'outofstock', $product->get_stock_status() );
|
||||
// Product should be out of stock if managing orders, no backorders allowed, and quantity too low.
|
||||
$product->set_stock_quantity( 0 );
|
||||
$product->set_stock_status( 'instock' );
|
||||
$product->set_backorders( 'no' );
|
||||
$product->save();
|
||||
$this->assertEquals( 0, $product->get_stock_quantity() );
|
||||
$this->assertEquals( 'outofstock', $product->get_stock_status() );
|
||||
|
||||
// Product should be on backorder if managing orders, backorders allowed, and quantity too low.
|
||||
$product->set_stock_quantity( 0 );
|
||||
$product->set_stock_status( 'instock' );
|
||||
$product->set_backorders( 'yes' );
|
||||
$product->save();
|
||||
$this->assertEquals( 0, $product->get_stock_quantity() );
|
||||
$this->assertEquals( 'onbackorder', $product->get_stock_status() );
|
||||
// Product should be on backorder if managing orders, backorders allowed, and quantity too low.
|
||||
$product->set_stock_quantity( 0 );
|
||||
$product->set_stock_status( 'instock' );
|
||||
$product->set_backorders( 'yes' );
|
||||
$product->save();
|
||||
$this->assertEquals( 0, $product->get_stock_quantity() );
|
||||
$this->assertEquals( 'onbackorder', $product->get_stock_status() );
|
||||
|
||||
// Product should go to in stock if backordered and inventory increases.
|
||||
$product->set_stock_quantity( 5 );
|
||||
$product->set_stock_status( 'onbackorder' );
|
||||
$product->set_backorders( 'notify' );
|
||||
$product->save();
|
||||
$this->assertEquals( 5, $product->get_stock_quantity() );
|
||||
$this->assertEquals( 'instock', $product->get_stock_status() );
|
||||
// Product should go to in stock if backordered and inventory increases.
|
||||
$product->set_stock_quantity( 5 );
|
||||
$product->set_stock_status( 'onbackorder' );
|
||||
$product->set_backorders( 'notify' );
|
||||
$product->save();
|
||||
$this->assertEquals( 5, $product->get_stock_quantity() );
|
||||
$this->assertEquals( 'instock', $product->get_stock_status() );
|
||||
|
||||
// Product should go to in stock if out of stock and inventory increases.
|
||||
$product->set_stock_quantity( 3 );
|
||||
$product->set_stock_status( 'outofstock' );
|
||||
$product->set_backorders( 'no' );
|
||||
$product->save();
|
||||
$this->assertEquals( 3, $product->get_stock_quantity() );
|
||||
$this->assertEquals( 'instock', $product->get_stock_status() );
|
||||
// Product should go to in stock if out of stock and inventory increases.
|
||||
$product->set_stock_quantity( 3 );
|
||||
$product->set_stock_status( 'outofstock' );
|
||||
$product->set_backorders( 'no' );
|
||||
$product->save();
|
||||
$this->assertEquals( 3, $product->get_stock_quantity() );
|
||||
$this->assertEquals( 'instock', $product->get_stock_status() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
/**
|
||||
* Class Product_Variation.
|
||||
*
|
||||
* @package WooCommerce\Tests\Product
|
||||
* @since 3.0
|
||||
*/
|
||||
class WC_Tests_Product_Variation extends WC_Unit_Test_Case {
|
||||
|
|
Loading…
Reference in New Issue