From f70ee87db9ac22d0d4c11ef7c67a527318153aa4 Mon Sep 17 00:00:00 2001 From: mustafauysal Date: Sat, 22 Feb 2020 21:48:20 +0300 Subject: [PATCH] Add test for random order with the seed value --- tests/php/indexables/TestPost.php | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/php/indexables/TestPost.php b/tests/php/indexables/TestPost.php index 87d61cdef9..8e170814ea 100644 --- a/tests/php/indexables/TestPost.php +++ b/tests/php/indexables/TestPost.php @@ -2280,6 +2280,38 @@ public function testRandOrderby() { $this->assertEquals( 3, $query->found_posts ); } + /** + * Test random order with the seed value + * + * @since 3.4 + * @group post + */ + public function testRandOrderWithSeed() { + Functions\create_and_sync_post( array( 'post_title' => 'ordertest 1' ) ); + Functions\create_and_sync_post( array( 'post_title' => 'ordertest 2' ) ); + Functions\create_and_sync_post( array( 'post_title' => 'ordertest 3' ) ); + + ElasticPress\Elasticsearch::factory()->refresh_indices(); + add_action( 'ep_wp_query_search', array( $this, 'action_wp_query_search' ), 10, 0 ); + + $args = array( + 'ep_integrate' => true, + 'orderby' => 'rand(3)', + ); + + $query = new \WP_Query( $args ); + + // make sure the response retrieved from ES + $this->assertTrue( ! empty( $this->fired_actions['ep_wp_query_search'] ) ); + + /** + * Since it's test for random order, can't check against exact post ID or content + * but only found posts and post count. + */ + $this->assertEquals( 3, $query->post_count ); + $this->assertEquals( 3, $query->found_posts ); + } + /** * Test that a post being directly deleted gets correctly removed from the Elasticsearch index *