Skip to content

Commit

Permalink
Some tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
peterwilsoncc committed Jan 16, 2025
1 parent 80f5575 commit 881c8fa
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions tests/phpunit/tests/query/cacheResults.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,70 @@ public function test_generate_cache_key_unregister_post_type() {
$this->assertNotSame( $cache_key_1, $cache_key_2, 'Cache key should differ after unregistering post type.' );
}

/**
* @ticket 59516
*
* @covers WP_Query::generate_cache_key
*
* @dataProvider data_orderby_clauses_are_not_normalized
*/
public function test_orderby_clauses_are_not_normalized( $query_vars1, $query_vars2 ) {
global $wpdb;

$this->assertArrayHasKey( 'orderby', $query_vars1, 'First query vars should have orderby.' );
$this->assertArrayHasKey( 'orderby', $query_vars2, 'Second query vars should have orderby.' );

$fields = "{$wpdb->posts}.ID";
$query1 = new WP_Query( $query_vars1 );
$request1 = str_replace( $fields, "{$wpdb->posts}.*", $query1->request );

$query2 = new WP_Query( $query_vars2 );
$request2 = str_replace( $fields, "{$wpdb->posts}.*", $query2->request );

$reflection = new ReflectionMethod( $query1, 'generate_cache_key' );
$reflection->setAccessible( true );

$this->assertNotSame( $request1, $request2, 'Queries should not match' );

$cache_key_1 = $reflection->invoke( $query1, $query_vars1, $request1 );
$cache_key_2 = $reflection->invoke( $query1, $query_vars2, $request2 );

$this->assertSame( $cache_key_1, $cache_key_2, 'Cache key should differ.' );
}

public function data_orderby_clauses_are_not_normalized() {
return array(
'orderby post__in' => array(
'query_vars1' => array(
'post__in' => array( 1, 2, 3, 4, 5 ),
'orderby' => 'post__in',
),
'query_vars2' => array(
'post__in' => array( 5, 4, 3, 2, 1 ),
'orderby' => 'post__in',
),
),
'post parent in order' => array(
'query_vars1' => array( 'post_parent__in' => array( 1, 2, 3, 4, 5 ), 'orderby' => 'post_parent__in' ),

Check failure on line 247 in tests/phpunit/tests/query/cacheResults.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

When a multi-item array uses associative keys, each value should start on a new line.
'query_vars2' => array( 'post_parent__in' => array( 5, 4, 3, 2, 1 ), 'orderby' => 'post_parent__in' ),

Check failure on line 248 in tests/phpunit/tests/query/cacheResults.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

When a multi-item array uses associative keys, each value should start on a new line.
),
'orderby post_name__in' => array(
'query_vars1' => array(
'post_name__in' => array( 'elphaba', 'glinda', 'the-wizard-of-oz', 'doctor-dillamond' ),
'orderby' => 'post_name__in',
),
'query_vars2' => array(
'post_name__in' => array( 'doctor-dillamond', 'elphaba', 'the-wizard-of-oz', 'glinda' ),
'orderby' => 'post_name__in',
),
),
);
}


/**
* @ticket 59442
* @ticket 59516
*
* @covers WP_Query::generate_cache_key
*
Expand Down Expand Up @@ -326,6 +388,18 @@ public function data_query_cache_duplicate() {
'query_vars1' => array( 'post_status' => array( 'draft', 'publish' ) ),
'query_vars2' => array( 'post_status' => array( 'publish', 'draft' ) ),
),
'post in order' => array(
'query_vars1' => array( 'post__in' => array( 1, 2, 3, 4, 5 ) ),
'query_vars2' => array( 'post__in' => array( 5, 4, 3, 2, 1 ) ),
),
'post parent in order' => array(
'query_vars1' => array( 'post_parent__in' => array( 1, 2, 3, 4, 5 ) ),
'query_vars2' => array( 'post_parent__in' => array( 5, 4, 3, 2, 1 ) ),
),
'post name in order' => array(
'query_vars1' => array( 'post_name__in' => array( 'elphaba', 'glinda', 'the-wizard-of-oz', 'doctor-dillamond' ) ),
'query_vars2' => array( 'post_name__in' => array( 'doctor-dillamond', 'elphaba', 'the-wizard-of-oz', 'glinda' ) ),
),
'cache parameters' => array(
'query_vars1' => array(
'update_post_meta_cache' => true,
Expand Down

0 comments on commit 881c8fa

Please sign in to comment.