From 9f990fa55f6745a1f77b9bacb1d30833b5909f4b Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Wed, 5 Feb 2025 10:06:12 +1100 Subject: [PATCH] Test the queries return the same sets of posts. --- tests/phpunit/tests/query/cacheResults.php | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/tests/phpunit/tests/query/cacheResults.php b/tests/phpunit/tests/query/cacheResults.php index 19d4bbee7446d..5fa38a59e73ea 100644 --- a/tests/phpunit/tests/query/cacheResults.php +++ b/tests/phpunit/tests/query/cacheResults.php @@ -208,15 +208,7 @@ public function test_generate_cache_key_unregister_post_type() { public function test_post_in_order_by_clauses_are_not_normalized() { global $wpdb; - $post_names = array( 'doctor-dillamond', 'elphaba', 'fiyero', 'glinda', 'the-wizard-of-oz' ); - $post_ids = array(); - foreach ( $post_names as $post_name ) { - $post_ids[] = self::factory()->post->create( - array( - 'post_name' => $post_name, - ) - ); - } + $post_ids = self::$posts; $query_vars1 = array( 'post__in' => $post_ids, @@ -249,9 +241,10 @@ public function test_post_in_order_by_clauses_are_not_normalized() { $this->assertNotEmpty( $cache_key_1, 'Cache key for query one should not be empty.' ); $this->assertNotEmpty( $cache_key_2, 'Cache key for query two should not be empty.' ); - // Test the posts are returned in the correct order. - $this->assertSame( array( 'doctor-dillamond', 'elphaba', 'fiyero', 'glinda', 'the-wizard-of-oz' ), wp_list_pluck( $query1->posts, 'post_name' ), 'Query one posts should be in alphabetical order' ); - $this->assertSame( array( 'the-wizard-of-oz', 'glinda', 'fiyero', 'elphaba', 'doctor-dillamond' ), wp_list_pluck( $query2->posts, 'post_name' ), 'Query two posts should be in reverse alphabetical order.' ); + // Test the posts are returned different orders. + $this->assertNotSame( wp_list_pluck( $query1->posts, 'ID' ), wp_list_pluck( $query2->posts, 'ID' ), 'Query one posts should not match the order of query two posts.' ); + // Test the posts are the same sets. + $this->assertSameSets( wp_list_pluck( $query1->posts, 'ID' ), wp_list_pluck( $query2->posts, 'ID' ), 'Query one posts should match the set of query two posts.' ); } /** @@ -312,6 +305,8 @@ public function test_post_parent_in_order_by_clauses_are_not_normalized() { // Test the posts are returned in the correct order. $this->assertSame( array( 'doctor-dillamond', 'elphaba', 'fiyero', 'glinda', 'the-wizard-of-oz' ), wp_list_pluck( $query1->posts, 'post_name' ), 'Query one posts should be in alphabetical order' ); $this->assertSame( array( 'the-wizard-of-oz', 'glinda', 'fiyero', 'elphaba', 'doctor-dillamond' ), wp_list_pluck( $query2->posts, 'post_name' ), 'Query two posts should be in reverse alphabetical order.' ); + // Test the posts are the same sets. + $this->assertSameSets( wp_list_pluck( $query1->posts, 'ID' ), wp_list_pluck( $query2->posts, 'ID' ), 'Query one posts should match the set of query two posts.' ); } /** @@ -367,6 +362,8 @@ public function test_post_name_in_order_by_clauses_are_not_normalized() { // Test the posts are returned in the correct order. $this->assertSame( array( 'doctor-dillamond', 'elphaba', 'glinda', 'the-wizard-of-oz' ), wp_list_pluck( $query1->posts, 'post_name' ), 'Query one posts should be in alphabetical order' ); $this->assertSame( array( 'the-wizard-of-oz', 'glinda', 'elphaba', 'doctor-dillamond' ), wp_list_pluck( $query2->posts, 'post_name' ), 'Query two posts should be in reverse alphabetical order.' ); + // Test the posts are the same sets. + $this->assertSameSets( wp_list_pluck( $query1->posts, 'ID' ), wp_list_pluck( $query2->posts, 'ID' ), 'Query one posts should match the set of query two posts.' ); } /**