Product Collection: Added `timeFrame` PHPUnit Tests (#45365)
This commit is contained in:
parent
7ded649fa7
commit
f5f2bb035a
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: dev
|
||||
Comment: This just adds PHPUnit tests.
|
||||
|
|
@ -90,6 +90,7 @@ class ProductCollection extends \WP_UnitTestCase {
|
|||
'woocommerceOnSale' => false,
|
||||
'woocommerceAttributes' => array(),
|
||||
'woocommerceStockStatus' => array(),
|
||||
'timeFrame' => array(),
|
||||
'priceRange' => array(),
|
||||
)
|
||||
);
|
||||
|
@ -431,6 +432,54 @@ class ProductCollection extends \WP_UnitTestCase {
|
|||
set_query_var( 'filter_stock_status', '' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test merging time range queries.
|
||||
*/
|
||||
public function test_merging_time_frame_before_queries() {
|
||||
$time_frame_date = gmdate( 'Y-m-d H:i:s' );
|
||||
|
||||
$parsed_block = $this->get_base_parsed_block();
|
||||
$parsed_block['attrs']['query']['timeFrame'] = array(
|
||||
'operator' => 'not-in',
|
||||
'value' => $time_frame_date,
|
||||
);
|
||||
|
||||
$merged_query = $this->initialize_merged_query( $parsed_block );
|
||||
|
||||
$this->assertContainsEquals(
|
||||
array(
|
||||
'column' => 'post_date_gmt',
|
||||
'before' => $time_frame_date,
|
||||
'inclusive' => true,
|
||||
),
|
||||
$merged_query['date_query'],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test merging time range queries.
|
||||
*/
|
||||
public function test_merging_time_frame_after_queries() {
|
||||
$time_frame_date = gmdate( 'Y-m-d H:i:s' );
|
||||
|
||||
$parsed_block = $this->get_base_parsed_block();
|
||||
$parsed_block['attrs']['query']['timeFrame'] = array(
|
||||
'operator' => 'in',
|
||||
'value' => $time_frame_date,
|
||||
);
|
||||
|
||||
$merged_query = $this->initialize_merged_query( $parsed_block );
|
||||
|
||||
$this->assertContainsEquals(
|
||||
array(
|
||||
'column' => 'post_date_gmt',
|
||||
'after' => $time_frame_date,
|
||||
'inclusive' => true,
|
||||
),
|
||||
$merged_query['date_query'],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test merging filter by stock status queries.
|
||||
*/
|
||||
|
@ -617,8 +666,9 @@ class ProductCollection extends \WP_UnitTestCase {
|
|||
$product_visibility_terms = wc_get_product_visibility_term_ids();
|
||||
$product_visibility_not_in = array( is_search() ? $product_visibility_terms['exclude-from-search'] : $product_visibility_terms['exclude-from-catalog'] );
|
||||
|
||||
$args = array();
|
||||
$params = array(
|
||||
$args = array();
|
||||
$time_frame_date = gmdate( 'Y-m-d H:i:s' );
|
||||
$params = array(
|
||||
'featured' => 'true',
|
||||
'woocommerceOnSale' => 'true',
|
||||
'woocommerceAttributes' => array(
|
||||
|
@ -628,11 +678,16 @@ class ProductCollection extends \WP_UnitTestCase {
|
|||
),
|
||||
),
|
||||
'woocommerceStockStatus' => array( 'instock', 'outofstock' ),
|
||||
'timeFrame' => array(
|
||||
'operator' => 'in',
|
||||
'value' => $time_frame_date,
|
||||
),
|
||||
'priceRange' => array(
|
||||
'min' => 1,
|
||||
'max' => 100,
|
||||
),
|
||||
);
|
||||
|
||||
$request = $this->build_request( $params );
|
||||
|
||||
$updated_query = $this->block_instance->update_rest_query_in_editor( $args, $request );
|
||||
|
@ -665,6 +720,15 @@ class ProductCollection extends \WP_UnitTestCase {
|
|||
$updated_query['tax_query'],
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
array(
|
||||
'column' => 'post_date_gmt',
|
||||
'after' => $time_frame_date,
|
||||
'inclusive' => true,
|
||||
),
|
||||
$updated_query['date_query'],
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
array(
|
||||
'field' => 'term_id',
|
||||
|
|
Loading…
Reference in New Issue