Some phpcs

This commit is contained in:
claudiulodro 2017-11-22 14:03:26 -08:00
parent 5513dc4546
commit a878b0cde5
5 changed files with 154 additions and 132 deletions

View File

@ -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' ) ) {

View File

@ -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.
}
/**

View File

@ -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,6 +15,7 @@ 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() {
@ -58,6 +66,7 @@ class WC_Tests_Product_Data extends WC_Unit_Test_Case {
'download_limit' => 5,
'attributes' => $attributes,
);
$product = new WC_Product();
foreach ( $getters_and_setters as $function => $value ) {
$product->{"set_{$function}"}( $value );
@ -72,7 +81,7 @@ 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();
@ -151,6 +160,7 @@ class WC_Tests_Product_Data extends WC_Unit_Test_Case {
/**
* 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 );
}
@ -183,7 +195,9 @@ class WC_Tests_Product_Data extends WC_Unit_Test_Case {
$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 );
@ -197,15 +211,17 @@ class WC_Tests_Product_Data extends WC_Unit_Test_Case {
*/
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;
$product = new WC_Product_External();
foreach ( $getters_and_setters as $function => $value ) {
$product->{"set_{$function}"}( $value );
$this->assertEquals( $value, $product->{"get_{$function}"}(), $function );
}
}
}

View File

@ -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 {

View File

@ -8,7 +8,6 @@
/**
* Class Product_Variation.
*
* @package WooCommerce\Tests\Product
* @since 3.0
*/
class WC_Tests_Product_Variation extends WC_Unit_Test_Case {