diff --git a/tests/php/indexables/TestPost.php b/tests/php/indexables/TestPost.php index 9000001d48..b4e8c462c5 100644 --- a/tests/php/indexables/TestPost.php +++ b/tests/php/indexables/TestPost.php @@ -164,6 +164,7 @@ public function testPaginationWithOffset() { ) ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, count( $query->posts ) ); $this->assertEquals( 'two', $query->posts[0]->post_title ); } @@ -193,7 +194,7 @@ public function testWPQuerySearchContent() { $query = new \WP_Query( $args ); - $this->assertTrue( ! empty( $this->fired_actions['ep_wp_query_search'] ) ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( $query->post_count, 2 ); $this->assertEquals( $query->found_posts, 2 ); @@ -245,7 +246,7 @@ public function testWPQuerySearchTitle() { $query = new \WP_Query( $args ); - $this->assertTrue( ! empty( $this->fired_actions['ep_wp_query_search'] ) ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( $query->post_count, 3 ); $this->assertEquals( $query->found_posts, 3 ); @@ -405,6 +406,8 @@ public function testPostTermSyncHierarchyMultipleLevelQuery() { 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 ); + $this->assertNotNull( $query->posts[0] ); $this->assertNotNull( $query->posts[0]->terms ); $post = $query->posts[0]; @@ -446,11 +449,12 @@ public function testPostImplicitTaxonomyQueryCustomTax() { $args = array( $tax_name => $term_1_name, - 's' => '', + 'ep_integrate' => true ); $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( $query->post_count, 1 ); $this->assertEquals( $query->found_posts, 1 ); } @@ -476,11 +480,12 @@ public function testPostImplicitTaxonomyQueryCategoryName() { $args = array( 'category_name' => $term_1_name, - 's' => '', + 'ep_integrate' => true ); $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( $query->post_count, 1 ); $this->assertEquals( $query->found_posts, 1 ); } @@ -504,12 +509,13 @@ public function testPostImplicitTaxonomyQueryTag() { ElasticPress\Elasticsearch::factory()->refresh_indices(); $args = array( - 'tag' => $term_1_name, - 's' => '', + 'tag' => $term_1_name, + 'ep_integrate' => true, ); $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( $query->post_count, 1 ); $this->assertEquals( $query->found_posts, 1 ); } @@ -539,7 +545,7 @@ public function testWPQuerySearchExcerpt() { $query = new \WP_Query( $args ); - $this->assertTrue( ! empty( $this->fired_actions['ep_wp_query_search'] ) ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( $query->post_count, 1 ); $this->assertEquals( $query->found_posts, 1 ); @@ -571,6 +577,7 @@ public function testPagination() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, count( $query->posts ) ); $this->assertEquals( 3, $query->found_posts ); @@ -585,6 +592,7 @@ public function testPagination() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, count( $query->posts ) ); $this->assertEquals( 3, $query->found_posts ); @@ -599,6 +607,7 @@ public function testPagination() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, count( $query->posts ) ); $this->assertEquals( 3, $query->found_posts ); @@ -613,6 +622,7 @@ public function testPagination() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 0, $query->post_count ); $this->assertEquals( 0, count( $query->posts ) ); $this->assertEquals( 3, $query->found_posts ); @@ -662,6 +672,7 @@ public function testTaxQuerySlug() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); } @@ -713,6 +724,7 @@ public function testTaxQueryOrRelation() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); } @@ -768,6 +780,7 @@ public function testTaxQueryTermId() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); @@ -783,6 +796,7 @@ public function testTaxQueryTermId() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); } @@ -833,6 +847,7 @@ public function testTaxQueryTermName() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); } @@ -876,6 +891,7 @@ public function testCategoryNameQuery() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); } @@ -902,6 +918,7 @@ public function testPostInQuery() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); } @@ -928,6 +945,7 @@ public function testPostNotInQuery() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); } @@ -956,6 +974,7 @@ public function testCategoryNotInQuery() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); } @@ -984,6 +1003,7 @@ public function testTagNotInQuery() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); } @@ -1020,6 +1040,7 @@ public function testAuthorIDQuery() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); } @@ -1063,6 +1084,7 @@ public function testAuthorNameQuery() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 3, $query->post_count ); $this->assertEquals( 3, $query->found_posts ); @@ -1072,6 +1094,7 @@ public function testAuthorNameQuery() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); } @@ -1106,6 +1129,7 @@ public function testPostTypeQueryPage() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); } @@ -1141,6 +1165,7 @@ public function testPostTypeQueryPost() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, $query->found_posts ); } @@ -1170,6 +1195,7 @@ public function testNoPostTypeSearchQuery() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 3, $query->post_count ); $this->assertEquals( 3, $query->found_posts ); } @@ -1204,6 +1230,7 @@ public function testPostStatusQueryPublish() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, $query->found_posts ); } @@ -1240,6 +1267,7 @@ public function testPostStatusQueryDraft() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); @@ -1281,6 +1309,7 @@ public function testPostStatusQueryMulti() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 3, $query->post_count ); $this->assertEquals( 3, $query->found_posts ); @@ -1334,13 +1363,14 @@ public function testAttachmentQuery() { // post_type defaults to "any" $args = array( - 'post_type' => 'attachment', - 'post_status' => 'any', - 'elasticpress_integrate' => true, + 'post_type' => 'attachment', + 'post_status' => 'any', + 'ep_integrate' => true, ); $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, $query->found_posts ); @@ -1373,6 +1403,7 @@ public function testNoPostTypeNonSearchQuery() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); } @@ -1407,6 +1438,7 @@ public function testAnyPostTypeQuery() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 3, $query->post_count ); $this->assertEquals( 3, $query->found_posts ); } @@ -1430,6 +1462,7 @@ public function testSearchMetaInPostObject() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, count( $query->posts[0]->meta['test_key'] ) ); @@ -1459,6 +1492,7 @@ public function testSearchMetaQuery() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); @@ -1473,6 +1507,7 @@ public function testSearchMetaQuery() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, $query->found_posts ); } @@ -1510,6 +1545,7 @@ public function testSearchTaxQuery() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); @@ -1562,6 +1598,7 @@ public function testSearchAuthorQuery() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, $query->found_posts ); @@ -1632,6 +1669,7 @@ public function testAdvancedQuery() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, $query->found_posts ); } @@ -1657,6 +1695,7 @@ public function testSearchPostTitleOrderbyQuery() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 3, $query->post_count ); $this->assertEquals( 3, $query->found_posts ); $this->assertEquals( 'ordertest 333', $query->posts[0]->post_title ); @@ -1685,6 +1724,7 @@ public function testSearchPostMetaStringOrderbyQueryAsc() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 3, $query->post_count ); $this->assertEquals( 3, $query->found_posts ); $this->assertEquals( 'ordertest 111', $query->posts[0]->post_title ); @@ -1713,6 +1753,7 @@ public function testSearchPostMetaStringOrderbyQueryAscArray() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 3, $query->post_count ); $this->assertEquals( 3, $query->found_posts ); $this->assertEquals( 'ordertest 111', $query->posts[0]->post_title ); @@ -1759,6 +1800,7 @@ public function testSearchPostMetaStringOrderbyQueryAdvanced() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 3, $query->post_count ); $this->assertEquals( 3, $query->found_posts ); $this->assertEquals( 'ordertest 333', $query->posts[0]->post_title ); @@ -1821,6 +1863,8 @@ public function testAuthorLoginOrderbyQueryAsc() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); + $this->assertEquals( 3, $query->post_count ); $this->assertEquals( 3, $query->found_posts ); @@ -1884,6 +1928,8 @@ public function testAuthorDisplayNameOrderbyQueryAsc() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); + $this->assertEquals( 3, $query->post_count ); $this->assertEquals( 3, $query->found_posts ); @@ -1914,6 +1960,7 @@ public function testSearchPostMetaNumOrderbyQueryAsc() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 4, $query->post_count ); $this->assertEquals( 4, $query->found_posts ); $this->assertEquals( 'ordertest 111', $query->posts[0]->post_title ); @@ -1969,6 +2016,7 @@ public function testSearchTaxNameOrderbyQueryAsc() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 4, $query->post_count ); $this->assertEquals( 4, $query->found_posts ); $this->assertEquals( 'ordertest 111', $query->posts[0]->post_title ); @@ -1999,6 +2047,7 @@ public function testSearchPostMetaNumOrderbyQueryDesc() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 4, $query->post_count ); $this->assertEquals( 4, $query->found_posts ); $this->assertEquals( 'ordertest 111', $query->posts[3]->post_title ); @@ -2053,6 +2102,7 @@ public function testSearchPostMetaNumMultipleOrderbyQuery() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 4, $query->post_count ); $this->assertEquals( 4, $query->found_posts ); $this->assertEquals( 'ordertest 111', $query->posts[0]->post_title ); @@ -2089,6 +2139,7 @@ public function testSearchPostDateOrderbyQuery() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 3, $query->post_count ); $this->assertEquals( 3, $query->found_posts ); $this->assertEquals( 'Ordertest 222', $query->posts[0]->post_title ); @@ -2122,6 +2173,7 @@ public function testSearchPostDateOrderbyQueryEPIntegrate() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 3, $query->post_count ); $this->assertEquals( 3, $query->found_posts ); $this->assertEquals( 'Ordertest 222', $query->posts[0]->post_title ); @@ -2175,6 +2227,7 @@ public function testSearchRelevanceOrderbyQueryAdvanced() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 6, $query->post_count ); $this->assertEquals( 6, $query->found_posts ); @@ -2211,6 +2264,7 @@ public function testSearchRelevanceOrderbyQuery() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); $this->assertEquals( 'ordertest', $query->posts[0]->post_title ); @@ -2240,6 +2294,7 @@ public function testSearchPostNameOrderbyQuery() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 3, $query->post_count ); $this->assertEquals( 3, $query->found_posts ); $this->assertEquals( 'postname-ordertest-111', $query->posts[0]->post_name ); @@ -2271,6 +2326,7 @@ public function testSearchDefaultOrderbyQuery() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); $this->assertEquals( 'ordertest', $query->posts[0]->post_title ); @@ -2304,6 +2360,7 @@ public function testSearchDefaultOrderbyASCOrderQuery() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); $this->assertEquals( 'ordertestt', $query->posts[0]->post_title ); @@ -2332,6 +2389,8 @@ public function testRandOrderby() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); + /** * Since it's test for random order, can't check against exact post ID or content * but only found posts and post count. @@ -2390,11 +2449,12 @@ public function testEmptySearchString() { ElasticPress\Elasticsearch::factory()->refresh_indices(); $args = array( - 's' => '', + 'ep_integrate' => true ); $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); } @@ -2423,6 +2483,7 @@ public function testMetaQueryEquals() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, $query->found_posts ); } @@ -2452,6 +2513,7 @@ public function testMetaQueryNotEquals() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); } @@ -2480,6 +2542,7 @@ public function testMetaQueryExists() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, $query->found_posts ); } @@ -2508,6 +2571,7 @@ public function testMetaQueryNotExists() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); } @@ -2538,6 +2602,7 @@ public function testMetaQueryGreaterThan() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, $query->found_posts ); } @@ -2569,6 +2634,7 @@ public function testMetaQueryBetween() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, $query->found_posts ); } @@ -2599,6 +2665,7 @@ public function testMetaQueryGreaterThanEqual() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); } @@ -2629,6 +2696,7 @@ public function testMetaQueryLessThan() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, $query->found_posts ); } @@ -2659,6 +2727,7 @@ public function testMetaQueryLessThanEqual() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); } @@ -2706,6 +2775,7 @@ public function testMetaQueryOrRelation() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); } @@ -2757,6 +2827,7 @@ public function testMetaQueryAdvanced() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, $query->found_posts ); } @@ -2788,6 +2859,7 @@ public function testMetaQueryLike() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertTrue( isset( $query->posts[0]->elasticsearch ) ); $this->assertEquals( 3, $query->post_count ); $this->assertEquals( 3, $query->found_posts ); @@ -2818,6 +2890,7 @@ public function testMetaQueryNotLike() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertTrue( isset( $query->posts[0]->elasticsearch ) ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); @@ -2866,6 +2939,7 @@ public function testMetaQueryMultipleArray() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); @@ -2894,6 +2968,7 @@ public function testMetaQueryMultipleArray() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); } @@ -2939,7 +3014,7 @@ public function testExcludeFromSearch() { $query = new \WP_Query( $args ); - $this->assertTrue( ! empty( $this->fired_actions['ep_wp_query_search'] ) ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( $query->post_count, 2 ); $this->assertEquals( $query->found_posts, 2 ); @@ -2979,8 +3054,11 @@ public function testNoAvailablePostTypesToSearch() { 's' => 'findme', ); + $num_queries = $GLOBALS['wpdb']->num_queries; + $query = new \WP_Query( $args ); + $this->assertSame( $num_queries, $GLOBALS['wpdb']->num_queries ); $this->assertEquals( 0, $query->post_count ); $this->assertEquals( 0, $query->found_posts ); @@ -3007,6 +3085,7 @@ public function testCacheResultsDefaultOff() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertFalse( $query->query_vars['cache_results'] ); } @@ -3028,6 +3107,7 @@ public function testCacheResultsOn() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertTrue( $query->query_vars['cache_results'] ); } @@ -3051,6 +3131,8 @@ public function testCachedResultIsInCache() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); + $cache = wp_cache_get( $query->posts[0]->ID, 'posts' ); $this->assertTrue( ! empty( $cache ) ); @@ -3075,6 +3157,8 @@ public function testCachedResultIsNotInCache() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); + $cache = wp_cache_get( $query->posts[0]->ID, 'posts' ); $this->assertTrue( empty( $cache ) ); @@ -3349,6 +3433,7 @@ public function testMetaKeyQuery() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, $query->found_posts ); @@ -3374,6 +3459,7 @@ public function testMetaKeyQueryNum() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, $query->found_posts ); @@ -3411,6 +3497,7 @@ public function testMetaKeyQueryMix() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, $query->found_posts ); @@ -3444,6 +3531,7 @@ public function testMetaValueTypeQueryNumeric() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, $query->found_posts ); @@ -3461,6 +3549,7 @@ public function testMetaValueTypeQueryNumeric() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, $query->found_posts ); @@ -3478,6 +3567,7 @@ public function testMetaValueTypeQueryNumeric() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); @@ -3511,6 +3601,7 @@ public function testMetaValueTypeQueryDecimal() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, $query->found_posts ); @@ -3528,6 +3619,7 @@ public function testMetaValueTypeQueryDecimal() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, $query->found_posts ); } @@ -3560,6 +3652,7 @@ public function testMetaValueTypeQueryChar() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, $query->found_posts ); } @@ -3590,6 +3683,7 @@ public function testMetaValueTypeQueryDate() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $args = array( @@ -3606,6 +3700,7 @@ public function testMetaValueTypeQueryDate() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); } @@ -3635,6 +3730,7 @@ public function testMetaValueTypeQueryTime() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $args = array( @@ -3651,6 +3747,7 @@ public function testMetaValueTypeQueryTime() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); } @@ -3679,6 +3776,7 @@ public function testMetaValueTypeQueryDatetime() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $args = array( @@ -3695,6 +3793,7 @@ public function testMetaValueTypeQueryDatetime() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $args = array( @@ -3711,6 +3810,7 @@ public function testMetaValueTypeQueryDatetime() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); } @@ -3739,6 +3839,7 @@ public function testPostParentQuery() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, $query->found_posts ); } @@ -3769,10 +3870,14 @@ public function testPostNameInQuery() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); + $args['post_name__in'] = array( 'findme-name-in' ); $query2 = new \WP_Query( $args ); + $this->assertTrue( $query2->elasticsearch_success ); + $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, $query->found_posts ); $this->assertEquals( 1, $query2->post_count ); @@ -3817,6 +3922,7 @@ public function testTaxQueryNotIn() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); @@ -3839,6 +3945,7 @@ public function testTaxQueryNotIn() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, $query->found_posts ); } @@ -3881,6 +3988,7 @@ public function testTaxQueryExists() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); @@ -3903,6 +4011,7 @@ public function testTaxQueryExists() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, $query->found_posts ); } @@ -3945,6 +4054,7 @@ public function testTaxQueryNotExists() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, $query->found_posts ); } @@ -3995,6 +4105,8 @@ public function testPostMimeTypeQuery() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); + $attachment_names = wp_list_pluck( $query->posts, 'post_name' ); $this->assertEquals( 3, $query->post_count ); @@ -4012,6 +4124,8 @@ public function testPostMimeTypeQuery() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); + $attachment_names = wp_list_pluck( $query->posts, 'post_name' ); $this->assertEquals( 1, $query->post_count ); @@ -4030,6 +4144,8 @@ public function testPostMimeTypeQuery() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); + $attachment_names = wp_list_pluck( $query->posts, 'post_name' ); $this->assertEquals( 3, $query->found_posts ); @@ -4050,6 +4166,8 @@ public function testPostMimeTypeQuery() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); + $attachment_names = wp_list_pluck( $query->posts, 'post_name' ); $this->assertEquals( 4, $query->found_posts ); @@ -4070,6 +4188,8 @@ public function testPostMimeTypeQuery() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); + $attachment_names = wp_list_pluck( $query->posts, 'post_name' ); $this->assertEquals( 1, $query->found_posts ); @@ -4115,6 +4235,7 @@ public function testTaxQueryOperatorIn() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); @@ -4132,6 +4253,7 @@ public function testTaxQueryOperatorIn() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); } @@ -4176,6 +4298,7 @@ public function testTaxQueryOperatorAnd() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, $query->found_posts ); } @@ -4225,6 +4348,7 @@ public function testCustomTaxonomyPublic() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( $query->post_count, 1 ); $this->assertEquals( $query->found_posts, 1 ); $this->assertTrue( isset( $query->posts[0]->elasticsearch ) ); @@ -4289,6 +4413,8 @@ public function testSimpleDateMonthNum() { ); $query = new \WP_Query( $args ); + + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 5, $query->post_count ); $this->assertEquals( 5, $query->found_posts ); @@ -4299,6 +4425,8 @@ public function testSimpleDateMonthNum() { ); $query = new \WP_Query( $args ); + + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( $query->post_count, 1 ); $this->assertEquals( $query->found_posts, 1 ); } @@ -4318,6 +4446,8 @@ public function testSimpleDateDay() { ); $query = new \WP_Query( $args ); + + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( $query->post_count, 1 ); $this->assertEquals( $query->found_posts, 1 ); } @@ -4350,6 +4480,8 @@ public function testDateQueryBeforeAfter() { ); $query = new \WP_Query( $args ); + + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( $query->post_count, 2 ); $this->assertEquals( $query->found_posts, 2 ); } @@ -4379,6 +4511,7 @@ public function testDateQueryMultiColumn() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( $query->post_count, 4 ); $this->assertEquals( $query->found_posts, 4 ); } @@ -4408,6 +4541,8 @@ public function testDateQueryMultiColumnInclusive() { ); $query = new \WP_Query( $args ); + + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( $query->post_count, 1 ); $this->assertEquals( $query->found_posts, 1 ); } @@ -4442,6 +4577,7 @@ public function testDateQueryWorkingHours() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( $query->post_count, 5 ); $this->assertEquals( $query->found_posts, 5 ); } @@ -4471,6 +4607,8 @@ public function testDateQueryMultiColumnNotInclusive() { ); $query = new \WP_Query( $args ); + + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( $query->post_count, 0 ); $this->assertEquals( $query->found_posts, 0 ); } @@ -4496,6 +4634,8 @@ public function testDateQuerySimple() { ); $query = new \WP_Query( $args ); + + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( $query->post_count, 1 ); $this->assertEquals( $query->found_posts, 1 ); } @@ -4631,6 +4771,8 @@ public function testDateQueryBetween() { ); $query = new \WP_Query( $args ); + + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( $query->post_count, 5 ); $this->assertEquals( $query->found_posts, 5 ); } @@ -4655,6 +4797,8 @@ public function testDateQueryNotBetween() { ); $query = new \WP_Query( $args ); + + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( $query->post_count, 8 ); $this->assertEquals( $query->found_posts, 8 ); } @@ -4680,6 +4824,7 @@ public function testDateQueryShortBetween() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 1, $query->post_count ); $this->assertEquals( 1, $query->found_posts ); } @@ -4726,6 +4871,8 @@ public function testDateQueryCompare() { $this->assertSame( 10, $filter['and']['bool']['must'][0]['term']['date_terms.week'] ); $query = new \WP_Query( $args ); + + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( $query->post_count, 4 ); $this->assertEquals( $query->found_posts, 4 ); @@ -4797,6 +4944,8 @@ public function testDateQueryInclusiveTypeMix() { ); $query = new \WP_Query( $args ); + + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( $query->post_count, 2 ); $this->assertEquals( $query->found_posts, 2 ); } @@ -4827,6 +4976,8 @@ public function testDateQueryExclusiveTypeMix() { ); $query = new \WP_Query( $args ); + + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( $query->post_count, 0 ); $this->assertEquals( $query->found_posts, 0 ); } @@ -4859,6 +5010,8 @@ public function testDateQueryCompare2() { ); $query = new \WP_Query( $args ); + + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); } @@ -4883,6 +5036,8 @@ public function testDateQueryWeekdayRange() { ); $query = new \WP_Query( $args ); + + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 9, $query->post_count ); $this->assertEquals( 9, $query->found_posts ); } @@ -4910,6 +5065,9 @@ public function testQueryWithIsSearch() { 's' => 'findme', ); $query = new \WP_Query( $args ); + + $this->assertTrue( $query->elasticsearch_success ); + $check = ElasticPress\Indexables::factory()->get( 'post' )->elasticpress_enabled( $query ); $this->assertTrue( $check ); } @@ -4972,6 +5130,7 @@ public function testNestedTaxQuery() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, count( $query->posts ) ); } @@ -5009,6 +5168,9 @@ public function testTagSlugQuery() { $query1 = new \WP_Query( $query1_args ); $query2 = new \WP_Query( $query2_args ); + $this->assertTrue( $query1->elasticsearch_success ); + $this->assertTrue( $query2->elasticsearch_success ); + $this->assertTrue( isset( $query1->posts[0]->elasticsearch ) ); $this->assertTrue( isset( $query2->posts[0]->elasticsearch ) ); @@ -5059,6 +5221,7 @@ public function testTagQuery() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); @@ -5077,6 +5240,7 @@ public function testTagQuery() { $query = new \WP_Query( $args ); + $this->assertTrue( $query->elasticsearch_success ); $this->assertEquals( 2, $query->post_count ); $this->assertEquals( 2, $query->found_posts ); } @@ -6002,6 +6166,8 @@ public function testMaybeSwitchToBlog() { ] ); + $this->assertTrue( $query->elasticsearch_success ); + $blog_1_post = $query->posts[0]; $this->assertSame( $blog_1_id, $blog_1_post->site_id ); @@ -6021,6 +6187,8 @@ public function testMaybeSwitchToBlog() { ] ); + $this->assertTrue( $query->elasticsearch_success ); + $blog_2_post = $query->posts[0]; $this->assertSame( $blog_2_id, $blog_2_post->site_id );