From 6306ea0b977a6b217b4d8a57f44710a63e8c0ab4 Mon Sep 17 00:00:00 2001 From: Burhan Nasir Date: Fri, 7 Oct 2022 16:17:06 +0500 Subject: [PATCH 1/2] Remove legacy filter from unit tests --- tests/php/features/TestProtectedContent.php | 20 +++++--------------- tests/php/features/TestSearch.php | 5 +---- tests/php/features/TestWooCommerce.php | 16 ++++------------ tests/php/indexables/TestPost.php | 9 --------- tests/php/indexables/TestPostMultisite.php | 6 ------ 5 files changed, 10 insertions(+), 46 deletions(-) diff --git a/tests/php/features/TestProtectedContent.php b/tests/php/features/TestProtectedContent.php index de390aa103..99b9e9b7a2 100644 --- a/tests/php/features/TestProtectedContent.php +++ b/tests/php/features/TestProtectedContent.php @@ -70,8 +70,6 @@ public function testAdminNotOn() { ElasticPress\Elasticsearch::factory()->refresh_indices(); - add_action( 'ep_wp_query_search', array( $this, 'action_wp_query_search' ), 10, 0 ); - $query = new \WP_Query(); global $wp_the_query; @@ -80,7 +78,7 @@ public function testAdminNotOn() { $query->query( array() ); - $this->assertTrue( empty( $this->fired_actions['ep_wp_query_search'] ) ); + $this->assertNull( $query->elasticsearch_success ); } /** @@ -99,8 +97,6 @@ public function testAdminOn() { ElasticPress\Elasticsearch::factory()->refresh_indices(); - add_action( 'ep_wp_query_search', array( $this, 'action_wp_query_search' ), 10, 0 ); - $query = new \WP_Query(); global $wp_the_query; @@ -109,7 +105,7 @@ public function testAdminOn() { $wp_the_query->query( array() ); - $this->assertTrue( ! empty( $this->fired_actions['ep_wp_query_search'] ) ); + $this->assertTrue( $query->elasticsearch_success ); } /** @@ -129,8 +125,6 @@ public function testAdminOnDraft() { ElasticPress\Elasticsearch::factory()->refresh_indices(); - add_action( 'ep_wp_query_search', array( $this, 'action_wp_query_search' ), 10, 0 ); - $query = new \WP_Query(); global $wp_the_query; @@ -143,7 +137,7 @@ public function testAdminOnDraft() { $query->query( $args ); - $this->assertTrue( ! empty( $this->fired_actions['ep_wp_query_search'] ) ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, $query->found_posts ); } @@ -174,8 +168,6 @@ public function testAdminOnDraftUpdated() { ElasticPress\Elasticsearch::factory()->refresh_indices(); - add_action( 'ep_wp_query_search', array( $this, 'action_wp_query_search' ), 10, 0 ); - $query = new \WP_Query(); global $wp_the_query; @@ -188,7 +180,7 @@ public function testAdminOnDraftUpdated() { $query->query( $args ); - $this->assertTrue( ! empty( $this->fired_actions['ep_wp_query_search'] ) ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, $query->found_posts ); } @@ -211,8 +203,6 @@ public function testAdminCategories() { ElasticPress\Elasticsearch::factory()->refresh_indices(); - add_action( 'ep_wp_query_search', array( $this, 'action_wp_query_search' ), 10, 0 ); - $query = new \WP_Query(); global $wp_the_query; @@ -230,7 +220,7 @@ public function testAdminCategories() { $query->query( $args ); - $this->assertTrue( ! empty( $this->fired_actions['ep_wp_query_search'] ) ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); } diff --git a/tests/php/features/TestSearch.php b/tests/php/features/TestSearch.php index 5ff4503be4..c0e756c287 100644 --- a/tests/php/features/TestSearch.php +++ b/tests/php/features/TestSearch.php @@ -70,15 +70,13 @@ public function testSearchOn() { ElasticPress\Elasticsearch::factory()->refresh_indices(); - add_action( 'ep_wp_query_search', array( $this, 'action_wp_query_search' ), 10, 0 ); - $args = array( 's' => 'findme', ); $query = new \WP_Query( $args ); - $this->assertTrue( ! empty( $this->fired_actions['ep_wp_query_search'] ) ); + $this->assertTrue( $query->elasticsearch_success ); } /** @@ -367,4 +365,3 @@ public function testExcerptSetting() { $this->assertTrue( $settings['highlight_excerpt'] ); } } - diff --git a/tests/php/features/TestWooCommerce.php b/tests/php/features/TestWooCommerce.php index 692e26662b..9030667487 100644 --- a/tests/php/features/TestWooCommerce.php +++ b/tests/php/features/TestWooCommerce.php @@ -54,7 +54,7 @@ public function tearDown() { } /** - * Test products post type query does get integrated when the feature is not active + * Test products post type query does get integrated when the feature is active * * @since 2.1 * @group woocommerce @@ -73,8 +73,6 @@ public function testProductsPostTypeQueryOn() { ElasticPress\Elasticsearch::factory()->refresh_indices(); - add_action( 'ep_wp_query_search', array( $this, 'action_wp_query_search' ), 10, 0 ); - $args = array( 'post_type' => 'product', ); @@ -84,8 +82,6 @@ public function testProductsPostTypeQueryOn() { $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, $query->found_posts ); - - $this->assertTrue( ! empty( $this->fired_actions['ep_wp_query_search'] ) ); } /** @@ -103,8 +99,6 @@ public function testProductsPostTypeQueryProductCatTax() { ElasticPress\Elasticsearch::factory()->refresh_indices(); - add_action( 'ep_wp_query_search', array( $this, 'action_wp_query_search' ), 10, 0 ); - $args = array( 'tax_query' => array( array( @@ -236,8 +230,6 @@ public function testSearchOnAllFrontEnd() { ElasticPress\Elasticsearch::factory()->refresh_indices(); - add_action( 'ep_wp_query_search', array( $this, 'action_wp_query_search' ), 10, 0 ); - $args = array( 's' => 'findme', 'post_type' => 'product', @@ -250,7 +242,7 @@ public function testSearchOnAllFrontEnd() { /** * Test the addition of variations skus to product meta - * + * * @since 4.2.0 * @group woocommerce */ @@ -287,7 +279,7 @@ public function testAddVariationsSkusMeta() { /** * Test the translate_args_admin_products_list method - * + * * @since 4.2.0 * @group woocommerce */ @@ -329,7 +321,7 @@ public function testTranslateArgsAdminProductsList() { /** * Test the ep_woocommerce_admin_products_list_search_fields filter - * + * * @since 4.2.0 * @group woocommerce */ diff --git a/tests/php/indexables/TestPost.php b/tests/php/indexables/TestPost.php index 827b0ba679..04ccc58fb3 100644 --- a/tests/php/indexables/TestPost.php +++ b/tests/php/indexables/TestPost.php @@ -199,8 +199,6 @@ public function testWPQuerySearchContent() { 's' => 'findme', ); - add_action( 'ep_wp_query_search', array( $this, 'action_wp_query_search' ), 10, 0 ); - $query = new \WP_Query( $args ); $this->assertTrue( $query->elasticsearch_success ); @@ -251,8 +249,6 @@ public function testWPQuerySearchTitle() { 's' => 'findme', ); - add_action( 'ep_wp_query_search', array( $this, 'action_wp_query_search' ), 10, 0 ); - $query = new \WP_Query( $args ); $this->assertTrue( $query->elasticsearch_success ); @@ -412,7 +408,6 @@ public function testPostTermSyncHierarchyMultipleLevelQuery() { ElasticPress\Indexables::factory()->get( 'post' )->index( $post_id, true ); ElasticPress\Elasticsearch::factory()->refresh_indices(); - add_action( 'ep_wp_query_search', array( $this, 'action_wp_query_search' ), 10, 0 ); $query = new \WP_Query( array( 's' => '#findme' ) ); $this->assertTrue( $query->elasticsearch_success ); @@ -550,8 +545,6 @@ public function testWPQuerySearchExcerpt() { 's' => 'findme', ); - add_action( 'ep_wp_query_search', array( $this, 'action_wp_query_search' ), 10, 0 ); - $query = new \WP_Query( $args ); $this->assertTrue( $query->elasticsearch_success ); @@ -3108,8 +3101,6 @@ public function testExcludeFromSearch() { 's' => 'findme', ); - add_action( 'ep_wp_query_search', array( $this, 'action_wp_query_search' ), 10, 0 ); - $query = new \WP_Query( $args ); $this->assertTrue( $query->elasticsearch_success ); diff --git a/tests/php/indexables/TestPostMultisite.php b/tests/php/indexables/TestPostMultisite.php index 61d32101f1..2be9a6e0d6 100644 --- a/tests/php/indexables/TestPostMultisite.php +++ b/tests/php/indexables/TestPostMultisite.php @@ -198,8 +198,6 @@ public function testWPQuerySearchContent() { 'sites' => 'all', ); - add_action( 'ep_wp_query_search', array( $this, 'action_wp_query_search' ), 10, 0 ); - $query = new \WP_Query( $args ); $this->assertTrue( $query->elasticsearch_success ); @@ -450,8 +448,6 @@ public function testWPQuerySearchTitle() { 'sites' => 'all', ); - add_action( 'ep_wp_query_search', array( $this, 'action_wp_query_search' ), 10, 0 ); - $query = new \WP_Query( $args ); $this->assertTrue( $query->elasticsearch_success ); @@ -499,8 +495,6 @@ public function testWPQuerySearchExcerpt() { 'sites' => 'all', ); - add_action( 'ep_wp_query_search', array( $this, 'action_wp_query_search' ), 10, 0 ); - $query = new \WP_Query( $args ); $this->assertTrue( $query->elasticsearch_success ); From de91f7905f0dae5f3d9f36739f675bfad4929f1b Mon Sep 17 00:00:00 2001 From: Burhan Nasir Date: Fri, 7 Oct 2022 16:21:58 +0500 Subject: [PATCH 2/2] Minor change --- tests/php/includes/classes/BaseTestCase.php | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tests/php/includes/classes/BaseTestCase.php b/tests/php/includes/classes/BaseTestCase.php index 3cf1d38258..c2789d41dd 100644 --- a/tests/php/includes/classes/BaseTestCase.php +++ b/tests/php/includes/classes/BaseTestCase.php @@ -48,15 +48,6 @@ public function action_delete_post() { $this->fired_actions['ep_delete_post'] = true; } - /** - * Helper function to test whether a EP search has happened - * - * @since 1.0 - */ - public function action_wp_query_search() { - $this->fired_actions['ep_wp_query_search'] = true; - } - /** * Helper function to check post sync args *