Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add tests for WooCommerce #3259

Merged
merged 21 commits into from
Feb 24, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add new tests
  • Loading branch information
burhandodhy committed Jan 26, 2023
commit 856bb7e9f63e739cfbae8225665567c13645afcf
37 changes: 14 additions & 23 deletions tests/php/features/TestWooCommerce.php
Original file line number Diff line number Diff 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 );
}
}