From e31a0390b1a165009457211d371d6b258220312d Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Tue, 13 Oct 2015 02:35:36 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@35112 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/term/meta.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/phpunit/tests/term/meta.php b/tests/phpunit/tests/term/meta.php index ae1f372c0b..270eb4bc41 100644 --- a/tests/phpunit/tests/term/meta.php +++ b/tests/phpunit/tests/term/meta.php @@ -122,7 +122,10 @@ class Tests_Term_Meta extends WP_UnitTestCase { $orphan_term = $this->factory->term->create( array( 'taxonomy' => 'wptests_tax' ) ); add_term_meta( $orphan_term, 'foo', 'bar' ); + // Force results to be cached, even when using extended cache. + add_action( 'pre_get_posts', array( $this, 'set_cache_results' ) ); $this->go_to( get_permalink( $p ) ); + remove_action( 'pre_get_posts', array( $this, 'set_cache_results' ) ); if ( have_posts() ) { while ( have_posts() ) { @@ -163,9 +166,9 @@ class Tests_Term_Meta extends WP_UnitTestCase { add_term_meta( $t, 'foo', 'bar' ); } - $q0 = new WP_Query( array( 'p' => $posts[0] ) ); - $q1 = new WP_Query( array( 'p' => $posts[1] ) ); - $q2 = new WP_Query( array( 'p' => $posts[2] ) ); + $q0 = new WP_Query( array( 'p' => $posts[0], 'cache_results' => true ) ); + $q1 = new WP_Query( array( 'p' => $posts[1], 'cache_results' => true ) ); + $q2 = new WP_Query( array( 'p' => $posts[2], 'cache_results' => true ) ); /* * $terms[0] belongs to both $posts[0] and $posts[2], so `get_term_meta( $terms[0] )` should prime @@ -303,4 +306,8 @@ class Tests_Term_Meta extends WP_UnitTestCase { $this->assertEqualSets( array( $terms[0] ), $found ); } + + public static function set_cache_results( $q ) { + $q->set( 'cache_results', true ); + } }