Skip to content

Commit 2afc8b4

Browse files
committed
Fix tests
1 parent e0d7dde commit 2afc8b4

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

includes/classes/Indexable.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,19 @@ public function index( $object_id, $blocking = false ) {
290290
return false;
291291
}
292292

293+
/**
294+
* Conditionally kill indexing for an object.
295+
*
296+
* @hook ep_{$this->slug}_sync_kill
297+
* @param {bool} $kill True means dont sync
298+
* @param {int} $object_id Object ID
299+
* @return {bool} New value
300+
*/
301+
$ep_indexable_sync_kill = apply_filters( 'ep_' . $this->slug . '_sync_kill', false, $object_id );
302+
if ( $ep_indexable_sync_kill ) {
303+
return false;
304+
}
305+
293306
/**
294307
* Filter document before index
295308
*

tests/php/features/WooCommerce/TestWooCommerceOrdersAutosuggest.php

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ class TestWooCommerceOrdersAutosuggest extends BaseTestCase {
3636
*/
3737
public function set_up() {
3838
parent::set_up();
39-
ElasticPress\Features::factory()->activate_feature( 'protected_content' );
4039
ElasticPress\Features::factory()->activate_feature( 'woocommerce' );
4140

4241
$this->woocommerce_feature = ElasticPress\Features::factory()->get_registered_feature( 'woocommerce' );
@@ -46,6 +45,11 @@ public function set_up() {
4645

4746
ElasticPress\Features::factory()->setup_features();
4847

48+
ElasticPress\Elasticsearch::factory()->delete_all_indices();
49+
ElasticPress\Indexables::factory()->get( 'post' )->put_mapping();
50+
51+
ElasticPress\Indexables::factory()->get( 'post' )->sync_manager->reset_sync_queue();
52+
4953
$this->orders_autosuggest = $this->woocommerce_feature->orders_autosuggest;
5054
}
5155

@@ -438,4 +442,41 @@ public function test_get_setting_help_message_feature_not_available() {
438442
$new_settings_schema = $this->orders_autosuggest->add_settings_schema( [] );
439443
$this->assertStringContainsString( 'Due to the sensitive nature of orders', $new_settings_schema[0]['help'] );
440444
}
445+
446+
/**
447+
* Test shop_order with password is synced without Protected Content feature enabled.
448+
*
449+
* @since 5.3.3
450+
* @group woocommerce
451+
* @group woocommerce-orders-autosuggest
452+
*/
453+
public function test_order_with_password_is_synced() {
454+
add_filter( 'ep_woocommerce_orders_autosuggest_available', '__return_true' );
455+
456+
/**
457+
* Enable the orders autosuggest feature
458+
*/
459+
$filter = function () {
460+
return [
461+
'woocommerce' => [
462+
'orders' => '1',
463+
],
464+
];
465+
};
466+
add_filter( 'pre_site_option_ep_feature_settings', $filter );
467+
468+
$this->orders_autosuggest->setup();
469+
470+
$order = new \WC_Order();
471+
$order->set_order_key( '1234567890' ); // save in the post_password field
472+
$order->save();
473+
474+
$order_id = $order->get_id();
475+
476+
ElasticPress\Indexables::factory()->get( 'post' )->index( $order_id );
477+
ElasticPress\Elasticsearch::factory()->refresh_indices();
478+
479+
$order = ElasticPress\Indexables::factory()->get( 'post' )->get( $order_id );
480+
$this->assertNotEmpty( $order );
481+
}
441482
}

0 commit comments

Comments
 (0)