2017-08-24 23:12:12 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class WC_Shortcode_Products.
|
|
|
|
*
|
|
|
|
* @package WooCommerce\Tests\Shortcodes
|
|
|
|
*/
|
|
|
|
class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: WC_Shortcode_Products::get_attributes.
|
|
|
|
*/
|
|
|
|
public function test_get_attributes() {
|
|
|
|
$shortcode = new WC_Shortcode_Products();
|
|
|
|
$expected = array(
|
2017-08-28 20:45:56 +00:00
|
|
|
'limit' => '-1',
|
2018-03-19 13:05:43 +00:00
|
|
|
'columns' => '4',
|
2017-08-28 20:45:56 +00:00
|
|
|
'orderby' => 'title',
|
|
|
|
'order' => 'ASC',
|
|
|
|
'ids' => '',
|
|
|
|
'skus' => '',
|
|
|
|
'category' => '',
|
|
|
|
'cat_operator' => 'IN',
|
|
|
|
'attribute' => '',
|
|
|
|
'terms' => '',
|
|
|
|
'terms_operator' => 'IN',
|
2017-08-29 21:29:29 +00:00
|
|
|
'visibility' => 'visible',
|
2017-08-28 20:45:56 +00:00
|
|
|
'class' => '',
|
2017-11-10 17:45:01 +00:00
|
|
|
'rows' => '',
|
|
|
|
'page' => 1,
|
|
|
|
'paginate' => false,
|
|
|
|
'cache' => true,
|
2017-12-01 16:39:02 +00:00
|
|
|
'tag' => '',
|
2017-08-24 23:12:12 +00:00
|
|
|
);
|
|
|
|
$this->assertEquals( $expected, $shortcode->get_attributes() );
|
|
|
|
|
|
|
|
$shortcode2 = new WC_Shortcode_Products( array(
|
|
|
|
'orderby' => 'id',
|
2017-08-25 00:24:05 +00:00
|
|
|
'order' => 'DESC',
|
2017-08-24 23:12:12 +00:00
|
|
|
) );
|
|
|
|
$expected2 = array(
|
2017-08-28 20:45:56 +00:00
|
|
|
'limit' => '-1',
|
2018-03-19 13:05:43 +00:00
|
|
|
'columns' => '4',
|
2017-08-28 20:45:56 +00:00
|
|
|
'orderby' => 'id',
|
|
|
|
'order' => 'DESC',
|
|
|
|
'ids' => '',
|
|
|
|
'skus' => '',
|
|
|
|
'category' => '',
|
|
|
|
'cat_operator' => 'IN',
|
|
|
|
'attribute' => '',
|
|
|
|
'terms' => '',
|
|
|
|
'terms_operator' => 'IN',
|
2017-08-29 21:29:29 +00:00
|
|
|
'visibility' => 'visible',
|
2017-08-28 20:45:56 +00:00
|
|
|
'class' => '',
|
2017-11-10 17:45:01 +00:00
|
|
|
'rows' => '',
|
|
|
|
'page' => 1,
|
|
|
|
'paginate' => false,
|
|
|
|
'cache' => true,
|
2017-12-01 16:39:02 +00:00
|
|
|
'tag' => '',
|
2017-08-24 23:12:12 +00:00
|
|
|
);
|
|
|
|
$this->assertEquals( $expected2, $shortcode2->get_attributes() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: WC_Shortcode_Products::get_query_args.
|
|
|
|
*/
|
|
|
|
public function test_get_query_args() {
|
2017-08-25 00:38:42 +00:00
|
|
|
$meta_query = WC()->query->get_meta_query();
|
|
|
|
$tax_query = WC()->query->get_tax_query();
|
|
|
|
|
2018-03-01 18:05:22 +00:00
|
|
|
// Empty products shortcode.
|
2017-08-24 23:12:12 +00:00
|
|
|
$shortcode = new WC_Shortcode_Products();
|
|
|
|
$expected = array(
|
|
|
|
'post_type' => 'product',
|
|
|
|
'post_status' => 'publish',
|
2017-08-25 01:16:42 +00:00
|
|
|
'ignore_sticky_posts' => true,
|
|
|
|
'no_found_rows' => true,
|
2017-08-24 23:12:12 +00:00
|
|
|
'orderby' => 'title',
|
2017-08-25 00:24:05 +00:00
|
|
|
'order' => 'ASC',
|
2017-11-10 17:45:01 +00:00
|
|
|
'posts_per_page' => '-1',
|
2017-08-25 00:38:42 +00:00
|
|
|
'meta_query' => $meta_query,
|
|
|
|
'tax_query' => $tax_query,
|
2017-11-16 17:14:36 +00:00
|
|
|
'fields' => 'ids',
|
2017-08-24 23:12:12 +00:00
|
|
|
);
|
|
|
|
$this->assertEquals( $expected, $shortcode->get_query_args() );
|
|
|
|
|
2017-08-25 00:38:42 +00:00
|
|
|
// products shortcode with attributes.
|
2017-08-24 23:12:12 +00:00
|
|
|
$shortcode2 = new WC_Shortcode_Products( array(
|
|
|
|
'orderby' => 'id',
|
2017-08-25 00:24:05 +00:00
|
|
|
'order' => 'DESC',
|
2017-08-24 23:12:12 +00:00
|
|
|
) );
|
|
|
|
$expected2 = array(
|
|
|
|
'post_type' => 'product',
|
|
|
|
'post_status' => 'publish',
|
2017-08-25 01:16:42 +00:00
|
|
|
'ignore_sticky_posts' => true,
|
|
|
|
'no_found_rows' => true,
|
2017-08-24 23:12:12 +00:00
|
|
|
'orderby' => 'id',
|
2017-08-25 00:24:05 +00:00
|
|
|
'order' => 'DESC',
|
2017-11-10 17:45:01 +00:00
|
|
|
'posts_per_page' => '-1',
|
2017-08-25 00:38:42 +00:00
|
|
|
'meta_query' => $meta_query,
|
|
|
|
'tax_query' => $tax_query,
|
2017-11-16 17:14:36 +00:00
|
|
|
'fields' => 'ids',
|
2017-08-24 23:12:12 +00:00
|
|
|
);
|
|
|
|
$this->assertEquals( $expected2, $shortcode2->get_query_args() );
|
|
|
|
|
2017-08-29 21:29:29 +00:00
|
|
|
$shortcode3 = new WC_Shortcode_Products( array(
|
2017-08-24 23:12:12 +00:00
|
|
|
'ids' => '1,2,3',
|
|
|
|
'skus' => 'foo,bar',
|
|
|
|
) );
|
2017-08-29 21:29:29 +00:00
|
|
|
$expected3 = array(
|
2017-08-24 23:12:12 +00:00
|
|
|
'post_type' => 'product',
|
|
|
|
'post_status' => 'publish',
|
2017-08-25 01:16:42 +00:00
|
|
|
'ignore_sticky_posts' => true,
|
|
|
|
'no_found_rows' => true,
|
2017-08-24 23:12:12 +00:00
|
|
|
'orderby' => 'title',
|
2017-08-25 00:24:05 +00:00
|
|
|
'order' => 'ASC',
|
2017-11-10 17:45:01 +00:00
|
|
|
'posts_per_page' => '-1',
|
2017-08-25 00:38:42 +00:00
|
|
|
'meta_query' => $meta_query,
|
|
|
|
'tax_query' => $tax_query,
|
2017-08-24 23:12:12 +00:00
|
|
|
'post__in' => array( '1', '2', '3' ),
|
2017-11-16 17:14:36 +00:00
|
|
|
'fields' => 'ids',
|
2017-08-24 23:12:12 +00:00
|
|
|
);
|
2017-08-29 21:29:29 +00:00
|
|
|
$expected3['meta_query'][] = array(
|
2017-08-24 23:12:12 +00:00
|
|
|
'key' => '_sku',
|
|
|
|
'value' => array( 'foo', 'bar' ),
|
|
|
|
'compare' => 'IN',
|
|
|
|
);
|
|
|
|
|
2017-08-29 21:29:29 +00:00
|
|
|
$this->assertEquals( $expected3, $shortcode3->get_query_args() );
|
2017-08-25 00:24:05 +00:00
|
|
|
|
2017-08-25 00:38:42 +00:00
|
|
|
// product_category shortcode.
|
2017-08-29 21:29:29 +00:00
|
|
|
$shortcode4 = new WC_Shortcode_Products( array(
|
2017-08-25 00:24:05 +00:00
|
|
|
'per_page' => '12',
|
2017-08-25 00:38:42 +00:00
|
|
|
'columns' => '4',
|
2017-11-10 17:45:01 +00:00
|
|
|
'orderby' => 'title',
|
2017-08-25 00:38:42 +00:00
|
|
|
'order' => 'ASC',
|
|
|
|
'category' => 'clothing',
|
|
|
|
'operator' => 'IN',
|
2017-08-25 01:16:42 +00:00
|
|
|
), 'product_category' );
|
2017-08-29 21:29:29 +00:00
|
|
|
$expected4 = array(
|
2017-08-25 00:24:05 +00:00
|
|
|
'post_type' => 'product',
|
|
|
|
'post_status' => 'publish',
|
2017-08-25 01:16:42 +00:00
|
|
|
'ignore_sticky_posts' => true,
|
|
|
|
'no_found_rows' => true,
|
2017-11-10 17:45:01 +00:00
|
|
|
'orderby' => 'title',
|
2017-08-25 00:24:05 +00:00
|
|
|
'order' => 'ASC',
|
2017-11-10 17:45:01 +00:00
|
|
|
'posts_per_page' => '12',
|
2017-08-25 00:38:42 +00:00
|
|
|
'meta_query' => $meta_query,
|
|
|
|
'tax_query' => $tax_query,
|
2017-11-16 17:14:36 +00:00
|
|
|
'fields' => 'ids',
|
2017-08-25 00:24:05 +00:00
|
|
|
);
|
2017-08-29 21:29:29 +00:00
|
|
|
$expected4['tax_query'][] = array(
|
2018-05-24 15:12:48 +00:00
|
|
|
'taxonomy' => 'product_cat',
|
|
|
|
'terms' => array( 'clothing' ),
|
|
|
|
'field' => 'slug',
|
|
|
|
'operator' => 'IN',
|
|
|
|
'include_children' => true,
|
2017-08-25 00:24:05 +00:00
|
|
|
);
|
2017-08-29 21:29:29 +00:00
|
|
|
|
|
|
|
$this->assertEquals( $expected4, $shortcode4->get_query_args() );
|
2017-08-25 00:38:42 +00:00
|
|
|
|
2018-03-01 18:05:22 +00:00
|
|
|
// product_category shortcode using category ids.
|
|
|
|
$shortcode4_id = new WC_Shortcode_Products( array(
|
|
|
|
'per_page' => '12',
|
|
|
|
'columns' => '4',
|
|
|
|
'orderby' => 'title',
|
|
|
|
'order' => 'ASC',
|
|
|
|
'category' => '123',
|
|
|
|
'operator' => 'IN',
|
|
|
|
), 'product_category' );
|
|
|
|
$expected4_id = array(
|
|
|
|
'post_type' => 'product',
|
|
|
|
'post_status' => 'publish',
|
|
|
|
'ignore_sticky_posts' => true,
|
|
|
|
'no_found_rows' => true,
|
|
|
|
'orderby' => 'title',
|
|
|
|
'order' => 'ASC',
|
|
|
|
'posts_per_page' => '12',
|
|
|
|
'meta_query' => $meta_query,
|
|
|
|
'tax_query' => $tax_query,
|
|
|
|
'fields' => 'ids',
|
|
|
|
);
|
|
|
|
$expected4_id['tax_query'][] = array(
|
2018-05-24 15:12:48 +00:00
|
|
|
'taxonomy' => 'product_cat',
|
|
|
|
'terms' => array( 123 ),
|
|
|
|
'field' => 'term_id',
|
|
|
|
'operator' => 'IN',
|
|
|
|
'include_children' => true,
|
2018-03-01 18:05:22 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals( $expected4_id, $shortcode4_id->get_query_args() );
|
|
|
|
|
2017-08-25 00:38:42 +00:00
|
|
|
// recent_products shortcode.
|
2017-08-29 21:29:29 +00:00
|
|
|
$shortcode5 = new WC_Shortcode_Products( array(
|
2017-08-25 00:38:42 +00:00
|
|
|
'per_page' => '12',
|
|
|
|
'columns' => '4',
|
|
|
|
'orderby' => 'date',
|
|
|
|
'order' => 'DESC',
|
|
|
|
'category' => '',
|
|
|
|
'operator' => 'IN',
|
2017-08-25 01:16:42 +00:00
|
|
|
), 'recent_products' );
|
2017-08-29 21:29:29 +00:00
|
|
|
$expected5 = array(
|
2017-08-25 00:38:42 +00:00
|
|
|
'post_type' => 'product',
|
|
|
|
'post_status' => 'publish',
|
2017-08-25 01:16:42 +00:00
|
|
|
'ignore_sticky_posts' => true,
|
|
|
|
'no_found_rows' => true,
|
2017-11-10 17:45:01 +00:00
|
|
|
'orderby' => 'date ID',
|
2017-08-25 00:38:42 +00:00
|
|
|
'order' => 'DESC',
|
2017-11-10 17:45:01 +00:00
|
|
|
'posts_per_page' => '12',
|
2017-08-25 00:38:42 +00:00
|
|
|
'meta_query' => $meta_query,
|
|
|
|
'tax_query' => $tax_query,
|
2017-11-16 17:14:36 +00:00
|
|
|
'fields' => 'ids',
|
2017-08-25 00:38:42 +00:00
|
|
|
);
|
|
|
|
|
2017-08-29 21:29:29 +00:00
|
|
|
$this->assertEquals( $expected5, $shortcode5->get_query_args() );
|
2017-08-25 01:16:42 +00:00
|
|
|
|
|
|
|
// product shortcode.
|
2017-08-29 21:29:29 +00:00
|
|
|
$shortcode6 = new WC_Shortcode_Products( array(
|
2017-08-25 01:16:42 +00:00
|
|
|
'ids' => '1',
|
|
|
|
'per_page' => '1',
|
|
|
|
), 'product' );
|
2017-08-29 21:29:29 +00:00
|
|
|
$expected6 = array(
|
2017-08-25 01:16:42 +00:00
|
|
|
'post_type' => 'product',
|
|
|
|
'post_status' => 'publish',
|
|
|
|
'ignore_sticky_posts' => true,
|
|
|
|
'no_found_rows' => true,
|
|
|
|
'orderby' => 'title',
|
|
|
|
'order' => 'ASC',
|
2017-11-10 17:45:01 +00:00
|
|
|
'posts_per_page' => '1',
|
2017-08-25 01:16:42 +00:00
|
|
|
'meta_query' => $meta_query,
|
|
|
|
'tax_query' => $tax_query,
|
|
|
|
'p' => '1',
|
2017-11-16 17:14:36 +00:00
|
|
|
'fields' => 'ids',
|
2017-08-25 01:16:42 +00:00
|
|
|
);
|
|
|
|
|
2017-08-29 21:29:29 +00:00
|
|
|
$this->assertEquals( $expected6, $shortcode6->get_query_args() );
|
2017-08-25 14:00:48 +00:00
|
|
|
|
|
|
|
// sale_products shortcode.
|
2017-08-29 21:29:29 +00:00
|
|
|
$shortcode7 = new WC_Shortcode_Products( array(
|
2017-08-25 14:00:48 +00:00
|
|
|
'per_page' => '12',
|
|
|
|
'columns' => '4',
|
|
|
|
'orderby' => 'title',
|
|
|
|
'order' => 'ASC',
|
|
|
|
'category' => '',
|
|
|
|
'operator' => 'IN',
|
|
|
|
), 'sale_products' );
|
2017-08-29 21:29:29 +00:00
|
|
|
$expected7 = array(
|
2017-08-25 14:00:48 +00:00
|
|
|
'post_type' => 'product',
|
|
|
|
'post_status' => 'publish',
|
|
|
|
'ignore_sticky_posts' => true,
|
|
|
|
'no_found_rows' => true,
|
|
|
|
'orderby' => 'title',
|
|
|
|
'order' => 'ASC',
|
|
|
|
'posts_per_page' => 12,
|
|
|
|
'meta_query' => $meta_query,
|
|
|
|
'tax_query' => $tax_query,
|
|
|
|
'post__in' => array_merge( array( 0 ), wc_get_product_ids_on_sale() ),
|
2017-11-16 17:14:36 +00:00
|
|
|
'fields' => 'ids',
|
2017-08-25 14:00:48 +00:00
|
|
|
);
|
|
|
|
|
2017-08-29 21:29:29 +00:00
|
|
|
$this->assertEquals( $expected7, $shortcode7->get_query_args() );
|
2017-08-25 14:46:47 +00:00
|
|
|
|
|
|
|
// best_selling_products shortcode.
|
2017-08-29 21:29:29 +00:00
|
|
|
$shortcode8 = new WC_Shortcode_Products( array(
|
2017-08-25 14:46:47 +00:00
|
|
|
'per_page' => '12',
|
|
|
|
'columns' => '4',
|
|
|
|
'category' => '',
|
|
|
|
'operator' => 'IN',
|
|
|
|
), 'best_selling_products' );
|
2017-08-29 21:29:29 +00:00
|
|
|
$expected8 = array(
|
2017-08-25 14:46:47 +00:00
|
|
|
'post_type' => 'product',
|
|
|
|
'post_status' => 'publish',
|
|
|
|
'ignore_sticky_posts' => true,
|
|
|
|
'no_found_rows' => true,
|
|
|
|
'orderby' => 'meta_value_num',
|
|
|
|
'order' => 'DESC',
|
|
|
|
'posts_per_page' => 12,
|
|
|
|
'meta_query' => $meta_query,
|
|
|
|
'tax_query' => $tax_query,
|
|
|
|
'meta_key' => 'total_sales',
|
2017-11-16 17:14:36 +00:00
|
|
|
'fields' => 'ids',
|
2017-08-25 14:46:47 +00:00
|
|
|
);
|
|
|
|
|
2017-08-29 21:29:29 +00:00
|
|
|
$this->assertEquals( $expected8, $shortcode8->get_query_args() );
|
2017-08-25 18:55:34 +00:00
|
|
|
|
|
|
|
// top_rated_products shortcode.
|
2017-08-29 21:29:29 +00:00
|
|
|
$shortcode9 = new WC_Shortcode_Products( array(
|
2017-08-25 18:55:34 +00:00
|
|
|
'per_page' => '12',
|
|
|
|
'columns' => '4',
|
|
|
|
'orderby' => 'title',
|
|
|
|
'order' => 'ASC',
|
|
|
|
'category' => '',
|
|
|
|
'operator' => 'IN',
|
|
|
|
), 'top_rated_products' );
|
2017-08-29 21:29:29 +00:00
|
|
|
$expected9 = array(
|
2017-08-25 18:55:34 +00:00
|
|
|
'post_type' => 'product',
|
|
|
|
'post_status' => 'publish',
|
|
|
|
'ignore_sticky_posts' => true,
|
|
|
|
'no_found_rows' => true,
|
|
|
|
'orderby' => 'title',
|
|
|
|
'order' => 'ASC',
|
|
|
|
'posts_per_page' => 12,
|
|
|
|
'meta_query' => $meta_query,
|
|
|
|
'tax_query' => $tax_query,
|
2017-11-16 17:14:36 +00:00
|
|
|
'fields' => 'ids',
|
2017-08-25 18:55:34 +00:00
|
|
|
);
|
|
|
|
|
2017-08-29 21:29:29 +00:00
|
|
|
$this->assertEquals( $expected9, $shortcode9->get_query_args() );
|
|
|
|
|
2017-08-25 21:42:02 +00:00
|
|
|
// featured_products shortcode.
|
2017-08-29 21:29:29 +00:00
|
|
|
$shortcode10 = new WC_Shortcode_Products( array(
|
|
|
|
'per_page' => '12',
|
|
|
|
'columns' => '4',
|
|
|
|
'orderby' => 'date',
|
|
|
|
'order' => 'DESC',
|
|
|
|
'category' => '',
|
|
|
|
'operator' => 'IN',
|
|
|
|
'visibility' => 'featured',
|
|
|
|
) );
|
|
|
|
$expected10 = array(
|
2017-08-25 21:42:02 +00:00
|
|
|
'post_type' => 'product',
|
|
|
|
'post_status' => 'publish',
|
|
|
|
'ignore_sticky_posts' => true,
|
|
|
|
'no_found_rows' => true,
|
2017-11-10 17:45:01 +00:00
|
|
|
'orderby' => 'date ID',
|
2017-08-25 21:42:02 +00:00
|
|
|
'order' => 'DESC',
|
|
|
|
'posts_per_page' => 12,
|
|
|
|
'meta_query' => $meta_query,
|
|
|
|
'tax_query' => array_merge( $tax_query, array(
|
|
|
|
array(
|
2017-08-29 21:29:29 +00:00
|
|
|
'taxonomy' => 'product_visibility',
|
|
|
|
'terms' => 'featured',
|
|
|
|
'field' => 'name',
|
|
|
|
'operator' => 'IN',
|
|
|
|
'include_children' => false,
|
2017-08-25 21:42:02 +00:00
|
|
|
),
|
|
|
|
) ),
|
2017-11-16 17:14:36 +00:00
|
|
|
'fields' => 'ids',
|
2017-08-25 21:42:02 +00:00
|
|
|
);
|
|
|
|
|
2017-08-29 21:29:29 +00:00
|
|
|
$this->assertEquals( $expected10, $shortcode10->get_query_args() );
|
|
|
|
|
2017-08-25 22:07:10 +00:00
|
|
|
// product_attribute shortcode.
|
2017-08-29 21:29:29 +00:00
|
|
|
$shortcode11 = new WC_Shortcode_Products( array(
|
2017-08-25 22:07:10 +00:00
|
|
|
'per_page' => '12',
|
|
|
|
'columns' => '4',
|
|
|
|
'orderby' => 'title',
|
|
|
|
'order' => 'asc',
|
|
|
|
'attribute' => 'color',
|
|
|
|
'filter' => 'black',
|
|
|
|
), 'product_attribute' );
|
2017-08-29 21:29:29 +00:00
|
|
|
$expected11 = array(
|
2017-08-25 22:07:10 +00:00
|
|
|
'post_type' => 'product',
|
|
|
|
'post_status' => 'publish',
|
|
|
|
'ignore_sticky_posts' => true,
|
|
|
|
'no_found_rows' => true,
|
|
|
|
'orderby' => 'title',
|
|
|
|
'order' => 'ASC',
|
|
|
|
'posts_per_page' => 12,
|
|
|
|
'meta_query' => $meta_query,
|
|
|
|
'tax_query' => array_merge( $tax_query, array(
|
|
|
|
array(
|
|
|
|
'taxonomy' => 'pa_color',
|
|
|
|
'terms' => array( 'black' ),
|
|
|
|
'field' => 'slug',
|
2017-08-28 20:45:56 +00:00
|
|
|
'operator' => 'IN',
|
2017-08-25 22:07:10 +00:00
|
|
|
),
|
|
|
|
) ),
|
2017-11-16 17:14:36 +00:00
|
|
|
'fields' => 'ids',
|
2017-08-25 22:07:10 +00:00
|
|
|
);
|
|
|
|
|
2017-08-29 21:29:29 +00:00
|
|
|
$this->assertEquals( $expected11, $shortcode11->get_query_args() );
|
|
|
|
|
2018-03-01 18:05:22 +00:00
|
|
|
// product_attribute shortcode using term ids.
|
|
|
|
$shortcode11_id = new WC_Shortcode_Products( array(
|
|
|
|
'per_page' => '12',
|
|
|
|
'columns' => '4',
|
|
|
|
'orderby' => 'title',
|
|
|
|
'order' => 'asc',
|
|
|
|
'attribute' => 'color',
|
|
|
|
'terms' => '123',
|
|
|
|
), 'product_attribute' );
|
|
|
|
$expected11_id = array(
|
|
|
|
'post_type' => 'product',
|
|
|
|
'post_status' => 'publish',
|
|
|
|
'ignore_sticky_posts' => true,
|
|
|
|
'no_found_rows' => true,
|
|
|
|
'orderby' => 'title',
|
|
|
|
'order' => 'ASC',
|
|
|
|
'posts_per_page' => 12,
|
|
|
|
'meta_query' => $meta_query,
|
|
|
|
'tax_query' => array_merge( $tax_query, array(
|
|
|
|
array(
|
|
|
|
'taxonomy' => 'pa_color',
|
|
|
|
'terms' => array( 123 ),
|
|
|
|
'field' => 'term_id',
|
|
|
|
'operator' => 'IN',
|
|
|
|
),
|
|
|
|
) ),
|
|
|
|
'fields' => 'ids',
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals( $expected11_id, $shortcode11_id->get_query_args() );
|
|
|
|
|
2017-08-29 21:29:29 +00:00
|
|
|
// Check for visibility shortcode.
|
|
|
|
$shortcode12 = new WC_Shortcode_Products( array(
|
|
|
|
'visibility' => 'hidden',
|
|
|
|
) );
|
|
|
|
$expected12 = array(
|
|
|
|
'post_type' => 'product',
|
|
|
|
'post_status' => 'publish',
|
|
|
|
'ignore_sticky_posts' => true,
|
|
|
|
'no_found_rows' => true,
|
|
|
|
'orderby' => 'title',
|
|
|
|
'order' => 'ASC',
|
|
|
|
'posts_per_page' => -1,
|
|
|
|
'meta_query' => $meta_query,
|
|
|
|
'tax_query' => array(
|
|
|
|
array(
|
|
|
|
'taxonomy' => 'product_visibility',
|
|
|
|
'terms' => array( 'exclude-from-catalog', 'exclude-from-search' ),
|
|
|
|
'field' => 'name',
|
|
|
|
'operator' => 'AND',
|
|
|
|
'include_children' => false,
|
|
|
|
),
|
|
|
|
),
|
2017-11-16 17:14:36 +00:00
|
|
|
'fields' => 'ids',
|
2017-08-29 21:29:29 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals( $expected12, $shortcode12->get_query_args() );
|
|
|
|
|
|
|
|
$shortcode13 = new WC_Shortcode_Products( array(
|
|
|
|
'visibility' => 'catalog',
|
|
|
|
) );
|
|
|
|
$expected13 = array(
|
|
|
|
'post_type' => 'product',
|
|
|
|
'post_status' => 'publish',
|
|
|
|
'ignore_sticky_posts' => true,
|
|
|
|
'no_found_rows' => true,
|
|
|
|
'orderby' => 'title',
|
|
|
|
'order' => 'ASC',
|
|
|
|
'posts_per_page' => -1,
|
|
|
|
'meta_query' => $meta_query,
|
|
|
|
'tax_query' => array(
|
|
|
|
array(
|
|
|
|
'taxonomy' => 'product_visibility',
|
|
|
|
'terms' => 'exclude-from-search',
|
|
|
|
'field' => 'name',
|
|
|
|
'operator' => 'IN',
|
|
|
|
'include_children' => false,
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'taxonomy' => 'product_visibility',
|
|
|
|
'terms' => 'exclude-from-catalog',
|
|
|
|
'field' => 'name',
|
|
|
|
'operator' => 'NOT IN',
|
|
|
|
'include_children' => false,
|
|
|
|
),
|
|
|
|
),
|
2017-11-16 17:14:36 +00:00
|
|
|
'fields' => 'ids',
|
2017-08-29 21:29:29 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals( $expected13, $shortcode13->get_query_args() );
|
|
|
|
|
|
|
|
$shortcode14 = new WC_Shortcode_Products( array(
|
|
|
|
'visibility' => 'search',
|
|
|
|
) );
|
|
|
|
$expected14 = array(
|
|
|
|
'post_type' => 'product',
|
|
|
|
'post_status' => 'publish',
|
|
|
|
'ignore_sticky_posts' => true,
|
|
|
|
'no_found_rows' => true,
|
|
|
|
'orderby' => 'title',
|
|
|
|
'order' => 'ASC',
|
|
|
|
'posts_per_page' => -1,
|
|
|
|
'meta_query' => $meta_query,
|
|
|
|
'tax_query' => array(
|
|
|
|
array(
|
|
|
|
'taxonomy' => 'product_visibility',
|
|
|
|
'terms' => 'exclude-from-catalog',
|
|
|
|
'field' => 'name',
|
|
|
|
'operator' => 'IN',
|
|
|
|
'include_children' => false,
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'taxonomy' => 'product_visibility',
|
|
|
|
'terms' => 'exclude-from-search',
|
|
|
|
'field' => 'name',
|
|
|
|
'operator' => 'NOT IN',
|
|
|
|
'include_children' => false,
|
|
|
|
),
|
|
|
|
),
|
2017-11-16 17:14:36 +00:00
|
|
|
'fields' => 'ids',
|
2017-08-29 21:29:29 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals( $expected14, $shortcode14->get_query_args() );
|
2018-05-24 15:12:48 +00:00
|
|
|
|
|
|
|
// products shortcode -- select multiple categories using AND operator.
|
|
|
|
$shortcode15 = new WC_Shortcode_Products( array(
|
|
|
|
'category' => 'cat1,cat2',
|
|
|
|
'cat_operator' => 'AND',
|
|
|
|
) );
|
|
|
|
$expected15 = array(
|
|
|
|
'post_type' => 'product',
|
|
|
|
'post_status' => 'publish',
|
|
|
|
'ignore_sticky_posts' => true,
|
|
|
|
'no_found_rows' => true,
|
|
|
|
'orderby' => 'title',
|
|
|
|
'order' => 'ASC',
|
|
|
|
'posts_per_page' => -1,
|
|
|
|
'meta_query' => $meta_query,
|
|
|
|
'tax_query' => array_merge( $tax_query, array(
|
|
|
|
array(
|
|
|
|
'taxonomy' => 'product_cat',
|
|
|
|
'terms' => array( 'cat1', 'cat2' ),
|
|
|
|
'field' => 'slug',
|
|
|
|
'operator' => 'AND',
|
|
|
|
'include_children' => false,
|
|
|
|
),
|
|
|
|
) ),
|
|
|
|
'fields' => 'ids',
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals( $expected15, $shortcode15->get_query_args() );
|
|
|
|
|
|
|
|
// products shortcode -- exclude multiple categories using NOT IN operator.
|
|
|
|
$shortcode16 = new WC_Shortcode_Products( array(
|
|
|
|
'category' => 'cat1,cat2',
|
|
|
|
'cat_operator' => 'NOT IN',
|
|
|
|
) );
|
|
|
|
$expected16 = array(
|
|
|
|
'post_type' => 'product',
|
|
|
|
'post_status' => 'publish',
|
|
|
|
'ignore_sticky_posts' => true,
|
|
|
|
'no_found_rows' => true,
|
|
|
|
'orderby' => 'title',
|
|
|
|
'order' => 'ASC',
|
|
|
|
'posts_per_page' => -1,
|
|
|
|
'meta_query' => $meta_query,
|
|
|
|
'tax_query' => array_merge( $tax_query, array(
|
|
|
|
array(
|
|
|
|
'taxonomy' => 'product_cat',
|
|
|
|
'terms' => array( 'cat1', 'cat2' ),
|
|
|
|
'field' => 'slug',
|
|
|
|
'operator' => 'NOT IN',
|
|
|
|
'include_children' => true,
|
|
|
|
),
|
|
|
|
) ),
|
|
|
|
'fields' => 'ids',
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals( $expected16, $shortcode16->get_query_args() );
|
|
|
|
|
2017-08-24 23:12:12 +00:00
|
|
|
}
|
|
|
|
|
2017-08-24 23:20:14 +00:00
|
|
|
/**
|
2017-08-25 01:22:42 +00:00
|
|
|
* Test: WC_Shortcode_Products::get_type.
|
2017-08-24 23:20:14 +00:00
|
|
|
*/
|
2017-08-25 21:42:02 +00:00
|
|
|
public function test_get_type() {
|
2017-08-24 23:20:14 +00:00
|
|
|
$shortcode = new WC_Shortcode_Products();
|
|
|
|
|
2017-08-25 01:22:42 +00:00
|
|
|
$this->assertEquals( 'products', $shortcode->get_type() );
|
2017-08-24 23:20:14 +00:00
|
|
|
}
|
|
|
|
|
2017-08-24 23:12:12 +00:00
|
|
|
/**
|
|
|
|
* Test: WC_Shortcode_Products::get_content.
|
|
|
|
*/
|
|
|
|
public function test_get_content() {
|
|
|
|
$shortcode = new WC_Shortcode_Products();
|
2017-08-25 18:55:34 +00:00
|
|
|
$result = $shortcode->get_content();
|
|
|
|
|
|
|
|
$this->assertTrue( ! empty( $result ) );
|
|
|
|
}
|
|
|
|
|
2017-08-29 21:29:29 +00:00
|
|
|
/**
|
|
|
|
* Test: WC_Shortcode_Products::set_product_as_visible.
|
|
|
|
*/
|
|
|
|
public function test_set_product_as_visible() {
|
|
|
|
$shortcode = new WC_Shortcode_Products();
|
|
|
|
$this->assertFalse( $shortcode->set_product_as_visible( false ) );
|
|
|
|
|
|
|
|
$shortcode2 = new WC_Shortcode_Products( array(
|
|
|
|
'visibility' => 'hidden',
|
|
|
|
) );
|
|
|
|
$this->assertTrue( $shortcode2->set_product_as_visible( false ) );
|
|
|
|
}
|
|
|
|
|
2017-08-25 18:55:34 +00:00
|
|
|
/**
|
|
|
|
* Test: WC_Shortcode_Products::order_by_rating_post_clauses.
|
|
|
|
*/
|
|
|
|
public function test_order_by_rating_post_clauses() {
|
|
|
|
global $wpdb;
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
'where' => " AND $wpdb->commentmeta.meta_key = 'rating' ",
|
|
|
|
'join' => "LEFT JOIN $wpdb->comments ON($wpdb->posts.ID = $wpdb->comments.comment_post_ID) LEFT JOIN $wpdb->commentmeta ON($wpdb->comments.comment_ID = $wpdb->commentmeta.comment_id)",
|
|
|
|
'orderby' => "$wpdb->commentmeta.meta_value DESC",
|
|
|
|
'groupby' => "$wpdb->posts.ID",
|
|
|
|
);
|
2017-08-24 23:12:12 +00:00
|
|
|
|
2018-03-01 18:05:22 +00:00
|
|
|
$this->assertEquals( $expected, WC_Shortcode_Products::order_by_rating_post_clauses( array(
|
|
|
|
'where' => '',
|
|
|
|
'join' => '',
|
|
|
|
) ) );
|
2017-08-24 23:12:12 +00:00
|
|
|
}
|
|
|
|
}
|