Skip to content

Add tests for WooCommerce #3259

New issue

Have a question about this project? Sign up for a free account to open an issue and contact its maintainers and the community.

By clicking “Sign up for ”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on ? Sign in to your account

Merged
merged 21 commits into from
Feb 24, 2023
Merged
PrevPrevious commit
Next Next commit
Add new tests
  • Loading branch information
@burhandodhy
burhandodhy committedJan 26, 2023
commit 856bb7e9f63e739cfbae8225665567c13645afcf
37 changes: 14 additions & 23 deletions tests/php/features/TestWooCommerce.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -1455,7 +1455,11 @@ public function testPriceFilterWithSearchQuery() {
$this->assertEquals( 2, count( $query ) );
}


/**
* Tests that attributes filter uses Elasticsearch.
*
* @since 4.5.0
*/
public function testAttributesFilterUseES() {
ElasticPress\Features::factory()->activate_feature( 'woocommerce' );
ElasticPress\Features::factory()->setup_features();
Expand All@@ -1480,34 +1484,21 @@ public function testAttributesFilterUseES() {

ElasticPress\Elasticsearch::factory()->refresh_indices();

parse_str( 'filter_color=blue', $_GET );

update_option( 'show_on_front', 'page' );
// call the product query directly to bypass the additional checks by WooCommerce
add_action( 'pre_get_posts', function( $query ) {
$wc_query = WC()->query;
$wc_query->product_query( $query );
} );

parse_str( 'filter_colour=blue', $_GET );
$args = array(
'post_type' => 'product',

);
$query = new \WP_Query( $args );

// mock the query as main query and is_search
global $wp_the_query, $wp_query;
$wp_the_query = $query;
$wp_query->is_posts_page = false;
$wp_query->is_home = true;
$wp_query->is_post_type_archive = 'product';

$query = $query->query( $args );



$this->assertTrue( $wp_the_query->elasticsearch_success, 'Elasticsearch query failed' );







$this->assertTrue( $query->elasticsearch_success );
$this->assertEquals( 1, $query->post_count );
$this->assertEquals( 'Cap', $query->posts[0]->post_title );
}
}