Skip to content

Commit 881c8fa

Browse files
committed
Some tests.
1 parent 80f5575 commit 881c8fa

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

tests/phpunit/tests/query/cacheResults.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,70 @@ public function test_generate_cache_key_unregister_post_type() {
200200
$this->assertNotSame( $cache_key_1, $cache_key_2, 'Cache key should differ after unregistering post type.' );
201201
}
202202

203+
/**
204+
* @ticket 59516
205+
*
206+
* @covers WP_Query::generate_cache_key
207+
*
208+
* @dataProvider data_orderby_clauses_are_not_normalized
209+
*/
210+
public function test_orderby_clauses_are_not_normalized( $query_vars1, $query_vars2 ) {
211+
global $wpdb;
212+
213+
$this->assertArrayHasKey( 'orderby', $query_vars1, 'First query vars should have orderby.' );
214+
$this->assertArrayHasKey( 'orderby', $query_vars2, 'Second query vars should have orderby.' );
215+
216+
$fields = "{$wpdb->posts}.ID";
217+
$query1 = new WP_Query( $query_vars1 );
218+
$request1 = str_replace( $fields, "{$wpdb->posts}.*", $query1->request );
219+
220+
$query2 = new WP_Query( $query_vars2 );
221+
$request2 = str_replace( $fields, "{$wpdb->posts}.*", $query2->request );
222+
223+
$reflection = new ReflectionMethod( $query1, 'generate_cache_key' );
224+
$reflection->setAccessible( true );
225+
226+
$this->assertNotSame( $request1, $request2, 'Queries should not match' );
227+
228+
$cache_key_1 = $reflection->invoke( $query1, $query_vars1, $request1 );
229+
$cache_key_2 = $reflection->invoke( $query1, $query_vars2, $request2 );
230+
231+
$this->assertSame( $cache_key_1, $cache_key_2, 'Cache key should differ.' );
232+
}
233+
234+
public function data_orderby_clauses_are_not_normalized() {
235+
return array(
236+
'orderby post__in' => array(
237+
'query_vars1' => array(
238+
'post__in' => array( 1, 2, 3, 4, 5 ),
239+
'orderby' => 'post__in',
240+
),
241+
'query_vars2' => array(
242+
'post__in' => array( 5, 4, 3, 2, 1 ),
243+
'orderby' => 'post__in',
244+
),
245+
),
246+
'post parent in order' => array(
247+
'query_vars1' => array( 'post_parent__in' => array( 1, 2, 3, 4, 5 ), 'orderby' => 'post_parent__in' ),
248+
'query_vars2' => array( 'post_parent__in' => array( 5, 4, 3, 2, 1 ), 'orderby' => 'post_parent__in' ),
249+
),
250+
'orderby post_name__in' => array(
251+
'query_vars1' => array(
252+
'post_name__in' => array( 'elphaba', 'glinda', 'the-wizard-of-oz', 'doctor-dillamond' ),
253+
'orderby' => 'post_name__in',
254+
),
255+
'query_vars2' => array(
256+
'post_name__in' => array( 'doctor-dillamond', 'elphaba', 'the-wizard-of-oz', 'glinda' ),
257+
'orderby' => 'post_name__in',
258+
),
259+
),
260+
);
261+
}
262+
263+
203264
/**
204265
* @ticket 59442
266+
* @ticket 59516
205267
*
206268
* @covers WP_Query::generate_cache_key
207269
*
@@ -326,6 +388,18 @@ public function data_query_cache_duplicate() {
326388
'query_vars1' => array( 'post_status' => array( 'draft', 'publish' ) ),
327389
'query_vars2' => array( 'post_status' => array( 'publish', 'draft' ) ),
328390
),
391+
'post in order' => array(
392+
'query_vars1' => array( 'post__in' => array( 1, 2, 3, 4, 5 ) ),
393+
'query_vars2' => array( 'post__in' => array( 5, 4, 3, 2, 1 ) ),
394+
),
395+
'post parent in order' => array(
396+
'query_vars1' => array( 'post_parent__in' => array( 1, 2, 3, 4, 5 ) ),
397+
'query_vars2' => array( 'post_parent__in' => array( 5, 4, 3, 2, 1 ) ),
398+
),
399+
'post name in order' => array(
400+
'query_vars1' => array( 'post_name__in' => array( 'elphaba', 'glinda', 'the-wizard-of-oz', 'doctor-dillamond' ) ),
401+
'query_vars2' => array( 'post_name__in' => array( 'doctor-dillamond', 'elphaba', 'the-wizard-of-oz', 'glinda' ) ),
402+
),
329403
'cache parameters' => array(
330404
'query_vars1' => array(
331405
'update_post_meta_cache' => true,

0 commit comments

Comments
 (0)