Fixed tests
This commit is contained in:
parent
fb8db3313e
commit
3bf47d7d97
|
@ -415,7 +415,15 @@ class WC_Query {
|
|||
public function get_catalog_ordering_args( $orderby = '', $order = '' ) {
|
||||
// Get ordering from query string unless defined.
|
||||
if ( ! $orderby ) {
|
||||
$orderby_value = isset( $_GET['orderby'] ) ? wc_clean( (string) wp_unslash( $_GET['orderby'] ) ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) ); // WPCS: sanitization ok, input var ok.
|
||||
$orderby_value = isset( $_GET['orderby'] ) ? wc_clean( (string) wp_unslash( $_GET['orderby'] ) ) : ''; // WPCS: sanitization ok, input var ok.
|
||||
|
||||
if ( ! $orderby_value ) {
|
||||
if ( is_search() ) {
|
||||
$orderby_value = 'relevance';
|
||||
} else {
|
||||
$orderby_value = apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
|
||||
}
|
||||
}
|
||||
|
||||
// Get order + orderby args from string.
|
||||
$orderby_value = explode( '-', $orderby_value );
|
||||
|
@ -426,23 +434,21 @@ class WC_Query {
|
|||
$orderby = strtolower( $orderby );
|
||||
$order = strtoupper( $order );
|
||||
$args = array(
|
||||
'orderby' => 'relevance',
|
||||
'order' => 'DESC',
|
||||
'orderby' => $orderby,
|
||||
'order' => ( 'DESC' === $order ) ? 'DESC' : 'ASC',
|
||||
'meta_key' => '', // @codingStandardsIgnoreLine
|
||||
);
|
||||
|
||||
// Set to default. Menu order for non-searches, relevance for searches.
|
||||
if ( ! is_search() ) {
|
||||
$args['orderby'] = 'menu_order title';
|
||||
$args['order'] = ( 'DESC' === $order ) ? 'DESC' : 'ASC';
|
||||
$args['meta_key'] = ''; // @codingStandardsIgnoreLine
|
||||
}
|
||||
|
||||
switch ( $orderby ) {
|
||||
case 'menu_order' :
|
||||
$args['orderby'] = 'menu_order title';
|
||||
break;
|
||||
case 'relevance' :
|
||||
$args['orderby']= 'relevance';
|
||||
$args['order'] = 'DESC';
|
||||
break;
|
||||
case 'rand' :
|
||||
// @codingStandardsIgnoreStart
|
||||
$args['orderby'] = 'rand';
|
||||
// @codingStandardsIgnoreEnd
|
||||
$args['orderby'] = 'rand'; // @codingStandardsIgnoreLine
|
||||
break;
|
||||
case 'date' :
|
||||
$args['orderby'] = 'date ID';
|
||||
|
|
|
@ -101,6 +101,8 @@ class WC_Template_Loader {
|
|||
'page' => $args->page,
|
||||
'columns' => $args->columns,
|
||||
'rows' => $args->rows,
|
||||
'orderby' => '',
|
||||
'order' => '',
|
||||
'paginate' => true,
|
||||
'cache' => false,
|
||||
)
|
||||
|
|
|
@ -116,8 +116,8 @@ class WC_Shortcode_Products {
|
|||
'limit' => '-1', // Results limit.
|
||||
'columns' => '3', // Number of columns.
|
||||
'rows' => '', // Number of rows. If defined, limit will be ignored.
|
||||
'orderby' => '', // menu_order, title, date, rand, price, popularity, rating, or id.
|
||||
'order' => '', // ASC or DESC.
|
||||
'orderby' => 'title', // menu_order, title, date, rand, price, popularity, rating, or id.
|
||||
'order' => 'ASC', // ASC or DESC.
|
||||
'ids' => '', // Comma separated IDs.
|
||||
'skus' => '', // Comma separated SKUs.
|
||||
'category' => '', // Comma separated category slugs.
|
||||
|
@ -185,8 +185,13 @@ class WC_Shortcode_Products {
|
|||
$ordering_args = WC()->query->get_catalog_ordering_args( $query_args['orderby'], $query_args['order'] );
|
||||
$query_args['orderby'] = $ordering_args['orderby'];
|
||||
$query_args['order'] = $ordering_args['order'];
|
||||
$query_args['posts_per_page'] = $this->attributes['limit'];
|
||||
$query_args['paged'] = absint( $this->attributes['page'] );
|
||||
if ( $ordering_args['meta_key'] ) {
|
||||
$query_args['meta_key'] = $ordering_args['meta_key'];
|
||||
}
|
||||
$query_args['posts_per_page'] = intval( $this->attributes['limit'] );
|
||||
if ( 1 < $this->attributes['page'] ) {
|
||||
$query_args['paged'] = absint( $this->attributes['page'] );
|
||||
}
|
||||
$query_args['meta_query'] = WC()->query->get_meta_query();
|
||||
$query_args['tax_query'] = array();
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
@ -274,10 +279,6 @@ class WC_Shortcode_Products {
|
|||
*/
|
||||
protected function set_categories_query_args( &$query_args ) {
|
||||
if ( ! empty( $this->attributes['category'] ) ) {
|
||||
// @codingStandardsIgnoreStart
|
||||
$query_args['meta_key'] = $ordering_args['meta_key'];
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
$query_args['tax_query'][] = array(
|
||||
'taxonomy' => 'product_cat',
|
||||
'terms' => array_map( 'sanitize_title', explode( ',', $this->attributes['category'] ) ),
|
||||
|
|
|
@ -14,7 +14,7 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
|||
$shortcode = new WC_Shortcode_Products();
|
||||
$expected = array(
|
||||
'limit' => '-1',
|
||||
'columns' => '4',
|
||||
'columns' => '3',
|
||||
'orderby' => 'title',
|
||||
'order' => 'ASC',
|
||||
'ids' => '',
|
||||
|
@ -26,6 +26,11 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
|||
'terms_operator' => 'IN',
|
||||
'visibility' => 'visible',
|
||||
'class' => '',
|
||||
'rows' => '',
|
||||
'page' => 1,
|
||||
'paginate' => false,
|
||||
'cache' => true,
|
||||
|
||||
);
|
||||
$this->assertEquals( $expected, $shortcode->get_attributes() );
|
||||
|
||||
|
@ -35,7 +40,7 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
|||
) );
|
||||
$expected2 = array(
|
||||
'limit' => '-1',
|
||||
'columns' => '4',
|
||||
'columns' => '3',
|
||||
'orderby' => 'id',
|
||||
'order' => 'DESC',
|
||||
'ids' => '',
|
||||
|
@ -47,6 +52,10 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
|||
'terms_operator' => 'IN',
|
||||
'visibility' => 'visible',
|
||||
'class' => '',
|
||||
'rows' => '',
|
||||
'page' => 1,
|
||||
'paginate' => false,
|
||||
'cache' => true,
|
||||
);
|
||||
$this->assertEquals( $expected2, $shortcode2->get_attributes() );
|
||||
}
|
||||
|
@ -67,7 +76,7 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
|||
'no_found_rows' => true,
|
||||
'orderby' => 'title',
|
||||
'order' => 'ASC',
|
||||
'posts_per_page' => -1,
|
||||
'posts_per_page' => '-1',
|
||||
'meta_query' => $meta_query,
|
||||
'tax_query' => $tax_query,
|
||||
);
|
||||
|
@ -85,7 +94,7 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
|||
'no_found_rows' => true,
|
||||
'orderby' => 'id',
|
||||
'order' => 'DESC',
|
||||
'posts_per_page' => -1,
|
||||
'posts_per_page' => '-1',
|
||||
'meta_query' => $meta_query,
|
||||
'tax_query' => $tax_query,
|
||||
);
|
||||
|
@ -102,7 +111,7 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
|||
'no_found_rows' => true,
|
||||
'orderby' => 'title',
|
||||
'order' => 'ASC',
|
||||
'posts_per_page' => -1,
|
||||
'posts_per_page' => '-1',
|
||||
'meta_query' => $meta_query,
|
||||
'tax_query' => $tax_query,
|
||||
'post__in' => array( '1', '2', '3' ),
|
||||
|
@ -119,7 +128,7 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
|||
$shortcode4 = new WC_Shortcode_Products( array(
|
||||
'per_page' => '12',
|
||||
'columns' => '4',
|
||||
'orderby' => 'menu_order title',
|
||||
'orderby' => 'title',
|
||||
'order' => 'ASC',
|
||||
'category' => 'clothing',
|
||||
'operator' => 'IN',
|
||||
|
@ -129,12 +138,11 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
|||
'post_status' => 'publish',
|
||||
'ignore_sticky_posts' => true,
|
||||
'no_found_rows' => true,
|
||||
'orderby' => 'menu_order title',
|
||||
'orderby' => 'title',
|
||||
'order' => 'ASC',
|
||||
'posts_per_page' => 12,
|
||||
'posts_per_page' => '12',
|
||||
'meta_query' => $meta_query,
|
||||
'tax_query' => $tax_query,
|
||||
'meta_key' => '',
|
||||
);
|
||||
$expected4['tax_query'][] = array(
|
||||
'taxonomy' => 'product_cat',
|
||||
|
@ -159,9 +167,9 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
|||
'post_status' => 'publish',
|
||||
'ignore_sticky_posts' => true,
|
||||
'no_found_rows' => true,
|
||||
'orderby' => 'date',
|
||||
'orderby' => 'date ID',
|
||||
'order' => 'DESC',
|
||||
'posts_per_page' => 12,
|
||||
'posts_per_page' => '12',
|
||||
'meta_query' => $meta_query,
|
||||
'tax_query' => $tax_query,
|
||||
);
|
||||
|
@ -180,7 +188,7 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
|||
'no_found_rows' => true,
|
||||
'orderby' => 'title',
|
||||
'order' => 'ASC',
|
||||
'posts_per_page' => 1,
|
||||
'posts_per_page' => '1',
|
||||
'meta_query' => $meta_query,
|
||||
'tax_query' => $tax_query,
|
||||
'p' => '1',
|
||||
|
@ -272,7 +280,7 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
|||
'post_status' => 'publish',
|
||||
'ignore_sticky_posts' => true,
|
||||
'no_found_rows' => true,
|
||||
'orderby' => 'date',
|
||||
'orderby' => 'date ID',
|
||||
'order' => 'DESC',
|
||||
'posts_per_page' => 12,
|
||||
'meta_query' => $meta_query,
|
||||
|
|
Loading…
Reference in New Issue