mirror of
git://develop.git.wordpress.org/
synced 2025-04-21 04:31:55 +02:00
Tests: Use the function get_num_queries
across all unit tests.
Replace use of `$wpdb->num_queries` with a function call to `get_num_queries`. This improves readability and consistency between tests. Props SergeyBiryukov, peterwilsoncc, spacedmonkey. See #57841. git-svn-id: https://develop.svn.wordpress.org/trunk@55745 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
55ee499f4e
commit
07fc459e7a
8
package-lock.json
generated
8
package-lock.json
generated
@ -11954,7 +11954,7 @@
|
||||
"from2-string": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/from2-string/-/from2-string-1.1.0.tgz",
|
||||
"integrity": "sha512-m8vCh+KnXXXBtfF2VUbiYlQ+nczLcntB0BrtNgpmLkHylhObe9WF1b2LZjBBzrZzA6P4mkEla6ZYQoOUTG8cYA==",
|
||||
"integrity": "sha1-GCgrJ9CKJnyzAwzSuLSw8hKvdSo=",
|
||||
"requires": {
|
||||
"from2": "^2.0.3"
|
||||
}
|
||||
@ -21112,7 +21112,7 @@
|
||||
"promise-polyfill": {
|
||||
"version": "1.1.6",
|
||||
"resolved": "https://registry.npmjs.org/promise-polyfill/-/promise-polyfill-1.1.6.tgz",
|
||||
"integrity": "sha512-7rrONfyLkDEc7OJ5QBkqa4KI4EBhCd340xRuIUPGCfu13znS+vx+VDdrT9ODAJHlXm7w4lbxN3DRjyv58EuzDg=="
|
||||
"integrity": "sha1-zQTv9G9clcOn0EVZHXm14+AfEtc="
|
||||
},
|
||||
"prompts": {
|
||||
"version": "2.4.2",
|
||||
@ -23251,7 +23251,7 @@
|
||||
"stream-from-promise": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/stream-from-promise/-/stream-from-promise-1.0.0.tgz",
|
||||
"integrity": "sha512-j84KLkudt+gr8KJ21RB02btPLx61uGbrLnewsWz6QKmsz8/c4ZFqXw6mJh5+G4oRN7DgDxdbjPxnpySpg1mUig=="
|
||||
"integrity": "sha1-djaH9913fkyJT2QIMz/Gs/yKYbs="
|
||||
},
|
||||
"stream-to-string": {
|
||||
"version": "1.2.0",
|
||||
@ -24519,7 +24519,7 @@
|
||||
"toposort": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/toposort/-/toposort-2.0.2.tgz",
|
||||
"integrity": "sha512-0a5EOkAUp8D4moMi2W8ZF8jcga7BgZd91O/yabJCFY8az+XSzeGyTKs0Aoo897iV1Nj6guFq8orWDS96z91oGg=="
|
||||
"integrity": "sha1-riF2gXXRVZ1IvvNUILL0li8JwzA="
|
||||
},
|
||||
"totalist": {
|
||||
"version": "1.1.0",
|
||||
|
@ -5,8 +5,6 @@
|
||||
*/
|
||||
class Tests_Bookmark_GetBookmarks extends WP_UnitTestCase {
|
||||
public function test_should_hit_cache() {
|
||||
global $wpdb;
|
||||
|
||||
$bookmarks = self::factory()->bookmark->create_many( 2 );
|
||||
|
||||
$found1 = get_bookmarks(
|
||||
@ -15,7 +13,7 @@ class Tests_Bookmark_GetBookmarks extends WP_UnitTestCase {
|
||||
)
|
||||
);
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
$found2 = get_bookmarks(
|
||||
array(
|
||||
@ -24,12 +22,10 @@ class Tests_Bookmark_GetBookmarks extends WP_UnitTestCase {
|
||||
);
|
||||
|
||||
$this->assertSameSets( $found1, $found2 );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
public function test_adding_bookmark_should_bust_get_bookmarks_cache() {
|
||||
global $wpdb;
|
||||
|
||||
$bookmarks = self::factory()->bookmark->create_many( 2 );
|
||||
|
||||
// Prime cache.
|
||||
@ -39,7 +35,7 @@ class Tests_Bookmark_GetBookmarks extends WP_UnitTestCase {
|
||||
)
|
||||
);
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
$bookmarks[] = wp_insert_link(
|
||||
array(
|
||||
@ -55,15 +51,13 @@ class Tests_Bookmark_GetBookmarks extends WP_UnitTestCase {
|
||||
);
|
||||
|
||||
$this->assertEqualSets( $bookmarks, wp_list_pluck( $found2, 'link_id' ) );
|
||||
$this->assertGreaterThan( $num_queries, $wpdb->num_queries );
|
||||
$this->assertGreaterThan( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 18356
|
||||
*/
|
||||
public function test_orderby_rand_should_not_be_cached() {
|
||||
global $wpdb;
|
||||
|
||||
$bookmarks = self::factory()->bookmark->create_many( 2 );
|
||||
|
||||
$found1 = get_bookmarks(
|
||||
@ -72,7 +66,7 @@ class Tests_Bookmark_GetBookmarks extends WP_UnitTestCase {
|
||||
)
|
||||
);
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
$found2 = get_bookmarks(
|
||||
array(
|
||||
@ -82,7 +76,7 @@ class Tests_Bookmark_GetBookmarks extends WP_UnitTestCase {
|
||||
|
||||
// Equal sets != same order.
|
||||
$this->assertEqualSets( $found1, $found2 );
|
||||
$this->assertGreaterThan( $num_queries, $wpdb->num_queries );
|
||||
$this->assertGreaterThan( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
public function test_exclude_param_gets_properly_parsed_as_list() {
|
||||
|
@ -100,27 +100,23 @@ class Tests_Comment_GetPageOfComment extends WP_UnitTestCase {
|
||||
* @ticket 11334
|
||||
*/
|
||||
public function test_subsequent_calls_should_hit_cache() {
|
||||
global $wpdb;
|
||||
|
||||
$p = self::factory()->post->create();
|
||||
$c = self::factory()->comment->create( array( 'comment_post_ID' => $p ) );
|
||||
|
||||
// Prime cache.
|
||||
$page_1 = get_page_of_comment( $c, array( 'per_page' => 3 ) );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
$page_2 = get_page_of_comment( $c, array( 'per_page' => 3 ) );
|
||||
|
||||
$this->assertSame( $page_1, $page_2 );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 11334
|
||||
*/
|
||||
public function test_cache_hits_should_be_sensitive_to_comment_type() {
|
||||
global $wpdb;
|
||||
|
||||
$p = self::factory()->post->create();
|
||||
$comment = self::factory()->comment->create(
|
||||
array(
|
||||
@ -151,7 +147,7 @@ class Tests_Comment_GetPageOfComment extends WP_UnitTestCase {
|
||||
);
|
||||
$this->assertSame( 2, $page_trackbacks );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
$page_comments = get_page_of_comment(
|
||||
$comment,
|
||||
array(
|
||||
@ -161,7 +157,7 @@ class Tests_Comment_GetPageOfComment extends WP_UnitTestCase {
|
||||
);
|
||||
$this->assertSame( 1, $page_comments );
|
||||
|
||||
$this->assertNotEquals( $num_queries, $wpdb->num_queries );
|
||||
$this->assertNotEquals( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -12,8 +12,6 @@ class Tests_Comment_MetaCache extends WP_UnitTestCase {
|
||||
* @covers ::update_comment_meta
|
||||
*/
|
||||
public function test_update_comment_meta_cache_should_default_to_true() {
|
||||
global $wpdb;
|
||||
|
||||
$p = self::factory()->post->create( array( 'post_status' => 'publish' ) );
|
||||
$comment_ids = self::factory()->comment->create_post_comments( $p, 3 );
|
||||
|
||||
@ -30,12 +28,12 @@ class Tests_Comment_MetaCache extends WP_UnitTestCase {
|
||||
)
|
||||
);
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
foreach ( $comment_ids as $cid ) {
|
||||
get_comment_meta( $cid, 'foo', 'bar' );
|
||||
}
|
||||
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -44,8 +42,6 @@ class Tests_Comment_MetaCache extends WP_UnitTestCase {
|
||||
* @covers ::update_comment_meta
|
||||
*/
|
||||
public function test_update_comment_meta_cache_true() {
|
||||
global $wpdb;
|
||||
|
||||
$p = self::factory()->post->create( array( 'post_status' => 'publish' ) );
|
||||
$comment_ids = self::factory()->comment->create_post_comments( $p, 3 );
|
||||
|
||||
@ -63,12 +59,12 @@ class Tests_Comment_MetaCache extends WP_UnitTestCase {
|
||||
)
|
||||
);
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
foreach ( $comment_ids as $cid ) {
|
||||
get_comment_meta( $cid, 'foo', 'bar' );
|
||||
}
|
||||
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -77,8 +73,6 @@ class Tests_Comment_MetaCache extends WP_UnitTestCase {
|
||||
* @covers ::update_comment_meta
|
||||
*/
|
||||
public function test_update_comment_meta_cache_false() {
|
||||
global $wpdb;
|
||||
|
||||
$p = self::factory()->post->create( array( 'post_status' => 'publish' ) );
|
||||
$comment_ids = self::factory()->comment->create_post_comments( $p, 3 );
|
||||
|
||||
@ -93,12 +87,12 @@ class Tests_Comment_MetaCache extends WP_UnitTestCase {
|
||||
)
|
||||
);
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
foreach ( $comment_ids as $cid ) {
|
||||
get_comment_meta( $cid, 'foo', 'bar' );
|
||||
}
|
||||
|
||||
$this->assertSame( $num_queries + 3, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries + 3, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -107,8 +101,6 @@ class Tests_Comment_MetaCache extends WP_UnitTestCase {
|
||||
* @covers ::get_comment_meta
|
||||
*/
|
||||
public function test_comment_meta_should_be_lazy_loaded_for_all_comments_in_comments_template() {
|
||||
global $wpdb;
|
||||
|
||||
$p = self::factory()->post->create( array( 'post_status' => 'publish' ) );
|
||||
$comment_ids = self::factory()->comment->create_post_comments( $p, 3 );
|
||||
|
||||
@ -126,14 +118,14 @@ class Tests_Comment_MetaCache extends WP_UnitTestCase {
|
||||
$cform = get_echo( 'comments_template' );
|
||||
|
||||
// First request will hit the database.
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
get_comment_meta( $comment_ids[0], 'sauce' );
|
||||
$this->assertSame( $num_queries + 1, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries + 1, get_num_queries() );
|
||||
|
||||
// Second and third requests should be in cache.
|
||||
get_comment_meta( $comment_ids[1], 'sauce' );
|
||||
get_comment_meta( $comment_ids[2], 'sauce' );
|
||||
$this->assertSame( $num_queries + 1, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries + 1, get_num_queries() );
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -144,8 +136,6 @@ class Tests_Comment_MetaCache extends WP_UnitTestCase {
|
||||
* @covers ::get_comment_meta
|
||||
*/
|
||||
public function test_comment_meta_should_be_lazy_loaded_in_comment_feed_queries() {
|
||||
global $wpdb;
|
||||
|
||||
$posts = self::factory()->post->create_many( 2, array( 'post_status' => 'publish' ) );
|
||||
|
||||
$now = time();
|
||||
@ -173,19 +163,19 @@ class Tests_Comment_MetaCache extends WP_UnitTestCase {
|
||||
);
|
||||
|
||||
// First comment will cause the cache to be primed.
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
$this->assertSame( 'bar', get_comment_meta( $comments[0], 'foo', 'bar' ) );
|
||||
$num_queries++;
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
|
||||
// Second comment from the results should not cause more queries.
|
||||
$this->assertSame( 'bar', get_comment_meta( $comments[1], 'foo', 'bar' ) );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
|
||||
// A comment from outside the results will not be primed.
|
||||
$this->assertSame( 'bar', get_comment_meta( $comments[4], 'foo', 'bar' ) );
|
||||
$num_queries++;
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -194,8 +184,6 @@ class Tests_Comment_MetaCache extends WP_UnitTestCase {
|
||||
* @covers ::get_comment_meta
|
||||
*/
|
||||
public function test_comment_meta_should_be_lazy_loaded_in_single_post_comment_feed_queries() {
|
||||
global $wpdb;
|
||||
|
||||
$posts = self::factory()->post->create_many( 2, array( 'post_status' => 'publish' ) );
|
||||
|
||||
$now = time();
|
||||
@ -224,19 +212,19 @@ class Tests_Comment_MetaCache extends WP_UnitTestCase {
|
||||
);
|
||||
|
||||
// First comment will cause the cache to be primed.
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
$this->assertSame( 'bar', get_comment_meta( $comments[0], 'foo', 'bar' ) );
|
||||
$num_queries++;
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
|
||||
// Second comment from the results should not cause more queries.
|
||||
$this->assertSame( 'bar', get_comment_meta( $comments[1], 'foo', 'bar' ) );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
|
||||
// A comment from outside the results will not be primed.
|
||||
$this->assertSame( 'bar', get_comment_meta( $comments[4], 'foo', 'bar' ) );
|
||||
$num_queries++;
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3588,8 +3588,6 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
* @covers WP_Comment_Query::query
|
||||
*/
|
||||
public function test_comment_cache_key_should_ignore_custom_params() {
|
||||
global $wpdb;
|
||||
|
||||
$p = self::factory()->post->create();
|
||||
$c = self::factory()->comment->create( array( 'comment_post_ID' => $p ) );
|
||||
|
||||
@ -3601,7 +3599,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
)
|
||||
);
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
$q2 = new WP_Comment_Query();
|
||||
$q2->query(
|
||||
@ -3612,7 +3610,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -3629,7 +3627,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
)
|
||||
);
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
$q2 = new WP_Comment_Query(
|
||||
array(
|
||||
@ -3637,7 +3635,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertNotEquals( $num_queries, $wpdb->num_queries );
|
||||
$this->assertNotEquals( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -3654,7 +3652,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
)
|
||||
);
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
$q2 = new WP_Comment_Query(
|
||||
array(
|
||||
@ -3662,7 +3660,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertNotEquals( $num_queries, $wpdb->num_queries );
|
||||
$this->assertNotEquals( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -4427,7 +4425,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
);
|
||||
$q1_ids = wp_list_pluck( $q1->comments, 'comment_ID' );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
$q2 = new WP_Comment_Query(
|
||||
array(
|
||||
'post_id' => $p,
|
||||
@ -4437,7 +4435,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
$q2_ids = wp_list_pluck( $q2->comments, 'comment_ID' );
|
||||
|
||||
$this->assertSameSets( $q1_ids, $q2_ids );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -4590,9 +4588,9 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
)
|
||||
);
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
$this->assertTrue( isset( $q->comments[0]->post_name ) );
|
||||
$this->assertSame( $num_queries + 1, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries + 1, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -4613,9 +4611,9 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
)
|
||||
);
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
$this->assertTrue( isset( $q->comments[0]->post_name ) );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -4629,7 +4627,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
$comments = self::factory()->comment->create_many( 3, array( 'comment_post_ID' => self::$post_id ) );
|
||||
clean_comment_cache( $comments );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
$q = new WP_Comment_Query(
|
||||
array(
|
||||
'post_id' => self::$post_id,
|
||||
@ -4645,7 +4643,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
$found = wp_list_pluck( $q->comments, 'comment_ID' );
|
||||
$this->assertEqualSets( $comments, $found );
|
||||
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -4692,7 +4690,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
)
|
||||
);
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
$q2 = new WP_Comment_Query(
|
||||
array(
|
||||
@ -4701,7 +4699,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -4724,7 +4722,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
)
|
||||
);
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
$q = new WP_Comment_Query(
|
||||
array(
|
||||
@ -4733,7 +4731,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
$this->assertSameSets( array( $c ), $q->comments );
|
||||
}
|
||||
|
||||
@ -4766,7 +4764,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
)
|
||||
);
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
$q = new WP_Comment_Query(
|
||||
array(
|
||||
@ -4776,7 +4774,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
);
|
||||
|
||||
$num_queries++;
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
$this->assertSameSets( array( $c ), $q->comments );
|
||||
}
|
||||
|
||||
@ -4802,7 +4800,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
|
||||
wp_delete_comment( $c );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
$q = new WP_Comment_Query(
|
||||
array(
|
||||
@ -4812,7 +4810,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
);
|
||||
|
||||
$num_queries++;
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
$this->assertSameSets( array(), $q->comments );
|
||||
}
|
||||
|
||||
@ -4838,7 +4836,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
|
||||
wp_trash_comment( $c );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
$q = new WP_Comment_Query(
|
||||
array(
|
||||
@ -4848,7 +4846,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
);
|
||||
|
||||
$num_queries++;
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
$this->assertSameSets( array(), $q->comments );
|
||||
}
|
||||
|
||||
@ -4876,7 +4874,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
|
||||
wp_untrash_comment( $c );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
$q = new WP_Comment_Query(
|
||||
array(
|
||||
@ -4886,7 +4884,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
);
|
||||
|
||||
$num_queries++;
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
$this->assertSameSets( array( $c ), $q->comments );
|
||||
}
|
||||
|
||||
@ -4912,7 +4910,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
|
||||
wp_spam_comment( $c );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
$q = new WP_Comment_Query(
|
||||
array(
|
||||
@ -4922,7 +4920,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
);
|
||||
|
||||
$num_queries++;
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
$this->assertSameSets( array(), $q->comments );
|
||||
}
|
||||
|
||||
@ -4950,7 +4948,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
|
||||
wp_unspam_comment( $c );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
$q = new WP_Comment_Query(
|
||||
array(
|
||||
@ -4960,7 +4958,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
);
|
||||
|
||||
$num_queries++;
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
$this->assertSameSets( array( $c ), $q->comments );
|
||||
}
|
||||
|
||||
@ -4982,7 +4980,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
)
|
||||
);
|
||||
|
||||
$number_of_queries = $wpdb->num_queries;
|
||||
$number_of_queries = get_num_queries();
|
||||
|
||||
$query_2 = $q->query(
|
||||
array(
|
||||
@ -4992,7 +4990,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
'count' => true,
|
||||
)
|
||||
);
|
||||
$this->assertSame( $number_of_queries + 1, $wpdb->num_queries );
|
||||
$this->assertSame( $number_of_queries + 1, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -5013,7 +5011,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
'count' => true,
|
||||
)
|
||||
);
|
||||
$number_of_queries = $wpdb->num_queries;
|
||||
$number_of_queries = get_num_queries();
|
||||
|
||||
$query_2 = $q->query(
|
||||
array(
|
||||
@ -5023,7 +5021,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
'count' => true,
|
||||
)
|
||||
);
|
||||
$this->assertSame( $number_of_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $number_of_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -5043,7 +5041,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
'order' => 'ASC',
|
||||
)
|
||||
);
|
||||
$number_of_queries = $wpdb->num_queries;
|
||||
$number_of_queries = get_num_queries();
|
||||
|
||||
$query_2 = $q->query(
|
||||
array(
|
||||
@ -5053,7 +5051,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertSame( $number_of_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $number_of_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -5219,7 +5217,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
|
||||
add_filter( 'comments_pre_query', array( __CLASS__, 'filter_comments_pre_query' ), 10, 2 );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
$q = new WP_Comment_Query();
|
||||
$results = $q->query( array() );
|
||||
@ -5227,7 +5225,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
remove_filter( 'comments_pre_query', array( __CLASS__, 'filter_comments_pre_query' ), 10, 2 );
|
||||
|
||||
// Make sure no queries were executed.
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
|
||||
// We manually inserted a non-existing site and overrode the results with it.
|
||||
$this->assertSame( array( 555 ), $results );
|
||||
|
@ -14,16 +14,14 @@ class Tests_Comment_wpUpdateCommentCountNow extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_regular_post_updates_comment_count() {
|
||||
global $wpdb;
|
||||
|
||||
$post_id = self::factory()->post->create();
|
||||
|
||||
self::factory()->comment->create_post_comments( $post_id, 1 );
|
||||
$this->assertSame( '1', get_comments_number( $post_id ) );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
$this->assertTrue( wp_update_comment_count_now( $post_id ) );
|
||||
$this->assertSame( $num_queries + 2, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries + 2, get_num_queries() );
|
||||
|
||||
$this->assertSame( '1', get_comments_number( $post_id ) );
|
||||
}
|
||||
@ -38,10 +36,10 @@ class Tests_Comment_wpUpdateCommentCountNow extends WP_UnitTestCase {
|
||||
self::factory()->comment->create_post_comments( $post_id, 1 );
|
||||
$this->assertSame( '100', get_comments_number( $post_id ) );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
$this->assertTrue( wp_update_comment_count_now( $post_id ) );
|
||||
// Only one query is made instead of two.
|
||||
$this->assertSame( $num_queries + 1, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries + 1, get_num_queries() );
|
||||
|
||||
$this->assertSame( '100', get_comments_number( $post_id ) );
|
||||
|
||||
|
@ -271,7 +271,7 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase {
|
||||
* @ticket 41039
|
||||
*/
|
||||
public function test_fresh_site_flag_clearing() {
|
||||
global $wp_customize, $wpdb;
|
||||
global $wp_customize;
|
||||
|
||||
// Make sure fresh site flag is cleared when publishing a changeset.
|
||||
update_option( 'fresh_site', '1' );
|
||||
@ -283,9 +283,9 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase {
|
||||
wp_load_alloptions();
|
||||
|
||||
// Make sure no DB write is done when publishing and a site is already non-fresh.
|
||||
$query_count = $wpdb->num_queries;
|
||||
$query_count = get_num_queries();
|
||||
do_action( 'customize_save_after', $wp_customize );
|
||||
$this->assertSame( $query_count, $wpdb->num_queries );
|
||||
$this->assertSame( $query_count, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -16,13 +16,11 @@ class Tests_General_wpGetArchives extends WP_UnitTestCase {
|
||||
* @ticket 23206
|
||||
*/
|
||||
public function test_get_archives_cache() {
|
||||
global $wpdb;
|
||||
|
||||
self::factory()->post->create_many( 3, array( 'post_type' => 'post' ) );
|
||||
wp_cache_delete( 'last_changed', 'posts' );
|
||||
$this->assertFalse( wp_cache_get( 'last_changed', 'posts' ) );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
// Cache is not primed, expect 1 query.
|
||||
$result = wp_get_archives(
|
||||
@ -34,9 +32,9 @@ class Tests_General_wpGetArchives extends WP_UnitTestCase {
|
||||
$this->assertIsString( $result );
|
||||
$time1 = wp_cache_get( 'last_changed', 'posts' );
|
||||
$this->assertNotEmpty( $time1 );
|
||||
$this->assertSame( $num_queries + 1, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries + 1, get_num_queries() );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
// Cache is primed, expect no queries.
|
||||
$result = wp_get_archives(
|
||||
@ -47,7 +45,7 @@ class Tests_General_wpGetArchives extends WP_UnitTestCase {
|
||||
);
|
||||
$this->assertIsString( $result );
|
||||
$this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
|
||||
// Change args, resulting in a different query string. Cache is not primed, expect 1 query.
|
||||
$result = wp_get_archives(
|
||||
@ -59,9 +57,9 @@ class Tests_General_wpGetArchives extends WP_UnitTestCase {
|
||||
);
|
||||
$this->assertIsString( $result );
|
||||
$this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
|
||||
$this->assertSame( $num_queries + 1, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries + 1, get_num_queries() );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
// Cache is primed, expect no queries.
|
||||
$result = wp_get_archives(
|
||||
@ -73,9 +71,9 @@ class Tests_General_wpGetArchives extends WP_UnitTestCase {
|
||||
);
|
||||
$this->assertIsString( $result );
|
||||
$this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
// Change type. Cache is not primed, expect 1 query.
|
||||
$result = wp_get_archives(
|
||||
@ -86,9 +84,9 @@ class Tests_General_wpGetArchives extends WP_UnitTestCase {
|
||||
);
|
||||
$this->assertIsString( $result );
|
||||
$this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
|
||||
$this->assertSame( $num_queries + 1, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries + 1, get_num_queries() );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
// Cache is primed, expect no queries.
|
||||
$result = wp_get_archives(
|
||||
@ -99,7 +97,7 @@ class Tests_General_wpGetArchives extends WP_UnitTestCase {
|
||||
);
|
||||
$this->assertIsString( $result );
|
||||
$this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
|
||||
// Change type. Cache is not primed, expect 1 query.
|
||||
$result = wp_get_archives(
|
||||
@ -110,9 +108,9 @@ class Tests_General_wpGetArchives extends WP_UnitTestCase {
|
||||
);
|
||||
$this->assertIsString( $result );
|
||||
$this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
|
||||
$this->assertSame( $num_queries + 1, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries + 1, get_num_queries() );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
// Cache is primed, expect no queries.
|
||||
$result = wp_get_archives(
|
||||
@ -123,7 +121,7 @@ class Tests_General_wpGetArchives extends WP_UnitTestCase {
|
||||
);
|
||||
$this->assertIsString( $result );
|
||||
$this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
|
||||
// Change type. Cache is not primed, expect 1 query.
|
||||
$result = wp_get_archives(
|
||||
@ -134,9 +132,9 @@ class Tests_General_wpGetArchives extends WP_UnitTestCase {
|
||||
);
|
||||
$this->assertIsString( $result );
|
||||
$this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
|
||||
$this->assertSame( $num_queries + 1, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries + 1, get_num_queries() );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
// Cache is primed, expect no queries.
|
||||
$result = wp_get_archives(
|
||||
@ -147,7 +145,7 @@ class Tests_General_wpGetArchives extends WP_UnitTestCase {
|
||||
);
|
||||
$this->assertIsString( $result );
|
||||
$this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
|
||||
// Change type. Cache is not primed, expect 1 query.
|
||||
$result = wp_get_archives(
|
||||
@ -158,9 +156,9 @@ class Tests_General_wpGetArchives extends WP_UnitTestCase {
|
||||
);
|
||||
$this->assertIsString( $result );
|
||||
$this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
|
||||
$this->assertSame( $num_queries + 1, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries + 1, get_num_queries() );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
// Cache is primed, expect no queries.
|
||||
$result = wp_get_archives(
|
||||
@ -171,6 +169,6 @@ class Tests_General_wpGetArchives extends WP_UnitTestCase {
|
||||
);
|
||||
$this->assertIsString( $result );
|
||||
$this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
}
|
||||
|
@ -590,14 +590,12 @@ if ( is_multisite() ) :
|
||||
* @ticket 42251
|
||||
*/
|
||||
public function test_get_network_not_found_cache() {
|
||||
global $wpdb;
|
||||
|
||||
$new_network_id = $this->_get_next_network_id();
|
||||
$this->assertNull( get_network( $new_network_id ) );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
$this->assertNull( get_network( $new_network_id ) );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2170,14 +2170,12 @@ if ( is_multisite() ) :
|
||||
* @ticket 42251
|
||||
*/
|
||||
public function test_get_site_not_found_cache() {
|
||||
global $wpdb;
|
||||
|
||||
$new_site_id = $this->_get_next_site_id();
|
||||
$this->assertNull( get_site( $new_site_id ) );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
$this->assertNull( get_site( $new_site_id ) );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -220,8 +220,6 @@ if ( is_multisite() ) :
|
||||
}
|
||||
|
||||
public function test_update_site_meta_cache() {
|
||||
global $wpdb;
|
||||
|
||||
if ( ! is_site_meta_supported() ) {
|
||||
$this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
|
||||
}
|
||||
@ -229,14 +227,12 @@ if ( is_multisite() ) :
|
||||
update_site_meta( self::$site_id, 'foo', 'bar' );
|
||||
update_sitemeta_cache( array( self::$site_id ) );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
get_site_meta( self::$site_id, 'foo', true );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
public function test_query_update_site_meta_cache_true() {
|
||||
global $wpdb;
|
||||
|
||||
if ( ! is_site_meta_supported() ) {
|
||||
$this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
|
||||
}
|
||||
@ -250,14 +246,12 @@ if ( is_multisite() ) :
|
||||
)
|
||||
);
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
get_site_meta( self::$site_id, 'foo', true );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
public function test_query_update_site_meta_cache_false() {
|
||||
global $wpdb;
|
||||
|
||||
if ( ! is_site_meta_supported() ) {
|
||||
$this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' );
|
||||
}
|
||||
@ -271,9 +265,9 @@ if ( is_multisite() ) :
|
||||
)
|
||||
);
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
get_site_meta( self::$site_id, 'foo', true );
|
||||
$this->assertSame( $num_queries + 1, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries + 1, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -428,8 +428,6 @@ if ( is_multisite() ) :
|
||||
* @ticket 41347
|
||||
*/
|
||||
public function test_wp_network_query_cache_with_different_fields_no_count() {
|
||||
global $wpdb;
|
||||
|
||||
$q = new WP_Network_Query();
|
||||
$query_1 = $q->query(
|
||||
array(
|
||||
@ -438,7 +436,7 @@ if ( is_multisite() ) :
|
||||
'order' => 'ASC',
|
||||
)
|
||||
);
|
||||
$number_of_queries = $wpdb->num_queries;
|
||||
$number_of_queries = get_num_queries();
|
||||
|
||||
$query_2 = $q->query(
|
||||
array(
|
||||
@ -448,15 +446,13 @@ if ( is_multisite() ) :
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertSame( $number_of_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $number_of_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 41347
|
||||
*/
|
||||
public function test_wp_network_query_cache_with_different_fields_active_count() {
|
||||
global $wpdb;
|
||||
|
||||
$q = new WP_Network_Query();
|
||||
|
||||
$query_1 = $q->query(
|
||||
@ -467,7 +463,7 @@ if ( is_multisite() ) :
|
||||
'count' => true,
|
||||
)
|
||||
);
|
||||
$number_of_queries = $wpdb->num_queries;
|
||||
$number_of_queries = get_num_queries();
|
||||
|
||||
$query_2 = $q->query(
|
||||
array(
|
||||
@ -477,15 +473,13 @@ if ( is_multisite() ) :
|
||||
'count' => true,
|
||||
)
|
||||
);
|
||||
$this->assertSame( $number_of_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $number_of_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 41347
|
||||
*/
|
||||
public function test_wp_network_query_cache_with_same_fields_different_count() {
|
||||
global $wpdb;
|
||||
|
||||
$q = new WP_Network_Query();
|
||||
|
||||
$query_1 = $q->query(
|
||||
@ -496,7 +490,7 @@ if ( is_multisite() ) :
|
||||
)
|
||||
);
|
||||
|
||||
$number_of_queries = $wpdb->num_queries;
|
||||
$number_of_queries = get_num_queries();
|
||||
|
||||
$query_2 = $q->query(
|
||||
array(
|
||||
@ -506,7 +500,7 @@ if ( is_multisite() ) :
|
||||
'count' => true,
|
||||
)
|
||||
);
|
||||
$this->assertSame( $number_of_queries + 1, $wpdb->num_queries );
|
||||
$this->assertSame( $number_of_queries + 1, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -568,11 +562,9 @@ if ( is_multisite() ) :
|
||||
* @ticket 47599
|
||||
*/
|
||||
public function test_networks_pre_query_filter_should_bypass_database_query() {
|
||||
global $wpdb;
|
||||
|
||||
add_filter( 'networks_pre_query', array( __CLASS__, 'filter_networks_pre_query' ), 10, 2 );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
$q = new WP_Network_Query();
|
||||
$results = $q->query( array() );
|
||||
@ -580,7 +572,7 @@ if ( is_multisite() ) :
|
||||
remove_filter( 'networks_pre_query', array( __CLASS__, 'filter_networks_pre_query' ), 10, 2 );
|
||||
|
||||
// Make sure no queries were executed.
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
|
||||
// We manually inserted a non-existing site and overrode the results with it.
|
||||
$this->assertSame( array( 555 ), $results );
|
||||
|
@ -779,7 +779,6 @@ if ( is_multisite() ) :
|
||||
* @ticket 41197
|
||||
*/
|
||||
public function test_wp_site_query_cache_with_different_fields_no_count() {
|
||||
global $wpdb;
|
||||
$q = new WP_Site_Query();
|
||||
$query_1 = $q->query(
|
||||
array(
|
||||
@ -789,7 +788,7 @@ if ( is_multisite() ) :
|
||||
'order' => 'ASC',
|
||||
)
|
||||
);
|
||||
$number_of_queries = $wpdb->num_queries;
|
||||
$number_of_queries = get_num_queries();
|
||||
|
||||
$query_2 = $q->query(
|
||||
array(
|
||||
@ -800,14 +799,13 @@ if ( is_multisite() ) :
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertSame( $number_of_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $number_of_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 41197
|
||||
*/
|
||||
public function test_wp_site_query_cache_with_different_fields_active_count() {
|
||||
global $wpdb;
|
||||
$q = new WP_Site_Query();
|
||||
|
||||
$query_1 = $q->query(
|
||||
@ -819,7 +817,7 @@ if ( is_multisite() ) :
|
||||
'count' => true,
|
||||
)
|
||||
);
|
||||
$number_of_queries = $wpdb->num_queries;
|
||||
$number_of_queries = get_num_queries();
|
||||
|
||||
$query_2 = $q->query(
|
||||
array(
|
||||
@ -830,14 +828,13 @@ if ( is_multisite() ) :
|
||||
'count' => true,
|
||||
)
|
||||
);
|
||||
$this->assertSame( $number_of_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $number_of_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 41197
|
||||
*/
|
||||
public function test_wp_site_query_cache_with_same_fields_different_count() {
|
||||
global $wpdb;
|
||||
$q = new WP_Site_Query();
|
||||
|
||||
$query_1 = $q->query(
|
||||
@ -860,7 +857,7 @@ if ( is_multisite() ) :
|
||||
'count' => true,
|
||||
)
|
||||
);
|
||||
$this->assertSame( $number_of_queries + 1, $wpdb->num_queries );
|
||||
$this->assertSame( $number_of_queries + 1, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1119,11 +1116,9 @@ if ( is_multisite() ) :
|
||||
* @ticket 47599
|
||||
*/
|
||||
public function test_sites_pre_query_filter_should_bypass_database_query() {
|
||||
global $wpdb;
|
||||
|
||||
add_filter( 'sites_pre_query', array( __CLASS__, 'filter_sites_pre_query' ), 10, 2 );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
$q = new WP_Site_Query();
|
||||
$results = $q->query( array() );
|
||||
@ -1131,7 +1126,7 @@ if ( is_multisite() ) :
|
||||
remove_filter( 'sites_pre_query', array( __CLASS__, 'filter_sites_pre_query' ), 10, 2 );
|
||||
|
||||
// Make sure no queries were executed.
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
|
||||
// We manually inserted a non-existing site and overrode the results with it.
|
||||
$this->assertSame( array( 555 ), $results );
|
||||
|
@ -28,7 +28,6 @@ class Tests_Option_UpdateOption extends WP_UnitTestCase {
|
||||
* @covers ::get_option
|
||||
*/
|
||||
public function test_should_set_autoload_yes_for_nonexistent_option_when_autoload_param_is_missing() {
|
||||
global $wpdb;
|
||||
$this->flush_cache();
|
||||
update_option( 'test_update_option_default', 'value' );
|
||||
$this->flush_cache();
|
||||
@ -36,9 +35,9 @@ class Tests_Option_UpdateOption extends WP_UnitTestCase {
|
||||
// Populate the alloptions cache, which includes autoload=yes options.
|
||||
wp_load_alloptions();
|
||||
|
||||
$before = $wpdb->num_queries;
|
||||
$before = get_num_queries();
|
||||
$value = get_option( 'test_update_option_default' );
|
||||
$after = $wpdb->num_queries;
|
||||
$after = get_num_queries();
|
||||
|
||||
$this->assertSame( $before, $after );
|
||||
$this->assertSame( $value, 'value' );
|
||||
@ -52,7 +51,6 @@ class Tests_Option_UpdateOption extends WP_UnitTestCase {
|
||||
* @covers ::get_option
|
||||
*/
|
||||
public function test_should_set_autoload_yes_for_nonexistent_option_when_autoload_param_is_yes() {
|
||||
global $wpdb;
|
||||
$this->flush_cache();
|
||||
update_option( 'test_update_option_default', 'value', 'yes' );
|
||||
$this->flush_cache();
|
||||
@ -60,9 +58,9 @@ class Tests_Option_UpdateOption extends WP_UnitTestCase {
|
||||
// Populate the alloptions cache, which includes autoload=yes options.
|
||||
wp_load_alloptions();
|
||||
|
||||
$before = $wpdb->num_queries;
|
||||
$before = get_num_queries();
|
||||
$value = get_option( 'test_update_option_default' );
|
||||
$after = $wpdb->num_queries;
|
||||
$after = get_num_queries();
|
||||
|
||||
$this->assertSame( $before, $after );
|
||||
$this->assertSame( $value, 'value' );
|
||||
@ -76,7 +74,6 @@ class Tests_Option_UpdateOption extends WP_UnitTestCase {
|
||||
* @covers ::get_option
|
||||
*/
|
||||
public function test_should_set_autoload_no_for_nonexistent_option_when_autoload_param_is_no() {
|
||||
global $wpdb;
|
||||
$this->flush_cache();
|
||||
update_option( 'test_update_option_default', 'value', 'no' );
|
||||
$this->flush_cache();
|
||||
@ -84,9 +81,9 @@ class Tests_Option_UpdateOption extends WP_UnitTestCase {
|
||||
// Populate the alloptions cache, which does not include autoload=no options.
|
||||
wp_load_alloptions();
|
||||
|
||||
$before = $wpdb->num_queries;
|
||||
$before = get_num_queries();
|
||||
$value = get_option( 'test_update_option_default' );
|
||||
$after = $wpdb->num_queries;
|
||||
$after = get_num_queries();
|
||||
|
||||
// Database has been hit.
|
||||
$this->assertSame( $before + 1, $after );
|
||||
@ -101,7 +98,6 @@ class Tests_Option_UpdateOption extends WP_UnitTestCase {
|
||||
* @covers ::get_option
|
||||
*/
|
||||
public function test_should_set_autoload_no_for_nonexistent_option_when_autoload_param_is_false() {
|
||||
global $wpdb;
|
||||
$this->flush_cache();
|
||||
update_option( 'test_update_option_default', 'value', false );
|
||||
$this->flush_cache();
|
||||
@ -109,9 +105,9 @@ class Tests_Option_UpdateOption extends WP_UnitTestCase {
|
||||
// Populate the alloptions cache, which does not include autoload=no options.
|
||||
wp_load_alloptions();
|
||||
|
||||
$before = $wpdb->num_queries;
|
||||
$before = get_num_queries();
|
||||
$value = get_option( 'test_update_option_default' );
|
||||
$after = $wpdb->num_queries;
|
||||
$after = get_num_queries();
|
||||
|
||||
// Database has been hit.
|
||||
$this->assertSame( $before + 1, $after );
|
||||
@ -126,7 +122,6 @@ class Tests_Option_UpdateOption extends WP_UnitTestCase {
|
||||
* @covers ::get_option
|
||||
*/
|
||||
public function test_autoload_should_be_updated_for_existing_option_when_value_is_changed() {
|
||||
global $wpdb;
|
||||
add_option( 'foo', 'bar', '', 'no' );
|
||||
$updated = update_option( 'foo', 'bar2', true );
|
||||
$this->assertTrue( $updated );
|
||||
@ -136,10 +131,10 @@ class Tests_Option_UpdateOption extends WP_UnitTestCase {
|
||||
// Populate the alloptions cache, which includes autoload=yes options.
|
||||
wp_load_alloptions();
|
||||
|
||||
$before = $wpdb->num_queries;
|
||||
$before = get_num_queries();
|
||||
$value = get_option( 'foo' );
|
||||
|
||||
$this->assertSame( $before, $wpdb->num_queries );
|
||||
$this->assertSame( $before, get_num_queries() );
|
||||
$this->assertSame( $value, 'bar2' );
|
||||
}
|
||||
|
||||
@ -151,7 +146,6 @@ class Tests_Option_UpdateOption extends WP_UnitTestCase {
|
||||
* @covers ::get_option
|
||||
*/
|
||||
public function test_autoload_should_not_be_updated_for_existing_option_when_value_is_unchanged() {
|
||||
global $wpdb;
|
||||
add_option( 'foo', 'bar', '', 'yes' );
|
||||
$updated = update_option( 'foo', 'bar', false );
|
||||
$this->assertFalse( $updated );
|
||||
@ -161,11 +155,11 @@ class Tests_Option_UpdateOption extends WP_UnitTestCase {
|
||||
// Populate the alloptions cache, which includes autoload=yes options.
|
||||
wp_load_alloptions();
|
||||
|
||||
$before = $wpdb->num_queries;
|
||||
$before = get_num_queries();
|
||||
$value = get_option( 'foo' );
|
||||
|
||||
// 'foo' should still be autoload=yes, so we should see no additional querios.
|
||||
$this->assertSame( $before, $wpdb->num_queries );
|
||||
$this->assertSame( $before, get_num_queries() );
|
||||
$this->assertSame( $value, 'bar' );
|
||||
}
|
||||
|
||||
@ -177,7 +171,6 @@ class Tests_Option_UpdateOption extends WP_UnitTestCase {
|
||||
* @covers ::get_option
|
||||
*/
|
||||
public function test_autoload_should_not_be_updated_for_existing_option_when_value_is_changed_but_no_value_of_autoload_is_provided() {
|
||||
global $wpdb;
|
||||
add_option( 'foo', 'bar', '', 'yes' );
|
||||
|
||||
// Don't pass a value for `$autoload`.
|
||||
@ -189,11 +182,11 @@ class Tests_Option_UpdateOption extends WP_UnitTestCase {
|
||||
// Populate the alloptions cache, which includes autoload=yes options.
|
||||
wp_load_alloptions();
|
||||
|
||||
$before = $wpdb->num_queries;
|
||||
$before = get_num_queries();
|
||||
$value = get_option( 'foo' );
|
||||
|
||||
// 'foo' should still be autoload=yes, so we should see no additional queries.
|
||||
$this->assertSame( $before, $wpdb->num_queries );
|
||||
$this->assertSame( $before, get_num_queries() );
|
||||
$this->assertSame( $value, 'bar2' );
|
||||
}
|
||||
|
||||
|
@ -34,10 +34,9 @@ class Tests_Option_wpLoadAlloptions extends WP_UnitTestCase {
|
||||
* @covers ::wp_load_alloptions
|
||||
*/
|
||||
public function test_if_alloptions_are_retrieved_from_cache() {
|
||||
global $wpdb;
|
||||
$before = $wpdb->num_queries;
|
||||
$before = get_num_queries();
|
||||
wp_load_alloptions();
|
||||
$after = $wpdb->num_queries;
|
||||
$after = get_num_queries();
|
||||
|
||||
// Database has not been hit.
|
||||
$this->assertSame( $before, $after );
|
||||
@ -49,14 +48,12 @@ class Tests_Option_wpLoadAlloptions extends WP_UnitTestCase {
|
||||
* @covers ::wp_load_alloptions
|
||||
*/
|
||||
public function test_if_alloptions_are_retrieved_from_database() {
|
||||
global $wpdb;
|
||||
|
||||
// Delete the existing cache first.
|
||||
wp_cache_delete( 'alloptions', 'options' );
|
||||
|
||||
$before = $wpdb->num_queries;
|
||||
$before = get_num_queries();
|
||||
wp_load_alloptions();
|
||||
$after = $wpdb->num_queries;
|
||||
$after = get_num_queries();
|
||||
|
||||
// Database has been hit.
|
||||
$this->assertSame( $before + 1, $after );
|
||||
|
@ -260,8 +260,6 @@ class Tests_Post_GetPageByPath extends WP_UnitTestCase {
|
||||
* @ticket 36711
|
||||
*/
|
||||
public function test_should_hit_cache() {
|
||||
global $wpdb;
|
||||
|
||||
$page = self::factory()->post->create(
|
||||
array(
|
||||
'post_type' => 'page',
|
||||
@ -273,35 +271,33 @@ class Tests_Post_GetPageByPath extends WP_UnitTestCase {
|
||||
$found = get_page_by_path( 'foo' );
|
||||
$this->assertSame( $page, $found->ID );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
$found = get_page_by_path( 'foo' );
|
||||
$this->assertSame( $page, $found->ID );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 36711
|
||||
*/
|
||||
public function test_bad_path_should_be_cached() {
|
||||
global $wpdb;
|
||||
|
||||
// Prime cache.
|
||||
$found = get_page_by_path( 'foo' );
|
||||
$this->assertNull( $found );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
$found = get_page_by_path( 'foo' );
|
||||
$this->assertNull( $found );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 36711
|
||||
*/
|
||||
public function test_bad_path_served_from_cache_should_not_fall_back_on_current_post() {
|
||||
global $wpdb, $post;
|
||||
global $post;
|
||||
|
||||
// Fake the global.
|
||||
$post = self::factory()->post->create_and_get();
|
||||
@ -310,11 +306,11 @@ class Tests_Post_GetPageByPath extends WP_UnitTestCase {
|
||||
$found = get_page_by_path( 'foo' );
|
||||
$this->assertNull( $found );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
$found = get_page_by_path( 'foo' );
|
||||
$this->assertNull( $found );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
|
||||
unset( $post );
|
||||
}
|
||||
@ -323,8 +319,6 @@ class Tests_Post_GetPageByPath extends WP_UnitTestCase {
|
||||
* @ticket 36711
|
||||
*/
|
||||
public function test_cache_should_not_match_post_in_different_post_type_with_same_path() {
|
||||
global $wpdb;
|
||||
|
||||
register_post_type( 'wptests_pt' );
|
||||
|
||||
$p1 = self::factory()->post->create(
|
||||
@ -345,20 +339,18 @@ class Tests_Post_GetPageByPath extends WP_UnitTestCase {
|
||||
$found = get_page_by_path( 'foo' );
|
||||
$this->assertSame( $p1, $found->ID );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
$found = get_page_by_path( 'foo', OBJECT, 'wptests_pt' );
|
||||
$this->assertSame( $p2, $found->ID );
|
||||
$num_queries++;
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 36711
|
||||
*/
|
||||
public function test_cache_should_be_invalidated_when_post_name_is_edited() {
|
||||
global $wpdb;
|
||||
|
||||
$page = self::factory()->post->create(
|
||||
array(
|
||||
'post_type' => 'page',
|
||||
@ -377,12 +369,12 @@ class Tests_Post_GetPageByPath extends WP_UnitTestCase {
|
||||
)
|
||||
);
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
$found = get_page_by_path( 'bar' );
|
||||
$this->assertSame( $page, $found->ID );
|
||||
$num_queries++;
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -10,8 +10,6 @@ class Tests_Post_GetPages extends WP_UnitTestCase {
|
||||
* @ticket 23167
|
||||
*/
|
||||
public function test_get_pages_cache() {
|
||||
global $wpdb;
|
||||
|
||||
self::factory()->post->create_many( 3, array( 'post_type' => 'page' ) );
|
||||
wp_cache_delete( 'last_changed', 'posts' );
|
||||
$this->assertFalse( wp_cache_get( 'last_changed', 'posts' ) );
|
||||
@ -20,7 +18,7 @@ class Tests_Post_GetPages extends WP_UnitTestCase {
|
||||
$this->assertCount( 3, $pages );
|
||||
$time1 = wp_cache_get( 'last_changed', 'posts' );
|
||||
$this->assertNotEmpty( $time1 );
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
foreach ( $pages as $page ) {
|
||||
$this->assertInstanceOf( 'WP_Post', $page );
|
||||
}
|
||||
@ -29,7 +27,7 @@ class Tests_Post_GetPages extends WP_UnitTestCase {
|
||||
$pages = get_pages();
|
||||
$this->assertCount( 3, $pages );
|
||||
$this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
foreach ( $pages as $page ) {
|
||||
$this->assertInstanceOf( 'WP_Post', $page );
|
||||
}
|
||||
@ -39,18 +37,18 @@ class Tests_Post_GetPages extends WP_UnitTestCase {
|
||||
$pages = get_pages( array( 'number' => 2 ) );
|
||||
$this->assertCount( 2, $pages );
|
||||
$this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
|
||||
$this->assertSame( $num_queries + 1, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries + 1, get_num_queries() );
|
||||
foreach ( $pages as $page ) {
|
||||
$this->assertInstanceOf( 'WP_Post', $page );
|
||||
}
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
// Again. num_queries and last_changed should remain the same.
|
||||
$pages = get_pages( array( 'number' => 2 ) );
|
||||
$this->assertCount( 2, $pages );
|
||||
$this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
foreach ( $pages as $page ) {
|
||||
$this->assertInstanceOf( 'WP_Post', $page );
|
||||
}
|
||||
@ -59,7 +57,7 @@ class Tests_Post_GetPages extends WP_UnitTestCase {
|
||||
$pages = get_pages();
|
||||
$this->assertCount( 3, $pages );
|
||||
$this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
foreach ( $pages as $page ) {
|
||||
$this->assertInstanceOf( 'WP_Post', $page );
|
||||
}
|
||||
@ -68,13 +66,13 @@ class Tests_Post_GetPages extends WP_UnitTestCase {
|
||||
clean_post_cache( $pages[0]->ID );
|
||||
$this->assertNotEquals( $time1, $time2 = wp_cache_get( 'last_changed', 'posts' ) );
|
||||
get_post( $pages[0]->ID );
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
// last_changed bumped so num_queries should increment.
|
||||
$pages = get_pages( array( 'number' => 2 ) );
|
||||
$this->assertCount( 2, $pages );
|
||||
$this->assertSame( $time2, wp_cache_get( 'last_changed', 'posts' ) );
|
||||
$this->assertSame( $num_queries + 1, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries + 1, get_num_queries() );
|
||||
foreach ( $pages as $page ) {
|
||||
$this->assertInstanceOf( 'WP_Post', $page );
|
||||
}
|
||||
@ -87,14 +85,14 @@ class Tests_Post_GetPages extends WP_UnitTestCase {
|
||||
$new_changed_float = $this->_microtime_to_float( wp_cache_get( 'last_changed', 'posts' ) );
|
||||
$this->assertGreaterThan( $old_changed_float, $new_changed_float );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
$last_changed = wp_cache_get( 'last_changed', 'posts' );
|
||||
|
||||
// num_queries should bump after wp_delete_post() bumps last_changed.
|
||||
$pages = get_pages();
|
||||
$this->assertCount( 2, $pages );
|
||||
$this->assertSame( $last_changed, wp_cache_get( 'last_changed', 'posts' ) );
|
||||
$this->assertSame( $num_queries + 1, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries + 1, get_num_queries() );
|
||||
foreach ( $pages as $page ) {
|
||||
$this->assertInstanceOf( 'WP_Post', $page );
|
||||
}
|
||||
@ -104,22 +102,20 @@ class Tests_Post_GetPages extends WP_UnitTestCase {
|
||||
* @ticket 43514
|
||||
*/
|
||||
public function test_get_pages_cache_empty() {
|
||||
global $wpdb;
|
||||
|
||||
wp_cache_delete( 'last_changed', 'posts' );
|
||||
$this->assertFalse( wp_cache_get( 'last_changed', 'posts' ) );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
$pages = get_pages(); // Database gets queried.
|
||||
|
||||
$this->assertSame( $num_queries + 1, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries + 1, get_num_queries() );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
$pages = get_pages(); // Database should not get queried.
|
||||
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -121,8 +121,6 @@ class Tests_Post_GetPostClass extends WP_UnitTestCase {
|
||||
* @group cache
|
||||
*/
|
||||
public function test_taxonomy_classes_hit_cache() {
|
||||
global $wpdb;
|
||||
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
wp_set_post_terms( $this->post_id, array( 'foo', 'bar' ), 'wptests_tax' );
|
||||
wp_set_post_terms( $this->post_id, array( 'footag', 'bartag' ), 'post_tag' );
|
||||
@ -131,10 +129,10 @@ class Tests_Post_GetPostClass extends WP_UnitTestCase {
|
||||
update_object_term_cache( $this->post_id, 'post' );
|
||||
update_meta_cache( 'post', $this->post_id );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
$found = get_post_class( '', $this->post_id );
|
||||
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
}
|
||||
|
@ -555,11 +555,9 @@ class Tests_Post_Query extends WP_UnitTestCase {
|
||||
* @ticket 36687
|
||||
*/
|
||||
public function test_posts_pre_query_filter_should_bypass_database_query() {
|
||||
global $wpdb;
|
||||
|
||||
add_filter( 'posts_pre_query', array( __CLASS__, 'filter_posts_pre_query' ) );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
$q = new WP_Query(
|
||||
array(
|
||||
'fields' => 'ids',
|
||||
@ -569,7 +567,7 @@ class Tests_Post_Query extends WP_UnitTestCase {
|
||||
|
||||
remove_filter( 'posts_pre_query', array( __CLASS__, 'filter_posts_pre_query' ) );
|
||||
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
$this->assertSame( array( 12345 ), $q->posts );
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,6 @@ class Tests_Query_CommentFeed extends WP_UnitTestCase {
|
||||
* @ticket 36904
|
||||
*/
|
||||
public function test_archive_comment_feed() {
|
||||
global $wpdb;
|
||||
add_filter( 'split_the_query', '__return_false' );
|
||||
$q1 = new WP_Query();
|
||||
$args = array(
|
||||
@ -42,12 +41,12 @@ class Tests_Query_CommentFeed extends WP_UnitTestCase {
|
||||
'cache_results' => false,
|
||||
);
|
||||
$q1->query( $args );
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
$q2 = new WP_Query();
|
||||
$q2->query( $args );
|
||||
$this->assertTrue( $q2->is_comment_feed() );
|
||||
$this->assertFalse( $q2->is_singular() );
|
||||
$this->assertSame( $num_queries + 1, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries + 1, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -87,7 +86,6 @@ class Tests_Query_CommentFeed extends WP_UnitTestCase {
|
||||
* @ticket 36904
|
||||
*/
|
||||
public function test_single_comment_feed() {
|
||||
global $wpdb;
|
||||
$post = get_post( self::$post_ids[0] );
|
||||
|
||||
$q1 = new WP_Query();
|
||||
@ -103,12 +101,12 @@ class Tests_Query_CommentFeed extends WP_UnitTestCase {
|
||||
);
|
||||
|
||||
$q1->query( $args );
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
$q2 = new WP_Query();
|
||||
$q2->query( $args );
|
||||
|
||||
$this->assertTrue( $q2->is_comment_feed() );
|
||||
$this->assertTrue( $q2->is_singular() );
|
||||
$this->assertSame( $num_queries + 1, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries + 1, get_num_queries() );
|
||||
}
|
||||
}
|
||||
|
@ -1336,8 +1336,6 @@ class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
* @ticket 38504
|
||||
*/
|
||||
public function test_object_term_queries_are_cached() {
|
||||
global $wpdb;
|
||||
|
||||
$tags = self::factory()->tag->create_many( 2 );
|
||||
$p = self::factory()->post->create();
|
||||
wp_set_object_terms( $p, $tags[0], 'post_tag' );
|
||||
@ -1349,7 +1347,7 @@ class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
|
||||
unset( $request, $response );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
$request = new WP_REST_Request( 'GET', '/wp/v2/tags' );
|
||||
$request->set_param( 'post', $p );
|
||||
@ -1357,7 +1355,7 @@ class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase {
|
||||
$found_2 = wp_list_pluck( $response->data, 'id' );
|
||||
|
||||
$this->assertSameSets( $found_1, $found_2 );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -101,8 +101,6 @@ class Tests_Term_Cache extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_get_term_should_update_term_cache_when_passed_an_object() {
|
||||
global $wpdb;
|
||||
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
$term = self::factory()->term->create(
|
||||
array(
|
||||
@ -116,7 +114,7 @@ class Tests_Term_Cache extends WP_UnitTestCase {
|
||||
// Affirm that the cache is empty.
|
||||
$this->assertEmpty( wp_cache_get( $term, 'terms' ) );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
// get_term() will only be update the cache if the 'filter' prop is unset.
|
||||
unset( $term_object->filter );
|
||||
@ -124,13 +122,11 @@ class Tests_Term_Cache extends WP_UnitTestCase {
|
||||
$term_object_2 = get_term( $term_object, 'wptests_tax' );
|
||||
|
||||
// No new queries should have fired.
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
$this->assertSame( $term_object, $term_object_2 );
|
||||
}
|
||||
|
||||
public function test_get_term_should_update_term_cache_when_passed_a_valid_term_identifier() {
|
||||
global $wpdb;
|
||||
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
$term = self::factory()->term->create(
|
||||
array(
|
||||
@ -143,23 +139,21 @@ class Tests_Term_Cache extends WP_UnitTestCase {
|
||||
// Affirm that the cache is empty.
|
||||
$this->assertEmpty( wp_cache_get( $term, 'terms' ) );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
// Prime cache.
|
||||
$term_object = get_term( $term, 'wptests_tax' );
|
||||
$this->assertNotEmpty( wp_cache_get( $term, 'terms' ) );
|
||||
$this->assertSame( $num_queries + 1, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries + 1, get_num_queries() );
|
||||
|
||||
$term_object_2 = get_term( $term, 'wptests_tax' );
|
||||
|
||||
// No new queries should have fired.
|
||||
$this->assertSame( $num_queries + 1, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries + 1, get_num_queries() );
|
||||
$this->assertEquals( $term_object, $term_object_2 );
|
||||
}
|
||||
|
||||
public function test_get_term_by_should_update_term_cache_when_passed_a_valid_term_identifier() {
|
||||
global $wpdb;
|
||||
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
$term = self::factory()->term->create(
|
||||
array(
|
||||
@ -172,17 +166,17 @@ class Tests_Term_Cache extends WP_UnitTestCase {
|
||||
// Affirm that the cache is empty.
|
||||
$this->assertEmpty( wp_cache_get( $term, 'terms' ) );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
// Prime cache.
|
||||
$term_object = get_term_by( 'id', $term, 'wptests_tax' );
|
||||
$this->assertNotEmpty( wp_cache_get( $term, 'terms' ) );
|
||||
$this->assertSame( $num_queries + 1, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries + 1, get_num_queries() );
|
||||
|
||||
$term_object_2 = get_term( $term, 'wptests_tax' );
|
||||
|
||||
// No new queries should have fired.
|
||||
$this->assertSame( $num_queries + 1, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries + 1, get_num_queries() );
|
||||
$this->assertEquals( $term_object, $term_object_2 );
|
||||
}
|
||||
|
||||
@ -190,8 +184,6 @@ class Tests_Term_Cache extends WP_UnitTestCase {
|
||||
* @ticket 30749
|
||||
*/
|
||||
public function test_get_terms_should_update_cache_for_located_terms() {
|
||||
global $wpdb;
|
||||
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
|
||||
$terms = self::factory()->term->create_many(
|
||||
@ -208,13 +200,13 @@ class Tests_Term_Cache extends WP_UnitTestCase {
|
||||
)
|
||||
);
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
foreach ( $terms as $term_id ) {
|
||||
get_term( $term_id, 'wptests_tax' );
|
||||
}
|
||||
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
|
||||
_unregister_taxonomy( 'wptests_tax' );
|
||||
}
|
||||
@ -242,8 +234,6 @@ class Tests_Term_Cache extends WP_UnitTestCase {
|
||||
* @ticket 21760
|
||||
*/
|
||||
public function test_get_term_by_slug_cache() {
|
||||
global $wpdb;
|
||||
|
||||
$term_id = self::factory()->term->create(
|
||||
array(
|
||||
'slug' => 'burrito',
|
||||
@ -253,28 +243,26 @@ class Tests_Term_Cache extends WP_UnitTestCase {
|
||||
);
|
||||
|
||||
clean_term_cache( $term_id, 'post_tag' );
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
$term = get_term_by( 'slug', 'burrito', 'post_tag' );
|
||||
$num_queries = $num_queries + 2;
|
||||
$this->assertSame( 'Taco', $term->name );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
|
||||
// This should now hit cache.
|
||||
$term = get_term_by( 'slug', 'burrito', 'post_tag' );
|
||||
$this->assertSame( 'Taco', $term->name );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
|
||||
$this->assertEquals( get_term( $term_id, 'post_tag' ), $term );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 21760
|
||||
*/
|
||||
public function test_get_term_by_slug_cache_update() {
|
||||
global $wpdb;
|
||||
|
||||
$term_id = self::factory()->term->create(
|
||||
array(
|
||||
'slug' => 'burrito',
|
||||
@ -284,35 +272,33 @@ class Tests_Term_Cache extends WP_UnitTestCase {
|
||||
);
|
||||
|
||||
clean_term_cache( $term_id, 'post_tag' );
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
$term = get_term_by( 'slug', 'burrito', 'post_tag' );
|
||||
$num_queries = $num_queries + 2;
|
||||
$this->assertSame( 'Taco', $term->name );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
|
||||
// This should now hit cache.
|
||||
$term = get_term_by( 'slug', 'burrito', 'post_tag' );
|
||||
$this->assertSame( 'Taco', $term->name );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
|
||||
// Update the tag which invalidates the cache.
|
||||
wp_update_term( $term_id, 'post_tag', array( 'name' => 'No Taco' ) );
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
// This should not hit cache.
|
||||
$term = get_term_by( 'slug', 'burrito', 'post_tag' );
|
||||
$num_queries = $num_queries + 2;
|
||||
$this->assertSame( 'No Taco', $term->name );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 21760
|
||||
*/
|
||||
public function test_get_term_by_name_cache() {
|
||||
global $wpdb;
|
||||
|
||||
$term_id = self::factory()->term->create(
|
||||
array(
|
||||
'name' => 'Burrito',
|
||||
@ -322,26 +308,24 @@ class Tests_Term_Cache extends WP_UnitTestCase {
|
||||
);
|
||||
|
||||
clean_term_cache( $term_id, 'post_tag' );
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
get_term_by( 'name', 'Burrito', 'post_tag' );
|
||||
$num_queries = $num_queries + 2;
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
|
||||
// This should now hit cache.
|
||||
$term = get_term_by( 'name', 'Burrito', 'post_tag' );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
|
||||
$this->assertEquals( get_term( $term_id, 'post_tag' ), $term );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 21760
|
||||
*/
|
||||
public function test_get_term_by_name_cache_update() {
|
||||
global $wpdb;
|
||||
|
||||
$term_id = self::factory()->term->create(
|
||||
array(
|
||||
'name' => 'Burrito',
|
||||
@ -351,32 +335,30 @@ class Tests_Term_Cache extends WP_UnitTestCase {
|
||||
);
|
||||
|
||||
clean_term_cache( $term_id, 'post_tag' );
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
get_term_by( 'name', 'Burrito', 'post_tag' );
|
||||
$num_queries = $num_queries + 2;
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
|
||||
// This should now hit cache.
|
||||
get_term_by( 'name', 'Burrito', 'post_tag' );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
|
||||
// Update the tag which invalidates the cache.
|
||||
wp_update_term( $term_id, 'post_tag', array( 'slug' => 'taco' ) );
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
// This should not hit cache.
|
||||
get_term_by( 'name', 'burrito', 'post_tag' );
|
||||
$num_queries = $num_queries + 2;
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 21760
|
||||
*/
|
||||
public function test_invalidating_term_caches_should_fail_when_invalidation_is_suspended() {
|
||||
global $wpdb;
|
||||
|
||||
$term_id = self::factory()->term->create(
|
||||
array(
|
||||
'name' => 'Burrito',
|
||||
@ -385,7 +367,7 @@ class Tests_Term_Cache extends WP_UnitTestCase {
|
||||
);
|
||||
|
||||
clean_term_cache( $term_id, 'post_tag' );
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
$last_changed = wp_cache_get( 'last_changed', 'terms' );
|
||||
|
||||
$term1 = get_term_by( 'name', 'Burrito', 'post_tag' );
|
||||
@ -393,18 +375,18 @@ class Tests_Term_Cache extends WP_UnitTestCase {
|
||||
|
||||
// Verify the term is cached.
|
||||
$term2 = get_term_by( 'name', 'Burrito', 'post_tag' );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
$this->assertEquals( $term1, $term2 );
|
||||
|
||||
$suspend = wp_suspend_cache_invalidation();
|
||||
|
||||
// Update the tag.
|
||||
wp_update_term( $term_id, 'post_tag', array( 'name' => 'Taco' ) );
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
// Verify that the cached term still matches the initial cached term.
|
||||
$term3 = get_term_by( 'name', 'Burrito', 'post_tag' );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
$this->assertEquals( $term1, $term3 );
|
||||
|
||||
// Verify that last changed has not been updated as part of an invalidation routine.
|
||||
@ -418,8 +400,6 @@ class Tests_Term_Cache extends WP_UnitTestCase {
|
||||
* @ticket 21760
|
||||
*/
|
||||
public function test_get_term_by_does_not_prime_term_meta_cache() {
|
||||
global $wpdb;
|
||||
|
||||
$term_id = self::factory()->term->create(
|
||||
array(
|
||||
'name' => 'Burrito',
|
||||
@ -429,18 +409,18 @@ class Tests_Term_Cache extends WP_UnitTestCase {
|
||||
add_term_meta( $term_id, 'foo', 'bar' );
|
||||
|
||||
clean_term_cache( $term_id, 'post_tag' );
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
$term = get_term_by( 'name', 'Burrito', 'post_tag' );
|
||||
$num_queries = $num_queries + 2;
|
||||
$this->assertInstanceOf( 'WP_Term', $term );
|
||||
$this->assertSame( $term_id, $term->term_id );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
|
||||
$term_meta = get_term_meta( $term_id, 'foo', true );
|
||||
$num_queries++;
|
||||
$this->assertSame( $term_meta, 'bar' );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -60,17 +60,15 @@ class Tests_Term_GetTerm extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_passing_term_object_should_skip_database_query_when_filter_property_is_empty() {
|
||||
global $wpdb;
|
||||
|
||||
$term = self::factory()->term->create_and_get( array( 'taxonomy' => 'wptests_tax' ) );
|
||||
clean_term_cache( $term->term_id, 'wptests_tax' );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
unset( $term->filter );
|
||||
$term_a = get_term( $term, 'wptests_tax' );
|
||||
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
public function test_passing_term_string_that_casts_to_int_0_should_return_null() {
|
||||
@ -82,18 +80,16 @@ class Tests_Term_GetTerm extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_cache_should_be_populated_by_successful_fetch() {
|
||||
global $wpdb;
|
||||
|
||||
$t = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax' ) );
|
||||
clean_term_cache( $t, 'wptests_tax' );
|
||||
|
||||
// Prime cache.
|
||||
$term_a = get_term( $t, 'wptests_tax' );
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
// Second call shouldn't require a database query.
|
||||
$term_b = get_term( $t, 'wptests_tax' );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
$this->assertEquals( $term_a, $term_b );
|
||||
}
|
||||
|
||||
@ -196,19 +192,17 @@ class Tests_Term_GetTerm extends WP_UnitTestCase {
|
||||
* @ticket 34533
|
||||
*/
|
||||
public function test_shared_term_in_cache_should_be_ignored_when_specifying_a_different_taxonomy() {
|
||||
global $wpdb;
|
||||
|
||||
$terms = $this->generate_shared_terms();
|
||||
|
||||
// Prime cache for 'wptests_tax'.
|
||||
get_term( $terms[0]['term_id'], 'wptests_tax' );
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
// Database should be hit again.
|
||||
$found = get_term( $terms[1]['term_id'], 'wptests_tax_2' );
|
||||
$num_queries++;
|
||||
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
$this->assertInstanceOf( 'WP_Term', $found );
|
||||
$this->assertSame( 'wptests_tax_2', $found->taxonomy );
|
||||
}
|
||||
|
@ -111,8 +111,6 @@ class Tests_Term_GetTermBy extends WP_UnitTestCase {
|
||||
* @ticket 14162
|
||||
*/
|
||||
public function test_should_prime_term_cache() {
|
||||
global $wpdb;
|
||||
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
$t = self::factory()->term->create(
|
||||
array(
|
||||
@ -123,18 +121,18 @@ class Tests_Term_GetTermBy extends WP_UnitTestCase {
|
||||
|
||||
clean_term_cache( $t, 'wptests_tax' );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
$found = get_term_by( 'slug', 'foo', 'wptests_tax' );
|
||||
$num_queries = $num_queries + 2;
|
||||
|
||||
$this->assertInstanceOf( 'WP_Term', $found );
|
||||
$this->assertSame( $t, $found->term_id );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
|
||||
// Calls to `get_term()` should now hit cache.
|
||||
$found2 = get_term( $t );
|
||||
$this->assertSame( $t, $found->term_id );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -134,26 +134,24 @@ class Tests_Term_getTerms extends WP_UnitTestCase {
|
||||
* @ticket 23326
|
||||
*/
|
||||
public function test_get_terms_cache() {
|
||||
global $wpdb;
|
||||
|
||||
$this->set_up_three_posts_and_tags();
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
// last_changed and num_queries should bump.
|
||||
$terms = get_terms( 'post_tag', array( 'update_term_meta_cache' => false ) );
|
||||
$this->assertCount( 3, $terms );
|
||||
$time1 = wp_cache_get( 'last_changed', 'terms' );
|
||||
$this->assertNotEmpty( $time1 );
|
||||
$this->assertSame( $num_queries + 2, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries + 2, get_num_queries() );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
// Again. last_changed and num_queries should remain the same.
|
||||
$terms = get_terms( 'post_tag', array( 'update_term_meta_cache' => false ) );
|
||||
$this->assertCount( 3, $terms );
|
||||
$this->assertSame( $time1, wp_cache_get( 'last_changed', 'terms' ) );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -167,21 +165,21 @@ class Tests_Term_getTerms extends WP_UnitTestCase {
|
||||
// Prime cache.
|
||||
$terms = get_terms( 'post_tag' );
|
||||
$time1 = wp_cache_get( 'last_changed', 'terms' );
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
// num_queries should bump, last_changed should remain the same.
|
||||
$terms = get_terms( 'post_tag', array( 'number' => 2 ) );
|
||||
$this->assertCount( 2, $terms );
|
||||
$this->assertSame( $time1, wp_cache_get( 'last_changed', 'terms' ) );
|
||||
$this->assertSame( $num_queries + 1, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries + 1, get_num_queries() );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
// Again. last_changed and num_queries should remain the same.
|
||||
$terms = get_terms( 'post_tag', array( 'number' => 2 ) );
|
||||
$this->assertCount( 2, $terms );
|
||||
$this->assertSame( $time1, wp_cache_get( 'last_changed', 'terms' ) );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -195,12 +193,12 @@ class Tests_Term_getTerms extends WP_UnitTestCase {
|
||||
// Prime cache.
|
||||
$terms = get_terms( 'post_tag' );
|
||||
$time1 = wp_cache_get( 'last_changed', 'terms' );
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
// Force last_changed to bump.
|
||||
wp_delete_term( $terms[0]->term_id, 'post_tag' );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
$time2 = wp_cache_get( 'last_changed', 'terms' );
|
||||
$this->assertNotEquals( $time1, $time2 );
|
||||
|
||||
@ -208,15 +206,15 @@ class Tests_Term_getTerms extends WP_UnitTestCase {
|
||||
$terms = get_terms( 'post_tag' );
|
||||
$this->assertCount( 2, $terms );
|
||||
$this->assertSame( $time2, wp_cache_get( 'last_changed', 'terms' ) );
|
||||
$this->assertSame( $num_queries + 1, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries + 1, get_num_queries() );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
// Again. last_changed and num_queries should remain the same.
|
||||
$terms = get_terms( 'post_tag' );
|
||||
$this->assertCount( 2, $terms );
|
||||
$this->assertSame( $time2, wp_cache_get( 'last_changed', 'terms' ) );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
|
||||
// @todo Repeat with term insert and update.
|
||||
}
|
||||
@ -848,13 +846,11 @@ class Tests_Term_getTerms extends WP_UnitTestCase {
|
||||
* @ticket 31118
|
||||
*/
|
||||
public function test_child_of_should_skip_query_when_specified_parent_is_not_found_in_hierarchy_cache() {
|
||||
global $wpdb;
|
||||
|
||||
register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) );
|
||||
|
||||
$terms = self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax' ) );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
$found = get_terms(
|
||||
'wptests_tax',
|
||||
@ -865,7 +861,7 @@ class Tests_Term_getTerms extends WP_UnitTestCase {
|
||||
);
|
||||
|
||||
$this->assertEmpty( $found );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2473,13 +2469,11 @@ class Tests_Term_getTerms extends WP_UnitTestCase {
|
||||
* @ticket 31118
|
||||
*/
|
||||
public function test_parent_should_skip_query_when_specified_parent_is_not_found_in_hierarchy_cache() {
|
||||
global $wpdb;
|
||||
|
||||
register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) );
|
||||
|
||||
$terms = self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax' ) );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
$found = get_terms(
|
||||
'wptests_tax',
|
||||
@ -2490,7 +2484,7 @@ class Tests_Term_getTerms extends WP_UnitTestCase {
|
||||
);
|
||||
|
||||
$this->assertEmpty( $found );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2773,13 +2767,13 @@ class Tests_Term_getTerms extends WP_UnitTestCase {
|
||||
)
|
||||
);
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
foreach ( $terms as $t ) {
|
||||
$this->assertSame( 'bar', get_term_meta( $t, 'foo', true ) );
|
||||
}
|
||||
|
||||
$this->assertSame( $num_queries + 1, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries + 1, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2803,13 +2797,13 @@ class Tests_Term_getTerms extends WP_UnitTestCase {
|
||||
)
|
||||
);
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
foreach ( $terms as $t ) {
|
||||
$this->assertSame( 'bar', get_term_meta( $t, 'foo', true ) );
|
||||
}
|
||||
|
||||
$this->assertSame( $num_queries + 3, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries + 3, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2908,7 +2902,7 @@ class Tests_Term_getTerms extends WP_UnitTestCase {
|
||||
)
|
||||
);
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
$found = get_terms(
|
||||
'wptests_tax',
|
||||
@ -2918,7 +2912,7 @@ class Tests_Term_getTerms extends WP_UnitTestCase {
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
|
||||
$this->assertNotEmpty( $found );
|
||||
|
||||
@ -2931,8 +2925,6 @@ class Tests_Term_getTerms extends WP_UnitTestCase {
|
||||
* @ticket 14162
|
||||
*/
|
||||
public function test_should_prime_individual_term_cache_when_fields_is_all() {
|
||||
global $wpdb;
|
||||
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
$terms = self::factory()->term->create_many( 2, array( 'taxonomy' => 'wptests_tax' ) );
|
||||
|
||||
@ -2944,9 +2936,9 @@ class Tests_Term_getTerms extends WP_UnitTestCase {
|
||||
)
|
||||
);
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
$term0 = get_term( $terms[0] );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
|
||||
}
|
||||
|
||||
|
@ -197,8 +197,6 @@ class Tests_Term_GetTheTerms extends WP_UnitTestCase {
|
||||
* @ticket 36814
|
||||
*/
|
||||
public function test_uncached_terms_should_be_primed_with_a_single_query() {
|
||||
global $wpdb;
|
||||
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
|
||||
$terms = self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax' ) );
|
||||
@ -210,13 +208,13 @@ class Tests_Term_GetTheTerms extends WP_UnitTestCase {
|
||||
// Clean cache for two of the terms.
|
||||
clean_term_cache( array( $terms[0], $terms[1] ), 'wptests_tax', false );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
$found = get_the_terms( self::$post_ids[0], 'wptests_tax' );
|
||||
|
||||
$this->assertSameSets( $terms, wp_list_pluck( $found, 'term_id' ) );
|
||||
|
||||
$num_queries++;
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
|
||||
}
|
||||
|
||||
|
@ -135,46 +135,42 @@ class Tests_IsObjectInTerm extends WP_UnitTestCase {
|
||||
* @ticket 32044
|
||||
*/
|
||||
public function test_should_populate_and_hit_relationships_cache() {
|
||||
global $wpdb;
|
||||
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
$terms = self::factory()->term->create_many( 2, array( 'taxonomy' => 'wptests_tax' ) );
|
||||
|
||||
$o = 12345;
|
||||
wp_set_object_terms( $o, $terms[0], 'wptests_tax' );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
$this->assertTrue( is_object_in_term( $o, 'wptests_tax', $terms[0] ) );
|
||||
$num_queries = $num_queries + 2;
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
|
||||
$this->assertFalse( is_object_in_term( $o, 'wptests_tax', $terms[1] ) );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 32044
|
||||
*/
|
||||
public function test_should_not_be_fooled_by_a_stale_relationship_cache() {
|
||||
global $wpdb;
|
||||
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
$terms = self::factory()->term->create_many( 2, array( 'taxonomy' => 'wptests_tax' ) );
|
||||
|
||||
$o = 12345;
|
||||
wp_set_object_terms( $o, $terms[0], 'wptests_tax' );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
$this->assertTrue( is_object_in_term( $o, 'wptests_tax', $terms[0] ) );
|
||||
$num_queries = $num_queries + 2;
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
|
||||
wp_set_object_terms( $o, $terms[1], 'wptests_tax' );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
$this->assertTrue( is_object_in_term( $o, 'wptests_tax', $terms[1] ) );
|
||||
$num_queries = $num_queries + 2;
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -114,8 +114,6 @@ class Tests_Term_Meta extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
public function test_term_meta_should_be_lazy_loaded_for_all_terms_in_wp_query_loop() {
|
||||
global $wpdb;
|
||||
|
||||
$p = self::factory()->post->create( array( 'post_status' => 'publish' ) );
|
||||
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
@ -139,20 +137,20 @@ class Tests_Term_Meta extends WP_UnitTestCase {
|
||||
the_post();
|
||||
|
||||
// First request will hit the database.
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
$this->assertSame( 'bar', get_term_meta( $terms[0], 'foo', true ) );
|
||||
$num_queries++;
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
|
||||
// Second and third requests should be in cache.
|
||||
$this->assertSame( 'bar', get_term_meta( $terms[1], 'foo', true ) );
|
||||
$this->assertSame( 'bar', get_term_meta( $terms[2], 'foo', true ) );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
|
||||
// Querying a term not primed should result in a hit.
|
||||
$num_queries++;
|
||||
$this->assertSame( 'bar', get_term_meta( $orphan_term, 'foo', true ) );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -186,8 +184,6 @@ class Tests_Term_Meta extends WP_UnitTestCase {
|
||||
* @ticket 36593
|
||||
*/
|
||||
public function test_lazy_load_term_meta_false() {
|
||||
global $wpdb;
|
||||
|
||||
$p = self::factory()->post->create( array( 'post_status' => 'publish' ) );
|
||||
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
@ -210,14 +206,14 @@ class Tests_Term_Meta extends WP_UnitTestCase {
|
||||
$q->the_post();
|
||||
|
||||
// Requests will hit the database.
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
$this->assertSame( 'bar', get_term_meta( $terms[0], 'foo', true ) );
|
||||
$num_queries++;
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
|
||||
$this->assertSame( 'bar', get_term_meta( $terms[1], 'foo', true ) );
|
||||
$num_queries++;
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -456,8 +456,6 @@ class Tests_Term_Query extends WP_UnitTestCase {
|
||||
* @group cache
|
||||
*/
|
||||
public function test_count_query_should_be_cached() {
|
||||
global $wpdb;
|
||||
|
||||
register_taxonomy( 'wptests_tax_1', 'post' );
|
||||
|
||||
$terms = self::factory()->term->create_many( 2, array( 'taxonomy' => 'wptests_tax_1' ) );
|
||||
@ -472,7 +470,7 @@ class Tests_Term_Query extends WP_UnitTestCase {
|
||||
$count = $query->get_terms();
|
||||
$this->assertEquals( 2, $count );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
$query = new WP_Term_Query(
|
||||
array(
|
||||
@ -483,7 +481,7 @@ class Tests_Term_Query extends WP_UnitTestCase {
|
||||
);
|
||||
$count = $query->get_terms();
|
||||
$this->assertEquals( 2, $count );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -803,11 +801,9 @@ class Tests_Term_Query extends WP_UnitTestCase {
|
||||
* @ticket 41246
|
||||
*/
|
||||
public function test_terms_pre_query_filter_should_bypass_database_query() {
|
||||
global $wpdb;
|
||||
|
||||
add_filter( 'terms_pre_query', array( __CLASS__, 'filter_terms_pre_query' ), 10, 2 );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
$q = new WP_Term_Query();
|
||||
$results = $q->query(
|
||||
@ -819,7 +815,7 @@ class Tests_Term_Query extends WP_UnitTestCase {
|
||||
remove_filter( 'terms_pre_query', array( __CLASS__, 'filter_terms_pre_query' ), 10, 2 );
|
||||
|
||||
// Make sure no queries were executed.
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
|
||||
// We manually inserted a non-existing term and overrode the results with it.
|
||||
$this->assertSame( array( 555 ), $q->terms );
|
||||
|
@ -320,7 +320,6 @@ class Tests_TermExists extends WP_UnitTestCase {
|
||||
* @covers ::term_exists()
|
||||
*/
|
||||
public function test_term_exists_caching() {
|
||||
global $wpdb;
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
|
||||
$slug = __FUNCTION__;
|
||||
@ -331,14 +330,14 @@ class Tests_TermExists extends WP_UnitTestCase {
|
||||
)
|
||||
);
|
||||
$this->assertEquals( $t, term_exists( $slug ) );
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
$this->assertEquals( $t, term_exists( $slug ) );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
|
||||
$this->assertTrue( wp_delete_term( $t, 'wptests_tax' ) );
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
$this->assertNull( term_exists( $slug ) );
|
||||
$this->assertSame( $num_queries + 2, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries + 2, get_num_queries() );
|
||||
|
||||
// Clean up.
|
||||
_unregister_taxonomy( 'wptests_tax' );
|
||||
@ -349,7 +348,6 @@ class Tests_TermExists extends WP_UnitTestCase {
|
||||
* @covers ::term_exists()
|
||||
*/
|
||||
public function test_term_exists_caching_suspend_cache_invalidation() {
|
||||
global $wpdb;
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
|
||||
wp_suspend_cache_invalidation( true );
|
||||
@ -362,9 +360,9 @@ class Tests_TermExists extends WP_UnitTestCase {
|
||||
);
|
||||
|
||||
$this->assertEquals( $t, term_exists( $slug ) );
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
$this->assertEquals( $t, term_exists( $slug ) );
|
||||
$this->assertSame( $num_queries + 1, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries + 1, get_num_queries() );
|
||||
wp_suspend_cache_invalidation( false );
|
||||
|
||||
// Clean up.
|
||||
|
@ -616,8 +616,6 @@ class Tests_Term_WpGetObjectTerms extends WP_UnitTestCase {
|
||||
* @ticket 10142
|
||||
*/
|
||||
public function test_termmeta_cache_should_be_lazy_loaded_by_default() {
|
||||
global $wpdb;
|
||||
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
$terms = self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax' ) );
|
||||
add_term_meta( $terms[0], 'foo', 'bar' );
|
||||
@ -629,21 +627,19 @@ class Tests_Term_WpGetObjectTerms extends WP_UnitTestCase {
|
||||
|
||||
$found = wp_get_object_terms( $p, 'wptests_tax' );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
foreach ( $terms as $t ) {
|
||||
$this->assertSame( 'bar', get_term_meta( $t, 'foo', true ) );
|
||||
}
|
||||
|
||||
$this->assertSame( $num_queries + 1, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries + 1, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 10142
|
||||
*/
|
||||
public function test_termmeta_cache_should_not_be_primed_when_update_term_meta_cache_is_false() {
|
||||
global $wpdb;
|
||||
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
$terms = self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax' ) );
|
||||
add_term_meta( $terms[0], 'foo', 'bar' );
|
||||
@ -661,21 +657,19 @@ class Tests_Term_WpGetObjectTerms extends WP_UnitTestCase {
|
||||
)
|
||||
);
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
foreach ( $terms as $t ) {
|
||||
$this->assertSame( 'bar', get_term_meta( $t, 'foo', true ) );
|
||||
}
|
||||
|
||||
$this->assertSame( $num_queries + 3, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries + 3, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 36932
|
||||
*/
|
||||
public function test_termmeta_cache_should_be_primed_when_fields_is_all_with_object_id() {
|
||||
global $wpdb;
|
||||
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
$terms = self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax' ) );
|
||||
add_term_meta( $terms[0], 'foo', 'bar' );
|
||||
@ -694,21 +688,19 @@ class Tests_Term_WpGetObjectTerms extends WP_UnitTestCase {
|
||||
)
|
||||
);
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
foreach ( $terms as $t ) {
|
||||
$this->assertSame( 'bar', get_term_meta( $t, 'foo', true ) );
|
||||
}
|
||||
|
||||
$this->assertSame( $num_queries + 1, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries + 1, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 36932
|
||||
*/
|
||||
public function test_termmeta_cache_should_be_primed_when_fields_is_ids() {
|
||||
global $wpdb;
|
||||
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
$terms = self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax' ) );
|
||||
add_term_meta( $terms[0], 'foo', 'bar' );
|
||||
@ -727,13 +719,13 @@ class Tests_Term_WpGetObjectTerms extends WP_UnitTestCase {
|
||||
)
|
||||
);
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
|
||||
foreach ( $terms as $t ) {
|
||||
$this->assertSame( 'bar', get_term_meta( $t, 'foo', true ) );
|
||||
}
|
||||
|
||||
$this->assertSame( $num_queries + 1, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries + 1, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -816,8 +808,6 @@ class Tests_Term_WpGetObjectTerms extends WP_UnitTestCase {
|
||||
* @ticket 14162
|
||||
*/
|
||||
public function test_should_prime_cache_for_found_terms() {
|
||||
global $wpdb;
|
||||
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
$p = self::factory()->post->create();
|
||||
$t = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax' ) );
|
||||
@ -831,9 +821,9 @@ class Tests_Term_WpGetObjectTerms extends WP_UnitTestCase {
|
||||
)
|
||||
);
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
$term = get_term( $t );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -865,8 +855,6 @@ class Tests_Term_WpGetObjectTerms extends WP_UnitTestCase {
|
||||
* @ticket 14162
|
||||
*/
|
||||
public function test_term_cache_should_be_primed_for_all_taxonomies() {
|
||||
global $wpdb;
|
||||
|
||||
register_taxonomy( 'wptests_tax1', 'post' );
|
||||
register_taxonomy( 'wptests_tax2', 'post' );
|
||||
$p = self::factory()->post->create();
|
||||
@ -888,10 +876,10 @@ class Tests_Term_WpGetObjectTerms extends WP_UnitTestCase {
|
||||
|
||||
$this->assertSameSets( array( $t1, $t2 ), wp_list_pluck( $found, 'term_id' ) );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
$term1 = get_term( $t1 );
|
||||
$term2 = get_term( $t2 );
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1720,11 +1720,9 @@ class Tests_User_Query extends WP_UnitTestCase {
|
||||
* @ticket 44169
|
||||
*/
|
||||
public function test_users_pre_query_filter_should_bypass_database_query() {
|
||||
global $wpdb;
|
||||
|
||||
add_filter( 'users_pre_query', array( __CLASS__, 'filter_users_pre_query' ), 10, 2 );
|
||||
|
||||
$num_queries = $wpdb->num_queries;
|
||||
$num_queries = get_num_queries();
|
||||
$q = new WP_User_Query(
|
||||
array(
|
||||
'fields' => 'ID',
|
||||
@ -1734,7 +1732,7 @@ class Tests_User_Query extends WP_UnitTestCase {
|
||||
remove_filter( 'users_pre_query', array( __CLASS__, 'filter_users_pre_query' ), 10, 2 );
|
||||
|
||||
// Make sure no queries were executed.
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
|
||||
// We manually inserted a non-existing user and overrode the results with it.
|
||||
$this->assertSame( array( 555 ), $q->results );
|
||||
|
Loading…
x
Reference in New Issue
Block a user