Skip to content

Commit

Permalink
Add test for random order with the seed value
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafauysal committed Feb 22, 2020
1 parent 2bf808d commit f70ee87
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/php/indexables/TestPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit f70ee87

Please sign in to comment.