Included unit test for recent_products shortcode
This commit is contained in:
parent
9b1a047c6f
commit
013da90f51
|
@ -45,6 +45,10 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
|||
* Test: WC_Shortcode_Products::get_query_args.
|
||||
*/
|
||||
public function test_get_query_args() {
|
||||
$meta_query = WC()->query->get_meta_query();
|
||||
$tax_query = WC()->query->get_tax_query();
|
||||
|
||||
// Emtpy products shortcode.
|
||||
$shortcode = new WC_Shortcode_Products();
|
||||
$expected = array(
|
||||
'post_type' => 'product',
|
||||
|
@ -53,11 +57,12 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
|||
'orderby' => 'title',
|
||||
'order' => 'ASC',
|
||||
'posts_per_page' => -1,
|
||||
'meta_query' => WC()->query->get_meta_query(),
|
||||
'tax_query' => WC()->query->get_tax_query(),
|
||||
'meta_query' => $meta_query,
|
||||
'tax_query' => $tax_query,
|
||||
);
|
||||
$this->assertEquals( $expected, $shortcode->get_query_args() );
|
||||
|
||||
// products shortcode with attributes.
|
||||
$shortcode2 = new WC_Shortcode_Products( array(
|
||||
'orderby' => 'id',
|
||||
'order' => 'DESC',
|
||||
|
@ -69,8 +74,8 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
|||
'orderby' => 'id',
|
||||
'order' => 'DESC',
|
||||
'posts_per_page' => -1,
|
||||
'meta_query' => WC()->query->get_meta_query(),
|
||||
'tax_query' => WC()->query->get_tax_query(),
|
||||
'meta_query' => $meta_query,
|
||||
'tax_query' => $tax_query,
|
||||
);
|
||||
$this->assertEquals( $expected2, $shortcode2->get_query_args() );
|
||||
|
||||
|
@ -85,8 +90,8 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
|||
'orderby' => 'title',
|
||||
'order' => 'ASC',
|
||||
'posts_per_page' => -1,
|
||||
'meta_query' => WC()->query->get_meta_query(),
|
||||
'tax_query' => WC()->query->get_tax_query(),
|
||||
'meta_query' => $meta_query,
|
||||
'tax_query' => $tax_query,
|
||||
'post__in' => array( '1', '2', '3' ),
|
||||
);
|
||||
$expected2['meta_query'][] = array(
|
||||
|
@ -97,11 +102,14 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
|||
|
||||
$this->assertEquals( $expected2, $shortcode2->get_query_args() );
|
||||
|
||||
// With categories.
|
||||
// product_category shortcode.
|
||||
$shortcode3 = new WC_Shortcode_Products( array(
|
||||
'category' => 'clothing',
|
||||
'orderby' => 'menu_order title',
|
||||
'per_page' => '12',
|
||||
'columns' => '4',
|
||||
'orderby' => 'menu_order title',
|
||||
'order' => 'ASC',
|
||||
'category' => 'clothing',
|
||||
'operator' => 'IN',
|
||||
) );
|
||||
$expected3 = array(
|
||||
'post_type' => 'product',
|
||||
|
@ -110,8 +118,8 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
|||
'orderby' => 'menu_order title',
|
||||
'order' => 'ASC',
|
||||
'posts_per_page' => 12,
|
||||
'meta_query' => WC()->query->get_meta_query(),
|
||||
'tax_query' => WC()->query->get_tax_query(),
|
||||
'meta_query' => $meta_query,
|
||||
'tax_query' => $tax_query,
|
||||
'meta_key' => '',
|
||||
);
|
||||
$expected3['tax_query'][] = array(
|
||||
|
@ -120,8 +128,29 @@ class WC_Test_Shortcode_Products extends WC_Unit_Test_Case {
|
|||
'field' => 'slug',
|
||||
'operator' => 'IN',
|
||||
);
|
||||
|
||||
$this->assertEquals( $expected3, $shortcode3->get_query_args() );
|
||||
|
||||
// recent_products shortcode.
|
||||
$shortcode4 = new WC_Shortcode_Products( array(
|
||||
'per_page' => '12',
|
||||
'columns' => '4',
|
||||
'orderby' => 'date',
|
||||
'order' => 'DESC',
|
||||
'category' => '',
|
||||
'operator' => 'IN',
|
||||
) );
|
||||
$expected4 = array(
|
||||
'post_type' => 'product',
|
||||
'post_status' => 'publish',
|
||||
'ignore_sticky_posts' => 1,
|
||||
'orderby' => 'date',
|
||||
'order' => 'DESC',
|
||||
'posts_per_page' => 12,
|
||||
'meta_query' => $meta_query,
|
||||
'tax_query' => $tax_query,
|
||||
);
|
||||
|
||||
$this->assertEquals( $expected4, $shortcode4->get_query_args() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue