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
Show file tree
Hide file tree
Changes from 13 commits
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
29 changes: 15 additions & 14 deletions includes/classes/Feature/WooCommerce/WooCommerce.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -284,7 +284,6 @@ 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',
Expand All@@ -300,6 +299,10 @@ public function translate_args( $query ) {
*/
$supported_post_types = apply_filters( 'ep_woocommerce_default_supported_post_types', $post_types );

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

$supported_post_types = array_intersect(
$supported_post_types,
Indexables::factory()->get( 'post' )->get_indexable_post_types()
Expand DownExpand Up@@ -1168,6 +1171,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@@ -1176,29 +1187,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@@ -1210,13 +1218,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 numberDiff line numberDiff 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