Make WordPress Core

Changeset 35112


Ignore:
Timestamp:
10/13/2015 02:35:36 AM (9 years ago)
Author:
boonebgorges
Message:

In term meta lazy-loading tests, force WP_Query to cache results.

By default, WP_Query will not cache query results when using a persistent
object cache. The lazyload tests, however, depend on the cache being set during
each WP_Query, because the object cache is cleared between tests.

See #31491.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/term/meta.php

    r34704 r35112  
    123123        add_term_meta( $orphan_term, 'foo', 'bar' );
    124124
     125        // Force results to be cached, even when using extended cache.
     126        add_action( 'pre_get_posts', array( $this, 'set_cache_results' ) );
    125127        $this->go_to( get_permalink( $p ) );
     128        remove_action( 'pre_get_posts', array( $this, 'set_cache_results' ) );
    126129
    127130        if ( have_posts() ) {
     
    164167        }
    165168
    166         $q0 = new WP_Query( array( 'p' => $posts[0] ) );
    167         $q1 = new WP_Query( array( 'p' => $posts[1] ) );
    168         $q2 = new WP_Query( array( 'p' => $posts[2] ) );
     169        $q0 = new WP_Query( array( 'p' => $posts[0], 'cache_results' => true ) );
     170        $q1 = new WP_Query( array( 'p' => $posts[1], 'cache_results' => true ) );
     171        $q2 = new WP_Query( array( 'p' => $posts[2], 'cache_results' => true ) );
    169172
    170173        /*
     
    304307        $this->assertEqualSets( array( $terms[0] ), $found );
    305308    }
     309
     310    public static function set_cache_results( $q ) {
     311        $q->set( 'cache_results', true );
     312    }
    306313}
Note: See TracChangeset for help on using the changeset viewer.