Skip to content

Commit

Permalink
Merge pull request #3259 from 10up/chore/3219
Browse files Browse the repository at this point in the history
Add tests for WooCommerce
  • Loading branch information
felipeelia authored Feb 24, 2023
2 parents bba5b97 + 8d654ca commit 81dcffa
Show file tree
Hide file tree
Showing 5 changed files with 889 additions and 21 deletions.
29 changes: 15 additions & 14 deletions includes/classes/Feature/WooCommerce/WooCommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,15 @@ public function translate_args( $query ) {

// Act only on a defined subset of all indexable post types here
$post_types = array(
'product',
'shop_order',
'shop_order_refund',
'product_variation',
);

if ( $query->is_post_type_archive( 'product' ) || isset( $query->query_vars['ep_integrate'] ) && filter_var( $query->query_vars['ep_integrate'], FILTER_VALIDATE_BOOLEAN ) ) {
$post_types[] = 'product';
}

/**
* Expands or contracts the post_types eligible for indexing.
*
Expand Down Expand Up @@ -1221,6 +1224,14 @@ protected function should_integrate_with_query( $query ) {
return false;
}

if ( defined( 'WC_API_REQUEST' ) && WC_API_REQUEST ) {
return false;
}

if ( isset( $query->query_vars['ep_integrate'] ) && ! filter_var( $query->query_vars['ep_integrate'], FILTER_VALIDATE_BOOLEAN ) ) {
return false;
}

/**
* Filter to skip WP Query integration
*
Expand All @@ -1229,29 +1240,26 @@ protected function should_integrate_with_query( $query ) {
* @param {WP_Query} $query WP Query to evaluate
* @return {bool} New skip value
*/
if ( apply_filters( 'ep_skip_query_integration', false, $query ) ||
( isset( $query->query_vars['ep_integrate'] ) && ! filter_var( $query->query_vars['ep_integrate'], FILTER_VALIDATE_BOOLEAN ) ) ) {
if ( apply_filters( 'ep_skip_query_integration', false, $query ) ) {
return false;
}

if ( ! Utils\is_integrated_request( $this->slug ) ) {
return false;
}

$product_name = $query->get( 'product', false );

$post_parent = $query->get( 'post_parent', false );

/**
* Do nothing for single product queries
*/
$product_name = $query->get( 'product', false );
if ( ! empty( $product_name ) || $query->is_single() ) {
return false;
}

/**
* ElasticPress does not yet support post_parent queries
*/
$post_parent = $query->get( 'post_parent', false );
if ( ! empty( $post_parent ) ) {
return false;
}
Expand All @@ -1263,13 +1271,6 @@ protected function should_integrate_with_query( $query ) {
return false;
}

/**
* Cant hook into WC API yet
*/
if ( defined( 'WC_API_REQUEST' ) && WC_API_REQUEST ) {
return false;
}

return true;
}

Expand Down
1 change: 1 addition & 0 deletions tests/php/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ function skip_translations_api() {
require_once __DIR__ . '/includes/classes/factory/UserFactory.php';
require_once __DIR__ . '/includes/classes/factory/TermFactory.php';
require_once __DIR__ . '/includes/classes/factory/CommentFactory.php';
require_once __DIR__ . '/includes/classes/factory/ProductFactory.php';
require_once __DIR__ . '/includes/classes/BaseTestCase.php';
require_once __DIR__ . '/includes/classes/FeatureTest.php';
require_once __DIR__ . '/includes/classes/mock/class-wp-cli-command.php';
Expand Down
Loading

0 comments on commit 81dcffa

Please sign in to comment.