Changeset 55745
- Timestamp:
- 05/11/2023 10:05:51 AM (17 months ago)
- Location:
- trunk
- Files:
-
- 32 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/package-lock.json
r55737 r55745 11955 11955 "version": "1.1.0", 11956 11956 "resolved": "https://registry.npmjs.org/from2-string/-/from2-string-1.1.0.tgz", 11957 "integrity": "sha 512-m8vCh+KnXXXBtfF2VUbiYlQ+nczLcntB0BrtNgpmLkHylhObe9WF1b2LZjBBzrZzA6P4mkEla6ZYQoOUTG8cYA==",11957 "integrity": "sha1-GCgrJ9CKJnyzAwzSuLSw8hKvdSo=", 11958 11958 "requires": { 11959 11959 "from2": "^2.0.3" … … 21113 21113 "version": "1.1.6", 21114 21114 "resolved": "https://registry.npmjs.org/promise-polyfill/-/promise-polyfill-1.1.6.tgz", 21115 "integrity": "sha 512-7rrONfyLkDEc7OJ5QBkqa4KI4EBhCd340xRuIUPGCfu13znS+vx+VDdrT9ODAJHlXm7w4lbxN3DRjyv58EuzDg=="21115 "integrity": "sha1-zQTv9G9clcOn0EVZHXm14+AfEtc=" 21116 21116 }, 21117 21117 "prompts": { … … 23252 23252 "version": "1.0.0", 23253 23253 "resolved": "https://registry.npmjs.org/stream-from-promise/-/stream-from-promise-1.0.0.tgz", 23254 "integrity": "sha 512-j84KLkudt+gr8KJ21RB02btPLx61uGbrLnewsWz6QKmsz8/c4ZFqXw6mJh5+G4oRN7DgDxdbjPxnpySpg1mUig=="23254 "integrity": "sha1-djaH9913fkyJT2QIMz/Gs/yKYbs=" 23255 23255 }, 23256 23256 "stream-to-string": { … … 24520 24520 "version": "2.0.2", 24521 24521 "resolved": "https://registry.npmjs.org/toposort/-/toposort-2.0.2.tgz", 24522 "integrity": "sha 512-0a5EOkAUp8D4moMi2W8ZF8jcga7BgZd91O/yabJCFY8az+XSzeGyTKs0Aoo897iV1Nj6guFq8orWDS96z91oGg=="24522 "integrity": "sha1-riF2gXXRVZ1IvvNUILL0li8JwzA=" 24523 24523 }, 24524 24524 "totalist": { -
trunk/tests/phpunit/tests/bookmark/getBookmarks.php
r51454 r55745 6 6 class Tests_Bookmark_GetBookmarks extends WP_UnitTestCase { 7 7 public function test_should_hit_cache() { 8 global $wpdb;9 10 8 $bookmarks = self::factory()->bookmark->create_many( 2 ); 11 9 … … 16 14 ); 17 15 18 $num_queries = $wpdb->num_queries;16 $num_queries = get_num_queries(); 19 17 20 18 $found2 = get_bookmarks( … … 25 23 26 24 $this->assertSameSets( $found1, $found2 ); 27 $this->assertSame( $num_queries, $wpdb->num_queries);25 $this->assertSame( $num_queries, get_num_queries() ); 28 26 } 29 27 30 28 public function test_adding_bookmark_should_bust_get_bookmarks_cache() { 31 global $wpdb;32 33 29 $bookmarks = self::factory()->bookmark->create_many( 2 ); 34 30 … … 40 36 ); 41 37 42 $num_queries = $wpdb->num_queries;38 $num_queries = get_num_queries(); 43 39 44 40 $bookmarks[] = wp_insert_link( … … 56 52 57 53 $this->assertEqualSets( $bookmarks, wp_list_pluck( $found2, 'link_id' ) ); 58 $this->assertGreaterThan( $num_queries, $wpdb->num_queries);54 $this->assertGreaterThan( $num_queries, get_num_queries() ); 59 55 } 60 56 … … 63 59 */ 64 60 public function test_orderby_rand_should_not_be_cached() { 65 global $wpdb;66 67 61 $bookmarks = self::factory()->bookmark->create_many( 2 ); 68 62 … … 73 67 ); 74 68 75 $num_queries = $wpdb->num_queries;69 $num_queries = get_num_queries(); 76 70 77 71 $found2 = get_bookmarks( … … 83 77 // Equal sets != same order. 84 78 $this->assertEqualSets( $found1, $found2 ); 85 $this->assertGreaterThan( $num_queries, $wpdb->num_queries);79 $this->assertGreaterThan( $num_queries, get_num_queries() ); 86 80 } 87 81 -
trunk/tests/phpunit/tests/comment/getPageOfComment.php
r53863 r55745 101 101 */ 102 102 public function test_subsequent_calls_should_hit_cache() { 103 global $wpdb;104 105 103 $p = self::factory()->post->create(); 106 104 $c = self::factory()->comment->create( array( 'comment_post_ID' => $p ) ); … … 109 107 $page_1 = get_page_of_comment( $c, array( 'per_page' => 3 ) ); 110 108 111 $num_queries = $wpdb->num_queries;109 $num_queries = get_num_queries(); 112 110 $page_2 = get_page_of_comment( $c, array( 'per_page' => 3 ) ); 113 111 114 112 $this->assertSame( $page_1, $page_2 ); 115 $this->assertSame( $num_queries, $wpdb->num_queries);113 $this->assertSame( $num_queries, get_num_queries() ); 116 114 } 117 115 … … 120 118 */ 121 119 public function test_cache_hits_should_be_sensitive_to_comment_type() { 122 global $wpdb;123 124 120 $p = self::factory()->post->create(); 125 121 $comment = self::factory()->comment->create( … … 152 148 $this->assertSame( 2, $page_trackbacks ); 153 149 154 $num_queries = $wpdb->num_queries;150 $num_queries = get_num_queries(); 155 151 $page_comments = get_page_of_comment( 156 152 $comment, … … 162 158 $this->assertSame( 1, $page_comments ); 163 159 164 $this->assertNotEquals( $num_queries, $wpdb->num_queries);160 $this->assertNotEquals( $num_queries, get_num_queries() ); 165 161 } 166 162 -
trunk/tests/phpunit/tests/comment/metaCache.php
r54704 r55745 13 13 */ 14 14 public function test_update_comment_meta_cache_should_default_to_true() { 15 global $wpdb;16 17 15 $p = self::factory()->post->create( array( 'post_status' => 'publish' ) ); 18 16 $comment_ids = self::factory()->comment->create_post_comments( $p, 3 ); … … 31 29 ); 32 30 33 $num_queries = $wpdb->num_queries;31 $num_queries = get_num_queries(); 34 32 foreach ( $comment_ids as $cid ) { 35 33 get_comment_meta( $cid, 'foo', 'bar' ); 36 34 } 37 35 38 $this->assertSame( $num_queries, $wpdb->num_queries);36 $this->assertSame( $num_queries, get_num_queries() ); 39 37 } 40 38 … … 45 43 */ 46 44 public function test_update_comment_meta_cache_true() { 47 global $wpdb;48 49 45 $p = self::factory()->post->create( array( 'post_status' => 'publish' ) ); 50 46 $comment_ids = self::factory()->comment->create_post_comments( $p, 3 ); … … 64 60 ); 65 61 66 $num_queries = $wpdb->num_queries;62 $num_queries = get_num_queries(); 67 63 foreach ( $comment_ids as $cid ) { 68 64 get_comment_meta( $cid, 'foo', 'bar' ); 69 65 } 70 66 71 $this->assertSame( $num_queries, $wpdb->num_queries);67 $this->assertSame( $num_queries, get_num_queries() ); 72 68 } 73 69 … … 78 74 */ 79 75 public function test_update_comment_meta_cache_false() { 80 global $wpdb;81 82 76 $p = self::factory()->post->create( array( 'post_status' => 'publish' ) ); 83 77 $comment_ids = self::factory()->comment->create_post_comments( $p, 3 ); … … 94 88 ); 95 89 96 $num_queries = $wpdb->num_queries;90 $num_queries = get_num_queries(); 97 91 foreach ( $comment_ids as $cid ) { 98 92 get_comment_meta( $cid, 'foo', 'bar' ); 99 93 } 100 94 101 $this->assertSame( $num_queries + 3, $wpdb->num_queries);95 $this->assertSame( $num_queries + 3, get_num_queries() ); 102 96 } 103 97 … … 108 102 */ 109 103 public function test_comment_meta_should_be_lazy_loaded_for_all_comments_in_comments_template() { 110 global $wpdb;111 112 104 $p = self::factory()->post->create( array( 'post_status' => 'publish' ) ); 113 105 $comment_ids = self::factory()->comment->create_post_comments( $p, 3 ); … … 127 119 128 120 // First request will hit the database. 129 $num_queries = $wpdb->num_queries;121 $num_queries = get_num_queries(); 130 122 get_comment_meta( $comment_ids[0], 'sauce' ); 131 $this->assertSame( $num_queries + 1, $wpdb->num_queries);123 $this->assertSame( $num_queries + 1, get_num_queries() ); 132 124 133 125 // Second and third requests should be in cache. 134 126 get_comment_meta( $comment_ids[1], 'sauce' ); 135 127 get_comment_meta( $comment_ids[2], 'sauce' ); 136 $this->assertSame( $num_queries + 1, $wpdb->num_queries);128 $this->assertSame( $num_queries + 1, get_num_queries() ); 137 129 } 138 130 } … … 145 137 */ 146 138 public function test_comment_meta_should_be_lazy_loaded_in_comment_feed_queries() { 147 global $wpdb;148 149 139 $posts = self::factory()->post->create_many( 2, array( 'post_status' => 'publish' ) ); 150 140 … … 174 164 175 165 // First comment will cause the cache to be primed. 176 $num_queries = $wpdb->num_queries;166 $num_queries = get_num_queries(); 177 167 $this->assertSame( 'bar', get_comment_meta( $comments[0], 'foo', 'bar' ) ); 178 168 $num_queries++; 179 $this->assertSame( $num_queries, $wpdb->num_queries);169 $this->assertSame( $num_queries, get_num_queries() ); 180 170 181 171 // Second comment from the results should not cause more queries. 182 172 $this->assertSame( 'bar', get_comment_meta( $comments[1], 'foo', 'bar' ) ); 183 $this->assertSame( $num_queries, $wpdb->num_queries);173 $this->assertSame( $num_queries, get_num_queries() ); 184 174 185 175 // A comment from outside the results will not be primed. 186 176 $this->assertSame( 'bar', get_comment_meta( $comments[4], 'foo', 'bar' ) ); 187 177 $num_queries++; 188 $this->assertSame( $num_queries, $wpdb->num_queries);178 $this->assertSame( $num_queries, get_num_queries() ); 189 179 } 190 180 … … 195 185 */ 196 186 public function test_comment_meta_should_be_lazy_loaded_in_single_post_comment_feed_queries() { 197 global $wpdb;198 199 187 $posts = self::factory()->post->create_many( 2, array( 'post_status' => 'publish' ) ); 200 188 … … 225 213 226 214 // First comment will cause the cache to be primed. 227 $num_queries = $wpdb->num_queries;215 $num_queries = get_num_queries(); 228 216 $this->assertSame( 'bar', get_comment_meta( $comments[0], 'foo', 'bar' ) ); 229 217 $num_queries++; 230 $this->assertSame( $num_queries, $wpdb->num_queries);218 $this->assertSame( $num_queries, get_num_queries() ); 231 219 232 220 // Second comment from the results should not cause more queries. 233 221 $this->assertSame( 'bar', get_comment_meta( $comments[1], 'foo', 'bar' ) ); 234 $this->assertSame( $num_queries, $wpdb->num_queries);222 $this->assertSame( $num_queries, get_num_queries() ); 235 223 236 224 // A comment from outside the results will not be primed. 237 225 $this->assertSame( 'bar', get_comment_meta( $comments[4], 'foo', 'bar' ) ); 238 226 $num_queries++; 239 $this->assertSame( $num_queries, $wpdb->num_queries);227 $this->assertSame( $num_queries, get_num_queries() ); 240 228 } 241 229 -
trunk/tests/phpunit/tests/comment/query.php
r54704 r55745 3589 3589 */ 3590 3590 public function test_comment_cache_key_should_ignore_custom_params() { 3591 global $wpdb;3592 3593 3591 $p = self::factory()->post->create(); 3594 3592 $c = self::factory()->comment->create( array( 'comment_post_ID' => $p ) ); … … 3602 3600 ); 3603 3601 3604 $num_queries = $wpdb->num_queries;3602 $num_queries = get_num_queries(); 3605 3603 3606 3604 $q2 = new WP_Comment_Query(); … … 3613 3611 ); 3614 3612 3615 $this->assertSame( $num_queries, $wpdb->num_queries);3613 $this->assertSame( $num_queries, get_num_queries() ); 3616 3614 } 3617 3615 … … 3630 3628 ); 3631 3629 3632 $num_queries = $wpdb->num_queries;3630 $num_queries = get_num_queries(); 3633 3631 3634 3632 $q2 = new WP_Comment_Query( … … 3638 3636 ); 3639 3637 3640 $this->assertNotEquals( $num_queries, $wpdb->num_queries);3638 $this->assertNotEquals( $num_queries, get_num_queries() ); 3641 3639 } 3642 3640 … … 3655 3653 ); 3656 3654 3657 $num_queries = $wpdb->num_queries;3655 $num_queries = get_num_queries(); 3658 3656 3659 3657 $q2 = new WP_Comment_Query( … … 3663 3661 ); 3664 3662 3665 $this->assertNotEquals( $num_queries, $wpdb->num_queries);3663 $this->assertNotEquals( $num_queries, get_num_queries() ); 3666 3664 } 3667 3665 … … 4428 4426 $q1_ids = wp_list_pluck( $q1->comments, 'comment_ID' ); 4429 4427 4430 $num_queries = $wpdb->num_queries;4428 $num_queries = get_num_queries(); 4431 4429 $q2 = new WP_Comment_Query( 4432 4430 array( … … 4438 4436 4439 4437 $this->assertSameSets( $q1_ids, $q2_ids ); 4440 $this->assertSame( $num_queries, $wpdb->num_queries);4438 $this->assertSame( $num_queries, get_num_queries() ); 4441 4439 } 4442 4440 … … 4591 4589 ); 4592 4590 4593 $num_queries = $wpdb->num_queries;4591 $num_queries = get_num_queries(); 4594 4592 $this->assertTrue( isset( $q->comments[0]->post_name ) ); 4595 $this->assertSame( $num_queries + 1, $wpdb->num_queries);4593 $this->assertSame( $num_queries + 1, get_num_queries() ); 4596 4594 } 4597 4595 … … 4614 4612 ); 4615 4613 4616 $num_queries = $wpdb->num_queries;4614 $num_queries = get_num_queries(); 4617 4615 $this->assertTrue( isset( $q->comments[0]->post_name ) ); 4618 $this->assertSame( $num_queries, $wpdb->num_queries);4616 $this->assertSame( $num_queries, get_num_queries() ); 4619 4617 } 4620 4618 … … 4630 4628 clean_comment_cache( $comments ); 4631 4629 4632 $num_queries = $wpdb->num_queries;4630 $num_queries = get_num_queries(); 4633 4631 $q = new WP_Comment_Query( 4634 4632 array( … … 4646 4644 $this->assertEqualSets( $comments, $found ); 4647 4645 4648 $this->assertSame( $num_queries, $wpdb->num_queries);4646 $this->assertSame( $num_queries, get_num_queries() ); 4649 4647 } 4650 4648 … … 4693 4691 ); 4694 4692 4695 $num_queries = $wpdb->num_queries;4693 $num_queries = get_num_queries(); 4696 4694 4697 4695 $q2 = new WP_Comment_Query( … … 4702 4700 ); 4703 4701 4704 $this->assertSame( $num_queries, $wpdb->num_queries);4702 $this->assertSame( $num_queries, get_num_queries() ); 4705 4703 } 4706 4704 … … 4725 4723 ); 4726 4724 4727 $num_queries = $wpdb->num_queries;4725 $num_queries = get_num_queries(); 4728 4726 4729 4727 $q = new WP_Comment_Query( … … 4734 4732 ); 4735 4733 4736 $this->assertSame( $num_queries, $wpdb->num_queries);4734 $this->assertSame( $num_queries, get_num_queries() ); 4737 4735 $this->assertSameSets( array( $c ), $q->comments ); 4738 4736 } … … 4767 4765 ); 4768 4766 4769 $num_queries = $wpdb->num_queries;4767 $num_queries = get_num_queries(); 4770 4768 4771 4769 $q = new WP_Comment_Query( … … 4777 4775 4778 4776 $num_queries++; 4779 $this->assertSame( $num_queries, $wpdb->num_queries);4777 $this->assertSame( $num_queries, get_num_queries() ); 4780 4778 $this->assertSameSets( array( $c ), $q->comments ); 4781 4779 } … … 4803 4801 wp_delete_comment( $c ); 4804 4802 4805 $num_queries = $wpdb->num_queries;4803 $num_queries = get_num_queries(); 4806 4804 4807 4805 $q = new WP_Comment_Query( … … 4813 4811 4814 4812 $num_queries++; 4815 $this->assertSame( $num_queries, $wpdb->num_queries);4813 $this->assertSame( $num_queries, get_num_queries() ); 4816 4814 $this->assertSameSets( array(), $q->comments ); 4817 4815 } … … 4839 4837 wp_trash_comment( $c ); 4840 4838 4841 $num_queries = $wpdb->num_queries;4839 $num_queries = get_num_queries(); 4842 4840 4843 4841 $q = new WP_Comment_Query( … … 4849 4847 4850 4848 $num_queries++; 4851 $this->assertSame( $num_queries, $wpdb->num_queries);4849 $this->assertSame( $num_queries, get_num_queries() ); 4852 4850 $this->assertSameSets( array(), $q->comments ); 4853 4851 } … … 4877 4875 wp_untrash_comment( $c ); 4878 4876 4879 $num_queries = $wpdb->num_queries;4877 $num_queries = get_num_queries(); 4880 4878 4881 4879 $q = new WP_Comment_Query( … … 4887 4885 4888 4886 $num_queries++; 4889 $this->assertSame( $num_queries, $wpdb->num_queries);4887 $this->assertSame( $num_queries, get_num_queries() ); 4890 4888 $this->assertSameSets( array( $c ), $q->comments ); 4891 4889 } … … 4913 4911 wp_spam_comment( $c ); 4914 4912 4915 $num_queries = $wpdb->num_queries;4913 $num_queries = get_num_queries(); 4916 4914 4917 4915 $q = new WP_Comment_Query( … … 4923 4921 4924 4922 $num_queries++; 4925 $this->assertSame( $num_queries, $wpdb->num_queries);4923 $this->assertSame( $num_queries, get_num_queries() ); 4926 4924 $this->assertSameSets( array(), $q->comments ); 4927 4925 } … … 4951 4949 wp_unspam_comment( $c ); 4952 4950 4953 $num_queries = $wpdb->num_queries;4951 $num_queries = get_num_queries(); 4954 4952 4955 4953 $q = new WP_Comment_Query( … … 4961 4959 4962 4960 $num_queries++; 4963 $this->assertSame( $num_queries, $wpdb->num_queries);4961 $this->assertSame( $num_queries, get_num_queries() ); 4964 4962 $this->assertSameSets( array( $c ), $q->comments ); 4965 4963 } … … 4983 4981 ); 4984 4982 4985 $number_of_queries = $wpdb->num_queries;4983 $number_of_queries = get_num_queries(); 4986 4984 4987 4985 $query_2 = $q->query( … … 4993 4991 ) 4994 4992 ); 4995 $this->assertSame( $number_of_queries + 1, $wpdb->num_queries);4993 $this->assertSame( $number_of_queries + 1, get_num_queries() ); 4996 4994 } 4997 4995 … … 5014 5012 ) 5015 5013 ); 5016 $number_of_queries = $wpdb->num_queries;5014 $number_of_queries = get_num_queries(); 5017 5015 5018 5016 $query_2 = $q->query( … … 5024 5022 ) 5025 5023 ); 5026 $this->assertSame( $number_of_queries, $wpdb->num_queries);5024 $this->assertSame( $number_of_queries, get_num_queries() ); 5027 5025 } 5028 5026 … … 5044 5042 ) 5045 5043 ); 5046 $number_of_queries = $wpdb->num_queries;5044 $number_of_queries = get_num_queries(); 5047 5045 5048 5046 $query_2 = $q->query( … … 5054 5052 ); 5055 5053 5056 $this->assertSame( $number_of_queries, $wpdb->num_queries);5054 $this->assertSame( $number_of_queries, get_num_queries() ); 5057 5055 } 5058 5056 … … 5220 5218 add_filter( 'comments_pre_query', array( __CLASS__, 'filter_comments_pre_query' ), 10, 2 ); 5221 5219 5222 $num_queries = $wpdb->num_queries;5220 $num_queries = get_num_queries(); 5223 5221 5224 5222 $q = new WP_Comment_Query(); … … 5228 5226 5229 5227 // Make sure no queries were executed. 5230 $this->assertSame( $num_queries, $wpdb->num_queries);5228 $this->assertSame( $num_queries, get_num_queries() ); 5231 5229 5232 5230 // We manually inserted a non-existing site and overrode the results with it. -
trunk/tests/phpunit/tests/comment/wpUpdateCommentCountNow.php
r54704 r55745 15 15 16 16 public function test_regular_post_updates_comment_count() { 17 global $wpdb;18 19 17 $post_id = self::factory()->post->create(); 20 18 … … 22 20 $this->assertSame( '1', get_comments_number( $post_id ) ); 23 21 24 $num_queries = $wpdb->num_queries;22 $num_queries = get_num_queries(); 25 23 $this->assertTrue( wp_update_comment_count_now( $post_id ) ); 26 $this->assertSame( $num_queries + 2, $wpdb->num_queries);24 $this->assertSame( $num_queries + 2, get_num_queries() ); 27 25 28 26 $this->assertSame( '1', get_comments_number( $post_id ) ); … … 39 37 $this->assertSame( '100', get_comments_number( $post_id ) ); 40 38 41 $num_queries = $wpdb->num_queries;39 $num_queries = get_num_queries(); 42 40 $this->assertTrue( wp_update_comment_count_now( $post_id ) ); 43 41 // Only one query is made instead of two. 44 $this->assertSame( $num_queries + 1, $wpdb->num_queries);42 $this->assertSame( $num_queries + 1, get_num_queries() ); 45 43 46 44 $this->assertSame( '100', get_comments_number( $post_id ) ); -
trunk/tests/phpunit/tests/customize/manager.php
r55039 r55745 272 272 */ 273 273 public function test_fresh_site_flag_clearing() { 274 global $wp_customize , $wpdb;274 global $wp_customize; 275 275 276 276 // Make sure fresh site flag is cleared when publishing a changeset. … … 284 284 285 285 // Make sure no DB write is done when publishing and a site is already non-fresh. 286 $query_count = $wpdb->num_queries;286 $query_count = get_num_queries(); 287 287 do_action( 'customize_save_after', $wp_customize ); 288 $this->assertSame( $query_count, $wpdb->num_queries);288 $this->assertSame( $query_count, get_num_queries() ); 289 289 } 290 290 -
trunk/tests/phpunit/tests/general/wpGetArchives.php
r52010 r55745 17 17 */ 18 18 public function test_get_archives_cache() { 19 global $wpdb;20 21 19 self::factory()->post->create_many( 3, array( 'post_type' => 'post' ) ); 22 20 wp_cache_delete( 'last_changed', 'posts' ); 23 21 $this->assertFalse( wp_cache_get( 'last_changed', 'posts' ) ); 24 22 25 $num_queries = $wpdb->num_queries;23 $num_queries = get_num_queries(); 26 24 27 25 // Cache is not primed, expect 1 query. … … 35 33 $time1 = wp_cache_get( 'last_changed', 'posts' ); 36 34 $this->assertNotEmpty( $time1 ); 37 $this->assertSame( $num_queries + 1, $wpdb->num_queries);35 $this->assertSame( $num_queries + 1, get_num_queries() ); 38 36 39 $num_queries = $wpdb->num_queries;37 $num_queries = get_num_queries(); 40 38 41 39 // Cache is primed, expect no queries. … … 48 46 $this->assertIsString( $result ); 49 47 $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) ); 50 $this->assertSame( $num_queries, $wpdb->num_queries);48 $this->assertSame( $num_queries, get_num_queries() ); 51 49 52 50 // Change args, resulting in a different query string. Cache is not primed, expect 1 query. … … 60 58 $this->assertIsString( $result ); 61 59 $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) ); 62 $this->assertSame( $num_queries + 1, $wpdb->num_queries);60 $this->assertSame( $num_queries + 1, get_num_queries() ); 63 61 64 $num_queries = $wpdb->num_queries;62 $num_queries = get_num_queries(); 65 63 66 64 // Cache is primed, expect no queries. … … 74 72 $this->assertIsString( $result ); 75 73 $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) ); 76 $this->assertSame( $num_queries, $wpdb->num_queries);74 $this->assertSame( $num_queries, get_num_queries() ); 77 75 78 $num_queries = $wpdb->num_queries;76 $num_queries = get_num_queries(); 79 77 80 78 // Change type. Cache is not primed, expect 1 query. … … 87 85 $this->assertIsString( $result ); 88 86 $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) ); 89 $this->assertSame( $num_queries + 1, $wpdb->num_queries);87 $this->assertSame( $num_queries + 1, get_num_queries() ); 90 88 91 $num_queries = $wpdb->num_queries;89 $num_queries = get_num_queries(); 92 90 93 91 // Cache is primed, expect no queries. … … 100 98 $this->assertIsString( $result ); 101 99 $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) ); 102 $this->assertSame( $num_queries, $wpdb->num_queries);100 $this->assertSame( $num_queries, get_num_queries() ); 103 101 104 102 // Change type. Cache is not primed, expect 1 query. … … 111 109 $this->assertIsString( $result ); 112 110 $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) ); 113 $this->assertSame( $num_queries + 1, $wpdb->num_queries);111 $this->assertSame( $num_queries + 1, get_num_queries() ); 114 112 115 $num_queries = $wpdb->num_queries;113 $num_queries = get_num_queries(); 116 114 117 115 // Cache is primed, expect no queries. … … 124 122 $this->assertIsString( $result ); 125 123 $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) ); 126 $this->assertSame( $num_queries, $wpdb->num_queries);124 $this->assertSame( $num_queries, get_num_queries() ); 127 125 128 126 // Change type. Cache is not primed, expect 1 query. … … 135 133 $this->assertIsString( $result ); 136 134 $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) ); 137 $this->assertSame( $num_queries + 1, $wpdb->num_queries);135 $this->assertSame( $num_queries + 1, get_num_queries() ); 138 136 139 $num_queries = $wpdb->num_queries;137 $num_queries = get_num_queries(); 140 138 141 139 // Cache is primed, expect no queries. … … 148 146 $this->assertIsString( $result ); 149 147 $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) ); 150 $this->assertSame( $num_queries, $wpdb->num_queries);148 $this->assertSame( $num_queries, get_num_queries() ); 151 149 152 150 // Change type. Cache is not primed, expect 1 query. … … 159 157 $this->assertIsString( $result ); 160 158 $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) ); 161 $this->assertSame( $num_queries + 1, $wpdb->num_queries);159 $this->assertSame( $num_queries + 1, get_num_queries() ); 162 160 163 $num_queries = $wpdb->num_queries;161 $num_queries = get_num_queries(); 164 162 165 163 // Cache is primed, expect no queries. … … 172 170 $this->assertIsString( $result ); 173 171 $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) ); 174 $this->assertSame( $num_queries, $wpdb->num_queries);172 $this->assertSame( $num_queries, get_num_queries() ); 175 173 } 176 174 } -
trunk/tests/phpunit/tests/multisite/network.php
r54637 r55745 591 591 */ 592 592 public function test_get_network_not_found_cache() { 593 global $wpdb;594 595 593 $new_network_id = $this->_get_next_network_id(); 596 594 $this->assertNull( get_network( $new_network_id ) ); 597 595 598 $num_queries = $wpdb->num_queries;596 $num_queries = get_num_queries(); 599 597 $this->assertNull( get_network( $new_network_id ) ); 600 $this->assertSame( $num_queries, $wpdb->num_queries);598 $this->assertSame( $num_queries, get_num_queries() ); 601 599 } 602 600 -
trunk/tests/phpunit/tests/multisite/site.php
r55043 r55745 2171 2171 */ 2172 2172 public function test_get_site_not_found_cache() { 2173 global $wpdb;2174 2175 2173 $new_site_id = $this->_get_next_site_id(); 2176 2174 $this->assertNull( get_site( $new_site_id ) ); 2177 2175 2178 $num_queries = $wpdb->num_queries;2176 $num_queries = get_num_queries(); 2179 2177 $this->assertNull( get_site( $new_site_id ) ); 2180 $this->assertSame( $num_queries, $wpdb->num_queries);2178 $this->assertSame( $num_queries, get_num_queries() ); 2181 2179 } 2182 2180 -
trunk/tests/phpunit/tests/multisite/siteMeta.php
r51860 r55745 221 221 222 222 public function test_update_site_meta_cache() { 223 global $wpdb;224 225 223 if ( ! is_site_meta_supported() ) { 226 224 $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' ); … … 230 228 update_sitemeta_cache( array( self::$site_id ) ); 231 229 232 $num_queries = $wpdb->num_queries;230 $num_queries = get_num_queries(); 233 231 get_site_meta( self::$site_id, 'foo', true ); 234 $this->assertSame( $num_queries, $wpdb->num_queries);232 $this->assertSame( $num_queries, get_num_queries() ); 235 233 } 236 234 237 235 public function test_query_update_site_meta_cache_true() { 238 global $wpdb;239 240 236 if ( ! is_site_meta_supported() ) { 241 237 $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' ); … … 251 247 ); 252 248 253 $num_queries = $wpdb->num_queries;249 $num_queries = get_num_queries(); 254 250 get_site_meta( self::$site_id, 'foo', true ); 255 $this->assertSame( $num_queries, $wpdb->num_queries);251 $this->assertSame( $num_queries, get_num_queries() ); 256 252 } 257 253 258 254 public function test_query_update_site_meta_cache_false() { 259 global $wpdb;260 261 255 if ( ! is_site_meta_supported() ) { 262 256 $this->markTestSkipped( 'Test only runs with the blogmeta database table installed.' ); … … 272 266 ); 273 267 274 $num_queries = $wpdb->num_queries;268 $num_queries = get_num_queries(); 275 269 get_site_meta( self::$site_id, 'foo', true ); 276 $this->assertSame( $num_queries + 1, $wpdb->num_queries);270 $this->assertSame( $num_queries + 1, get_num_queries() ); 277 271 } 278 272 -
trunk/tests/phpunit/tests/multisite/wpNetworkQuery.php
r53098 r55745 429 429 */ 430 430 public function test_wp_network_query_cache_with_different_fields_no_count() { 431 global $wpdb;432 433 431 $q = new WP_Network_Query(); 434 432 $query_1 = $q->query( … … 439 437 ) 440 438 ); 441 $number_of_queries = $wpdb->num_queries;439 $number_of_queries = get_num_queries(); 442 440 443 441 $query_2 = $q->query( … … 449 447 ); 450 448 451 $this->assertSame( $number_of_queries, $wpdb->num_queries);449 $this->assertSame( $number_of_queries, get_num_queries() ); 452 450 } 453 451 … … 456 454 */ 457 455 public function test_wp_network_query_cache_with_different_fields_active_count() { 458 global $wpdb;459 460 456 $q = new WP_Network_Query(); 461 457 … … 468 464 ) 469 465 ); 470 $number_of_queries = $wpdb->num_queries;466 $number_of_queries = get_num_queries(); 471 467 472 468 $query_2 = $q->query( … … 478 474 ) 479 475 ); 480 $this->assertSame( $number_of_queries, $wpdb->num_queries);476 $this->assertSame( $number_of_queries, get_num_queries() ); 481 477 } 482 478 … … 485 481 */ 486 482 public function test_wp_network_query_cache_with_same_fields_different_count() { 487 global $wpdb;488 489 483 $q = new WP_Network_Query(); 490 484 … … 497 491 ); 498 492 499 $number_of_queries = $wpdb->num_queries;493 $number_of_queries = get_num_queries(); 500 494 501 495 $query_2 = $q->query( … … 507 501 ) 508 502 ); 509 $this->assertSame( $number_of_queries + 1, $wpdb->num_queries);503 $this->assertSame( $number_of_queries + 1, get_num_queries() ); 510 504 } 511 505 … … 569 563 */ 570 564 public function test_networks_pre_query_filter_should_bypass_database_query() { 571 global $wpdb;572 573 565 add_filter( 'networks_pre_query', array( __CLASS__, 'filter_networks_pre_query' ), 10, 2 ); 574 566 575 $num_queries = $wpdb->num_queries;567 $num_queries = get_num_queries(); 576 568 577 569 $q = new WP_Network_Query(); … … 581 573 582 574 // Make sure no queries were executed. 583 $this->assertSame( $num_queries, $wpdb->num_queries);575 $this->assertSame( $num_queries, get_num_queries() ); 584 576 585 577 // We manually inserted a non-existing site and overrode the results with it. -
trunk/tests/phpunit/tests/multisite/wpSiteQuery.php
r53097 r55745 780 780 */ 781 781 public function test_wp_site_query_cache_with_different_fields_no_count() { 782 global $wpdb;783 782 $q = new WP_Site_Query(); 784 783 $query_1 = $q->query( … … 790 789 ) 791 790 ); 792 $number_of_queries = $wpdb->num_queries;791 $number_of_queries = get_num_queries(); 793 792 794 793 $query_2 = $q->query( … … 801 800 ); 802 801 803 $this->assertSame( $number_of_queries, $wpdb->num_queries);802 $this->assertSame( $number_of_queries, get_num_queries() ); 804 803 } 805 804 … … 808 807 */ 809 808 public function test_wp_site_query_cache_with_different_fields_active_count() { 810 global $wpdb;811 809 $q = new WP_Site_Query(); 812 810 … … 820 818 ) 821 819 ); 822 $number_of_queries = $wpdb->num_queries;820 $number_of_queries = get_num_queries(); 823 821 824 822 $query_2 = $q->query( … … 831 829 ) 832 830 ); 833 $this->assertSame( $number_of_queries, $wpdb->num_queries);831 $this->assertSame( $number_of_queries, get_num_queries() ); 834 832 } 835 833 … … 838 836 */ 839 837 public function test_wp_site_query_cache_with_same_fields_different_count() { 840 global $wpdb;841 838 $q = new WP_Site_Query(); 842 839 … … 861 858 ) 862 859 ); 863 $this->assertSame( $number_of_queries + 1, $wpdb->num_queries);860 $this->assertSame( $number_of_queries + 1, get_num_queries() ); 864 861 } 865 862 … … 1120 1117 */ 1121 1118 public function test_sites_pre_query_filter_should_bypass_database_query() { 1122 global $wpdb;1123 1124 1119 add_filter( 'sites_pre_query', array( __CLASS__, 'filter_sites_pre_query' ), 10, 2 ); 1125 1120 1126 $num_queries = $wpdb->num_queries;1121 $num_queries = get_num_queries(); 1127 1122 1128 1123 $q = new WP_Site_Query(); … … 1132 1127 1133 1128 // Make sure no queries were executed. 1134 $this->assertSame( $num_queries, $wpdb->num_queries);1129 $this->assertSame( $num_queries, get_num_queries() ); 1135 1130 1136 1131 // We manually inserted a non-existing site and overrode the results with it. -
trunk/tests/phpunit/tests/option/updateOption.php
r53865 r55745 29 29 */ 30 30 public function test_should_set_autoload_yes_for_nonexistent_option_when_autoload_param_is_missing() { 31 global $wpdb;32 31 $this->flush_cache(); 33 32 update_option( 'test_update_option_default', 'value' ); … … 37 36 wp_load_alloptions(); 38 37 39 $before = $wpdb->num_queries;40 $value = get_option( 'test_update_option_default' ); 41 $after = $wpdb->num_queries;38 $before = get_num_queries(); 39 $value = get_option( 'test_update_option_default' ); 40 $after = get_num_queries(); 42 41 43 42 $this->assertSame( $before, $after ); … … 53 52 */ 54 53 public function test_should_set_autoload_yes_for_nonexistent_option_when_autoload_param_is_yes() { 55 global $wpdb;56 54 $this->flush_cache(); 57 55 update_option( 'test_update_option_default', 'value', 'yes' ); … … 61 59 wp_load_alloptions(); 62 60 63 $before = $wpdb->num_queries;64 $value = get_option( 'test_update_option_default' ); 65 $after = $wpdb->num_queries;61 $before = get_num_queries(); 62 $value = get_option( 'test_update_option_default' ); 63 $after = get_num_queries(); 66 64 67 65 $this->assertSame( $before, $after ); … … 77 75 */ 78 76 public function test_should_set_autoload_no_for_nonexistent_option_when_autoload_param_is_no() { 79 global $wpdb;80 77 $this->flush_cache(); 81 78 update_option( 'test_update_option_default', 'value', 'no' ); … … 85 82 wp_load_alloptions(); 86 83 87 $before = $wpdb->num_queries;88 $value = get_option( 'test_update_option_default' ); 89 $after = $wpdb->num_queries;84 $before = get_num_queries(); 85 $value = get_option( 'test_update_option_default' ); 86 $after = get_num_queries(); 90 87 91 88 // Database has been hit. … … 102 99 */ 103 100 public function test_should_set_autoload_no_for_nonexistent_option_when_autoload_param_is_false() { 104 global $wpdb;105 101 $this->flush_cache(); 106 102 update_option( 'test_update_option_default', 'value', false ); … … 110 106 wp_load_alloptions(); 111 107 112 $before = $wpdb->num_queries;113 $value = get_option( 'test_update_option_default' ); 114 $after = $wpdb->num_queries;108 $before = get_num_queries(); 109 $value = get_option( 'test_update_option_default' ); 110 $after = get_num_queries(); 115 111 116 112 // Database has been hit. … … 127 123 */ 128 124 public function test_autoload_should_be_updated_for_existing_option_when_value_is_changed() { 129 global $wpdb;130 125 add_option( 'foo', 'bar', '', 'no' ); 131 126 $updated = update_option( 'foo', 'bar2', true ); … … 137 132 wp_load_alloptions(); 138 133 139 $before = $wpdb->num_queries;134 $before = get_num_queries(); 140 135 $value = get_option( 'foo' ); 141 136 142 $this->assertSame( $before, $wpdb->num_queries);137 $this->assertSame( $before, get_num_queries() ); 143 138 $this->assertSame( $value, 'bar2' ); 144 139 } … … 152 147 */ 153 148 public function test_autoload_should_not_be_updated_for_existing_option_when_value_is_unchanged() { 154 global $wpdb;155 149 add_option( 'foo', 'bar', '', 'yes' ); 156 150 $updated = update_option( 'foo', 'bar', false ); … … 162 156 wp_load_alloptions(); 163 157 164 $before = $wpdb->num_queries;158 $before = get_num_queries(); 165 159 $value = get_option( 'foo' ); 166 160 167 161 // 'foo' should still be autoload=yes, so we should see no additional querios. 168 $this->assertSame( $before, $wpdb->num_queries);162 $this->assertSame( $before, get_num_queries() ); 169 163 $this->assertSame( $value, 'bar' ); 170 164 } … … 178 172 */ 179 173 public function test_autoload_should_not_be_updated_for_existing_option_when_value_is_changed_but_no_value_of_autoload_is_provided() { 180 global $wpdb;181 174 add_option( 'foo', 'bar', '', 'yes' ); 182 175 … … 190 183 wp_load_alloptions(); 191 184 192 $before = $wpdb->num_queries;185 $before = get_num_queries(); 193 186 $value = get_option( 'foo' ); 194 187 195 188 // 'foo' should still be autoload=yes, so we should see no additional queries. 196 $this->assertSame( $before, $wpdb->num_queries);189 $this->assertSame( $before, get_num_queries() ); 197 190 $this->assertSame( $value, 'bar2' ); 198 191 } -
trunk/tests/phpunit/tests/option/wpLoadAlloptions.php
r55256 r55745 35 35 */ 36 36 public function test_if_alloptions_are_retrieved_from_cache() { 37 global $wpdb; 38 $before = $wpdb->num_queries; 37 $before = get_num_queries(); 39 38 wp_load_alloptions(); 40 $after = $wpdb->num_queries;39 $after = get_num_queries(); 41 40 42 41 // Database has not been hit. … … 50 49 */ 51 50 public function test_if_alloptions_are_retrieved_from_database() { 52 global $wpdb;53 54 51 // Delete the existing cache first. 55 52 wp_cache_delete( 'alloptions', 'options' ); 56 53 57 $before = $wpdb->num_queries;54 $before = get_num_queries(); 58 55 wp_load_alloptions(); 59 $after = $wpdb->num_queries;56 $after = get_num_queries(); 60 57 61 58 // Database has been hit. -
trunk/tests/phpunit/tests/post/getPageByPath.php
r55169 r55745 261 261 */ 262 262 public function test_should_hit_cache() { 263 global $wpdb;264 265 263 $page = self::factory()->post->create( 266 264 array( … … 274 272 $this->assertSame( $page, $found->ID ); 275 273 276 $num_queries = $wpdb->num_queries;277 278 $found = get_page_by_path( 'foo' ); 279 $this->assertSame( $page, $found->ID ); 280 $this->assertSame( $num_queries, $wpdb->num_queries);274 $num_queries = get_num_queries(); 275 276 $found = get_page_by_path( 'foo' ); 277 $this->assertSame( $page, $found->ID ); 278 $this->assertSame( $num_queries, get_num_queries() ); 281 279 } 282 280 … … 285 283 */ 286 284 public function test_bad_path_should_be_cached() { 287 global $wpdb;288 289 285 // Prime cache. 290 286 $found = get_page_by_path( 'foo' ); 291 287 $this->assertNull( $found ); 292 288 293 $num_queries = $wpdb->num_queries;294 295 $found = get_page_by_path( 'foo' ); 296 $this->assertNull( $found ); 297 $this->assertSame( $num_queries, $wpdb->num_queries);289 $num_queries = get_num_queries(); 290 291 $found = get_page_by_path( 'foo' ); 292 $this->assertNull( $found ); 293 $this->assertSame( $num_queries, get_num_queries() ); 298 294 } 299 295 … … 302 298 */ 303 299 public function test_bad_path_served_from_cache_should_not_fall_back_on_current_post() { 304 global $ wpdb, $post;300 global $post; 305 301 306 302 // Fake the global. … … 311 307 $this->assertNull( $found ); 312 308 313 $num_queries = $wpdb->num_queries;314 315 $found = get_page_by_path( 'foo' ); 316 $this->assertNull( $found ); 317 $this->assertSame( $num_queries, $wpdb->num_queries);309 $num_queries = get_num_queries(); 310 311 $found = get_page_by_path( 'foo' ); 312 $this->assertNull( $found ); 313 $this->assertSame( $num_queries, get_num_queries() ); 318 314 319 315 unset( $post ); … … 324 320 */ 325 321 public function test_cache_should_not_match_post_in_different_post_type_with_same_path() { 326 global $wpdb;327 328 322 register_post_type( 'wptests_pt' ); 329 323 … … 346 340 $this->assertSame( $p1, $found->ID ); 347 341 348 $num_queries = $wpdb->num_queries;342 $num_queries = get_num_queries(); 349 343 350 344 $found = get_page_by_path( 'foo', OBJECT, 'wptests_pt' ); 351 345 $this->assertSame( $p2, $found->ID ); 352 346 $num_queries++; 353 $this->assertSame( $num_queries, $wpdb->num_queries);347 $this->assertSame( $num_queries, get_num_queries() ); 354 348 } 355 349 … … 358 352 */ 359 353 public function test_cache_should_be_invalidated_when_post_name_is_edited() { 360 global $wpdb;361 362 354 $page = self::factory()->post->create( 363 355 array( … … 378 370 ); 379 371 380 $num_queries = $wpdb->num_queries;372 $num_queries = get_num_queries(); 381 373 382 374 $found = get_page_by_path( 'bar' ); 383 375 $this->assertSame( $page, $found->ID ); 384 376 $num_queries++; 385 $this->assertSame( $num_queries, $wpdb->num_queries);377 $this->assertSame( $num_queries, get_num_queries() ); 386 378 } 387 379 -
trunk/tests/phpunit/tests/post/getPages.php
r55590 r55745 11 11 */ 12 12 public function test_get_pages_cache() { 13 global $wpdb;14 15 13 self::factory()->post->create_many( 3, array( 'post_type' => 'page' ) ); 16 14 wp_cache_delete( 'last_changed', 'posts' ); … … 21 19 $time1 = wp_cache_get( 'last_changed', 'posts' ); 22 20 $this->assertNotEmpty( $time1 ); 23 $num_queries = $wpdb->num_queries;21 $num_queries = get_num_queries(); 24 22 foreach ( $pages as $page ) { 25 23 $this->assertInstanceOf( 'WP_Post', $page ); … … 30 28 $this->assertCount( 3, $pages ); 31 29 $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) ); 32 $this->assertSame( $num_queries, $wpdb->num_queries);30 $this->assertSame( $num_queries, get_num_queries() ); 33 31 foreach ( $pages as $page ) { 34 32 $this->assertInstanceOf( 'WP_Post', $page ); … … 40 38 $this->assertCount( 2, $pages ); 41 39 $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) ); 42 $this->assertSame( $num_queries + 1, $wpdb->num_queries);40 $this->assertSame( $num_queries + 1, get_num_queries() ); 43 41 foreach ( $pages as $page ) { 44 42 $this->assertInstanceOf( 'WP_Post', $page ); 45 43 } 46 44 47 $num_queries = $wpdb->num_queries;45 $num_queries = get_num_queries(); 48 46 49 47 // Again. num_queries and last_changed should remain the same. … … 51 49 $this->assertCount( 2, $pages ); 52 50 $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) ); 53 $this->assertSame( $num_queries, $wpdb->num_queries);51 $this->assertSame( $num_queries, get_num_queries() ); 54 52 foreach ( $pages as $page ) { 55 53 $this->assertInstanceOf( 'WP_Post', $page ); … … 60 58 $this->assertCount( 3, $pages ); 61 59 $this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) ); 62 $this->assertSame( $num_queries, $wpdb->num_queries);60 $this->assertSame( $num_queries, get_num_queries() ); 63 61 foreach ( $pages as $page ) { 64 62 $this->assertInstanceOf( 'WP_Post', $page ); … … 69 67 $this->assertNotEquals( $time1, $time2 = wp_cache_get( 'last_changed', 'posts' ) ); 70 68 get_post( $pages[0]->ID ); 71 $num_queries = $wpdb->num_queries;69 $num_queries = get_num_queries(); 72 70 73 71 // last_changed bumped so num_queries should increment. … … 75 73 $this->assertCount( 2, $pages ); 76 74 $this->assertSame( $time2, wp_cache_get( 'last_changed', 'posts' ) ); 77 $this->assertSame( $num_queries + 1, $wpdb->num_queries);75 $this->assertSame( $num_queries + 1, get_num_queries() ); 78 76 foreach ( $pages as $page ) { 79 77 $this->assertInstanceOf( 'WP_Post', $page ); … … 88 86 $this->assertGreaterThan( $old_changed_float, $new_changed_float ); 89 87 90 $num_queries = $wpdb->num_queries;88 $num_queries = get_num_queries(); 91 89 $last_changed = wp_cache_get( 'last_changed', 'posts' ); 92 90 … … 95 93 $this->assertCount( 2, $pages ); 96 94 $this->assertSame( $last_changed, wp_cache_get( 'last_changed', 'posts' ) ); 97 $this->assertSame( $num_queries + 1, $wpdb->num_queries);95 $this->assertSame( $num_queries + 1, get_num_queries() ); 98 96 foreach ( $pages as $page ) { 99 97 $this->assertInstanceOf( 'WP_Post', $page ); … … 105 103 */ 106 104 public function test_get_pages_cache_empty() { 107 global $wpdb;108 109 105 wp_cache_delete( 'last_changed', 'posts' ); 110 106 $this->assertFalse( wp_cache_get( 'last_changed', 'posts' ) ); 111 107 112 $num_queries = $wpdb->num_queries;108 $num_queries = get_num_queries(); 113 109 114 110 $pages = get_pages(); // Database gets queried. 115 111 116 $this->assertSame( $num_queries + 1, $wpdb->num_queries);117 118 $num_queries = $wpdb->num_queries;112 $this->assertSame( $num_queries + 1, get_num_queries() ); 113 114 $num_queries = get_num_queries(); 119 115 120 116 $pages = get_pages(); // Database should not get queried. 121 117 122 $this->assertSame( $num_queries, $wpdb->num_queries);118 $this->assertSame( $num_queries, get_num_queries() ); 123 119 } 124 120 -
trunk/tests/phpunit/tests/post/getPostClass.php
r51568 r55745 122 122 */ 123 123 public function test_taxonomy_classes_hit_cache() { 124 global $wpdb;125 126 124 register_taxonomy( 'wptests_tax', 'post' ); 127 125 wp_set_post_terms( $this->post_id, array( 'foo', 'bar' ), 'wptests_tax' ); … … 132 130 update_meta_cache( 'post', $this->post_id ); 133 131 134 $num_queries = $wpdb->num_queries;132 $num_queries = get_num_queries(); 135 133 136 134 $found = get_post_class( '', $this->post_id ); 137 135 138 $this->assertSame( $num_queries, $wpdb->num_queries);136 $this->assertSame( $num_queries, get_num_queries() ); 139 137 } 140 138 } -
trunk/tests/phpunit/tests/post/query.php
r55562 r55745 556 556 */ 557 557 public function test_posts_pre_query_filter_should_bypass_database_query() { 558 global $wpdb;559 560 558 add_filter( 'posts_pre_query', array( __CLASS__, 'filter_posts_pre_query' ) ); 561 559 562 $num_queries = $wpdb->num_queries;560 $num_queries = get_num_queries(); 563 561 $q = new WP_Query( 564 562 array( … … 570 568 remove_filter( 'posts_pre_query', array( __CLASS__, 'filter_posts_pre_query' ) ); 571 569 572 $this->assertSame( $num_queries, $wpdb->num_queries);570 $this->assertSame( $num_queries, get_num_queries() ); 573 571 $this->assertSame( array( 12345 ), $q->posts ); 574 572 } -
trunk/tests/phpunit/tests/query/commentFeed.php
r53941 r55745 29 29 */ 30 30 public function test_archive_comment_feed() { 31 global $wpdb;32 31 add_filter( 'split_the_query', '__return_false' ); 33 32 $q1 = new WP_Query(); … … 43 42 ); 44 43 $q1->query( $args ); 45 $num_queries = $wpdb->num_queries;44 $num_queries = get_num_queries(); 46 45 $q2 = new WP_Query(); 47 46 $q2->query( $args ); 48 47 $this->assertTrue( $q2->is_comment_feed() ); 49 48 $this->assertFalse( $q2->is_singular() ); 50 $this->assertSame( $num_queries + 1, $wpdb->num_queries);49 $this->assertSame( $num_queries + 1, get_num_queries() ); 51 50 } 52 51 … … 88 87 */ 89 88 public function test_single_comment_feed() { 90 global $wpdb;91 89 $post = get_post( self::$post_ids[0] ); 92 90 … … 104 102 105 103 $q1->query( $args ); 106 $num_queries = $wpdb->num_queries;104 $num_queries = get_num_queries(); 107 105 $q2 = new WP_Query(); 108 106 $q2->query( $args ); … … 110 108 $this->assertTrue( $q2->is_comment_feed() ); 111 109 $this->assertTrue( $q2->is_singular() ); 112 $this->assertSame( $num_queries + 1, $wpdb->num_queries);110 $this->assertSame( $num_queries + 1, get_num_queries() ); 113 111 } 114 112 } -
trunk/tests/phpunit/tests/rest-api/rest-tags-controller.php
r55457 r55745 1337 1337 */ 1338 1338 public function test_object_term_queries_are_cached() { 1339 global $wpdb;1340 1341 1339 $tags = self::factory()->tag->create_many( 2 ); 1342 1340 $p = self::factory()->post->create(); … … 1350 1348 unset( $request, $response ); 1351 1349 1352 $num_queries = $wpdb->num_queries;1350 $num_queries = get_num_queries(); 1353 1351 1354 1352 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); … … 1358 1356 1359 1357 $this->assertSameSets( $found_1, $found_2 ); 1360 $this->assertSame( $num_queries, $wpdb->num_queries);1358 $this->assertSame( $num_queries, get_num_queries() ); 1361 1359 } 1362 1360 -
trunk/tests/phpunit/tests/term/cache.php
r54090 r55745 102 102 103 103 public function test_get_term_should_update_term_cache_when_passed_an_object() { 104 global $wpdb;105 106 104 register_taxonomy( 'wptests_tax', 'post' ); 107 105 $term = self::factory()->term->create( … … 117 115 $this->assertEmpty( wp_cache_get( $term, 'terms' ) ); 118 116 119 $num_queries = $wpdb->num_queries;117 $num_queries = get_num_queries(); 120 118 121 119 // get_term() will only be update the cache if the 'filter' prop is unset. … … 125 123 126 124 // No new queries should have fired. 127 $this->assertSame( $num_queries, $wpdb->num_queries);125 $this->assertSame( $num_queries, get_num_queries() ); 128 126 $this->assertSame( $term_object, $term_object_2 ); 129 127 } 130 128 131 129 public function test_get_term_should_update_term_cache_when_passed_a_valid_term_identifier() { 132 global $wpdb;133 134 130 register_taxonomy( 'wptests_tax', 'post' ); 135 131 $term = self::factory()->term->create( … … 144 140 $this->assertEmpty( wp_cache_get( $term, 'terms' ) ); 145 141 146 $num_queries = $wpdb->num_queries;142 $num_queries = get_num_queries(); 147 143 148 144 // Prime cache. 149 145 $term_object = get_term( $term, 'wptests_tax' ); 150 146 $this->assertNotEmpty( wp_cache_get( $term, 'terms' ) ); 151 $this->assertSame( $num_queries + 1, $wpdb->num_queries);147 $this->assertSame( $num_queries + 1, get_num_queries() ); 152 148 153 149 $term_object_2 = get_term( $term, 'wptests_tax' ); 154 150 155 151 // No new queries should have fired. 156 $this->assertSame( $num_queries + 1, $wpdb->num_queries);152 $this->assertSame( $num_queries + 1, get_num_queries() ); 157 153 $this->assertEquals( $term_object, $term_object_2 ); 158 154 } 159 155 160 156 public function test_get_term_by_should_update_term_cache_when_passed_a_valid_term_identifier() { 161 global $wpdb;162 163 157 register_taxonomy( 'wptests_tax', 'post' ); 164 158 $term = self::factory()->term->create( … … 173 167 $this->assertEmpty( wp_cache_get( $term, 'terms' ) ); 174 168 175 $num_queries = $wpdb->num_queries;169 $num_queries = get_num_queries(); 176 170 177 171 // Prime cache. 178 172 $term_object = get_term_by( 'id', $term, 'wptests_tax' ); 179 173 $this->assertNotEmpty( wp_cache_get( $term, 'terms' ) ); 180 $this->assertSame( $num_queries + 1, $wpdb->num_queries);174 $this->assertSame( $num_queries + 1, get_num_queries() ); 181 175 182 176 $term_object_2 = get_term( $term, 'wptests_tax' ); 183 177 184 178 // No new queries should have fired. 185 $this->assertSame( $num_queries + 1, $wpdb->num_queries);179 $this->assertSame( $num_queries + 1, get_num_queries() ); 186 180 $this->assertEquals( $term_object, $term_object_2 ); 187 181 } … … 191 185 */ 192 186 public function test_get_terms_should_update_cache_for_located_terms() { 193 global $wpdb;194 195 187 register_taxonomy( 'wptests_tax', 'post' ); 196 188 … … 209 201 ); 210 202 211 $num_queries = $wpdb->num_queries;203 $num_queries = get_num_queries(); 212 204 213 205 foreach ( $terms as $term_id ) { … … 215 207 } 216 208 217 $this->assertSame( $num_queries, $wpdb->num_queries);209 $this->assertSame( $num_queries, get_num_queries() ); 218 210 219 211 _unregister_taxonomy( 'wptests_tax' ); … … 243 235 */ 244 236 public function test_get_term_by_slug_cache() { 245 global $wpdb;246 247 237 $term_id = self::factory()->term->create( 248 238 array( … … 254 244 255 245 clean_term_cache( $term_id, 'post_tag' ); 256 $num_queries = $wpdb->num_queries;246 $num_queries = get_num_queries(); 257 247 258 248 $term = get_term_by( 'slug', 'burrito', 'post_tag' ); 259 249 $num_queries = $num_queries + 2; 260 250 $this->assertSame( 'Taco', $term->name ); 261 $this->assertSame( $num_queries, $wpdb->num_queries);251 $this->assertSame( $num_queries, get_num_queries() ); 262 252 263 253 // This should now hit cache. 264 254 $term = get_term_by( 'slug', 'burrito', 'post_tag' ); 265 255 $this->assertSame( 'Taco', $term->name ); 266 $this->assertSame( $num_queries, $wpdb->num_queries);256 $this->assertSame( $num_queries, get_num_queries() ); 267 257 268 258 $this->assertEquals( get_term( $term_id, 'post_tag' ), $term ); 269 $this->assertSame( $num_queries, $wpdb->num_queries);259 $this->assertSame( $num_queries, get_num_queries() ); 270 260 } 271 261 … … 274 264 */ 275 265 public function test_get_term_by_slug_cache_update() { 276 global $wpdb;277 278 266 $term_id = self::factory()->term->create( 279 267 array( … … 285 273 286 274 clean_term_cache( $term_id, 'post_tag' ); 287 $num_queries = $wpdb->num_queries;275 $num_queries = get_num_queries(); 288 276 289 277 $term = get_term_by( 'slug', 'burrito', 'post_tag' ); 290 278 $num_queries = $num_queries + 2; 291 279 $this->assertSame( 'Taco', $term->name ); 292 $this->assertSame( $num_queries, $wpdb->num_queries);280 $this->assertSame( $num_queries, get_num_queries() ); 293 281 294 282 // This should now hit cache. 295 283 $term = get_term_by( 'slug', 'burrito', 'post_tag' ); 296 284 $this->assertSame( 'Taco', $term->name ); 297 $this->assertSame( $num_queries, $wpdb->num_queries);285 $this->assertSame( $num_queries, get_num_queries() ); 298 286 299 287 // Update the tag which invalidates the cache. 300 288 wp_update_term( $term_id, 'post_tag', array( 'name' => 'No Taco' ) ); 301 $num_queries = $wpdb->num_queries;289 $num_queries = get_num_queries(); 302 290 303 291 // This should not hit cache. … … 305 293 $num_queries = $num_queries + 2; 306 294 $this->assertSame( 'No Taco', $term->name ); 307 $this->assertSame( $num_queries, $wpdb->num_queries);295 $this->assertSame( $num_queries, get_num_queries() ); 308 296 } 309 297 … … 312 300 */ 313 301 public function test_get_term_by_name_cache() { 314 global $wpdb;315 316 302 $term_id = self::factory()->term->create( 317 303 array( … … 323 309 324 310 clean_term_cache( $term_id, 'post_tag' ); 325 $num_queries = $wpdb->num_queries;311 $num_queries = get_num_queries(); 326 312 327 313 get_term_by( 'name', 'Burrito', 'post_tag' ); 328 314 $num_queries = $num_queries + 2; 329 $this->assertSame( $num_queries, $wpdb->num_queries);315 $this->assertSame( $num_queries, get_num_queries() ); 330 316 331 317 // This should now hit cache. 332 318 $term = get_term_by( 'name', 'Burrito', 'post_tag' ); 333 $this->assertSame( $num_queries, $wpdb->num_queries);319 $this->assertSame( $num_queries, get_num_queries() ); 334 320 335 321 $this->assertEquals( get_term( $term_id, 'post_tag' ), $term ); 336 $this->assertSame( $num_queries, $wpdb->num_queries);322 $this->assertSame( $num_queries, get_num_queries() ); 337 323 } 338 324 … … 341 327 */ 342 328 public function test_get_term_by_name_cache_update() { 343 global $wpdb;344 345 329 $term_id = self::factory()->term->create( 346 330 array( … … 352 336 353 337 clean_term_cache( $term_id, 'post_tag' ); 354 $num_queries = $wpdb->num_queries;338 $num_queries = get_num_queries(); 355 339 356 340 get_term_by( 'name', 'Burrito', 'post_tag' ); 357 341 $num_queries = $num_queries + 2; 358 $this->assertSame( $num_queries, $wpdb->num_queries);342 $this->assertSame( $num_queries, get_num_queries() ); 359 343 360 344 // This should now hit cache. 361 345 get_term_by( 'name', 'Burrito', 'post_tag' ); 362 $this->assertSame( $num_queries, $wpdb->num_queries);346 $this->assertSame( $num_queries, get_num_queries() ); 363 347 364 348 // Update the tag which invalidates the cache. 365 349 wp_update_term( $term_id, 'post_tag', array( 'slug' => 'taco' ) ); 366 $num_queries = $wpdb->num_queries;350 $num_queries = get_num_queries(); 367 351 368 352 // This should not hit cache. 369 353 get_term_by( 'name', 'burrito', 'post_tag' ); 370 354 $num_queries = $num_queries + 2; 371 $this->assertSame( $num_queries, $wpdb->num_queries);355 $this->assertSame( $num_queries, get_num_queries() ); 372 356 } 373 357 … … 376 360 */ 377 361 public function test_invalidating_term_caches_should_fail_when_invalidation_is_suspended() { 378 global $wpdb;379 380 362 $term_id = self::factory()->term->create( 381 363 array( … … 386 368 387 369 clean_term_cache( $term_id, 'post_tag' ); 388 $num_queries = $wpdb->num_queries;370 $num_queries = get_num_queries(); 389 371 $last_changed = wp_cache_get( 'last_changed', 'terms' ); 390 372 … … 394 376 // Verify the term is cached. 395 377 $term2 = get_term_by( 'name', 'Burrito', 'post_tag' ); 396 $this->assertSame( $num_queries, $wpdb->num_queries);378 $this->assertSame( $num_queries, get_num_queries() ); 397 379 $this->assertEquals( $term1, $term2 ); 398 380 … … 401 383 // Update the tag. 402 384 wp_update_term( $term_id, 'post_tag', array( 'name' => 'Taco' ) ); 403 $num_queries = $wpdb->num_queries;385 $num_queries = get_num_queries(); 404 386 405 387 // Verify that the cached term still matches the initial cached term. 406 388 $term3 = get_term_by( 'name', 'Burrito', 'post_tag' ); 407 $this->assertSame( $num_queries, $wpdb->num_queries);389 $this->assertSame( $num_queries, get_num_queries() ); 408 390 $this->assertEquals( $term1, $term3 ); 409 391 … … 419 401 */ 420 402 public function test_get_term_by_does_not_prime_term_meta_cache() { 421 global $wpdb;422 423 403 $term_id = self::factory()->term->create( 424 404 array( … … 430 410 431 411 clean_term_cache( $term_id, 'post_tag' ); 432 $num_queries = $wpdb->num_queries;412 $num_queries = get_num_queries(); 433 413 434 414 $term = get_term_by( 'name', 'Burrito', 'post_tag' ); … … 436 416 $this->assertInstanceOf( 'WP_Term', $term ); 437 417 $this->assertSame( $term_id, $term->term_id ); 438 $this->assertSame( $num_queries, $wpdb->num_queries);418 $this->assertSame( $num_queries, get_num_queries() ); 439 419 440 420 $term_meta = get_term_meta( $term_id, 'foo', true ); 441 421 $num_queries++; 442 422 $this->assertSame( $term_meta, 'bar' ); 443 $this->assertSame( $num_queries, $wpdb->num_queries);423 $this->assertSame( $num_queries, get_num_queries() ); 444 424 } 445 425 -
trunk/tests/phpunit/tests/term/getTerm.php
r52921 r55745 61 61 62 62 public function test_passing_term_object_should_skip_database_query_when_filter_property_is_empty() { 63 global $wpdb;64 65 63 $term = self::factory()->term->create_and_get( array( 'taxonomy' => 'wptests_tax' ) ); 66 64 clean_term_cache( $term->term_id, 'wptests_tax' ); 67 65 68 $num_queries = $wpdb->num_queries;66 $num_queries = get_num_queries(); 69 67 70 68 unset( $term->filter ); 71 69 $term_a = get_term( $term, 'wptests_tax' ); 72 70 73 $this->assertSame( $num_queries, $wpdb->num_queries);71 $this->assertSame( $num_queries, get_num_queries() ); 74 72 } 75 73 … … 83 81 84 82 public function test_cache_should_be_populated_by_successful_fetch() { 85 global $wpdb;86 87 83 $t = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax' ) ); 88 84 clean_term_cache( $t, 'wptests_tax' ); … … 90 86 // Prime cache. 91 87 $term_a = get_term( $t, 'wptests_tax' ); 92 $num_queries = $wpdb->num_queries;88 $num_queries = get_num_queries(); 93 89 94 90 // Second call shouldn't require a database query. 95 91 $term_b = get_term( $t, 'wptests_tax' ); 96 $this->assertSame( $num_queries, $wpdb->num_queries);92 $this->assertSame( $num_queries, get_num_queries() ); 97 93 $this->assertEquals( $term_a, $term_b ); 98 94 } … … 197 193 */ 198 194 public function test_shared_term_in_cache_should_be_ignored_when_specifying_a_different_taxonomy() { 199 global $wpdb;200 201 195 $terms = $this->generate_shared_terms(); 202 196 203 197 // Prime cache for 'wptests_tax'. 204 198 get_term( $terms[0]['term_id'], 'wptests_tax' ); 205 $num_queries = $wpdb->num_queries;199 $num_queries = get_num_queries(); 206 200 207 201 // Database should be hit again. … … 209 203 $num_queries++; 210 204 211 $this->assertSame( $num_queries, $wpdb->num_queries);205 $this->assertSame( $num_queries, get_num_queries() ); 212 206 $this->assertInstanceOf( 'WP_Term', $found ); 213 207 $this->assertSame( 'wptests_tax_2', $found->taxonomy ); -
trunk/tests/phpunit/tests/term/getTermBy.php
r54090 r55745 112 112 */ 113 113 public function test_should_prime_term_cache() { 114 global $wpdb;115 116 114 register_taxonomy( 'wptests_tax', 'post' ); 117 115 $t = self::factory()->term->create( … … 124 122 clean_term_cache( $t, 'wptests_tax' ); 125 123 126 $num_queries = $wpdb->num_queries;124 $num_queries = get_num_queries(); 127 125 $found = get_term_by( 'slug', 'foo', 'wptests_tax' ); 128 126 $num_queries = $num_queries + 2; … … 130 128 $this->assertInstanceOf( 'WP_Term', $found ); 131 129 $this->assertSame( $t, $found->term_id ); 132 $this->assertSame( $num_queries, $wpdb->num_queries);130 $this->assertSame( $num_queries, get_num_queries() ); 133 131 134 132 // Calls to `get_term()` should now hit cache. 135 133 $found2 = get_term( $t ); 136 134 $this->assertSame( $t, $found->term_id ); 137 $this->assertSame( $num_queries, $wpdb->num_queries);135 $this->assertSame( $num_queries, get_num_queries() ); 138 136 } 139 137 -
trunk/tests/phpunit/tests/term/getTerms.php
r55671 r55745 135 135 */ 136 136 public function test_get_terms_cache() { 137 global $wpdb;138 139 137 $this->set_up_three_posts_and_tags(); 140 138 141 $num_queries = $wpdb->num_queries;139 $num_queries = get_num_queries(); 142 140 143 141 // last_changed and num_queries should bump. … … 146 144 $time1 = wp_cache_get( 'last_changed', 'terms' ); 147 145 $this->assertNotEmpty( $time1 ); 148 $this->assertSame( $num_queries + 2, $wpdb->num_queries);149 150 $num_queries = $wpdb->num_queries;146 $this->assertSame( $num_queries + 2, get_num_queries() ); 147 148 $num_queries = get_num_queries(); 151 149 152 150 // Again. last_changed and num_queries should remain the same. … … 154 152 $this->assertCount( 3, $terms ); 155 153 $this->assertSame( $time1, wp_cache_get( 'last_changed', 'terms' ) ); 156 $this->assertSame( $num_queries, $wpdb->num_queries);154 $this->assertSame( $num_queries, get_num_queries() ); 157 155 } 158 156 … … 168 166 $terms = get_terms( 'post_tag' ); 169 167 $time1 = wp_cache_get( 'last_changed', 'terms' ); 170 $num_queries = $wpdb->num_queries;168 $num_queries = get_num_queries(); 171 169 172 170 // num_queries should bump, last_changed should remain the same. … … 174 172 $this->assertCount( 2, $terms ); 175 173 $this->assertSame( $time1, wp_cache_get( 'last_changed', 'terms' ) ); 176 $this->assertSame( $num_queries + 1, $wpdb->num_queries);177 178 $num_queries = $wpdb->num_queries;174 $this->assertSame( $num_queries + 1, get_num_queries() ); 175 176 $num_queries = get_num_queries(); 179 177 180 178 // Again. last_changed and num_queries should remain the same. … … 182 180 $this->assertCount( 2, $terms ); 183 181 $this->assertSame( $time1, wp_cache_get( 'last_changed', 'terms' ) ); 184 $this->assertSame( $num_queries, $wpdb->num_queries);182 $this->assertSame( $num_queries, get_num_queries() ); 185 183 } 186 184 … … 196 194 $terms = get_terms( 'post_tag' ); 197 195 $time1 = wp_cache_get( 'last_changed', 'terms' ); 198 $num_queries = $wpdb->num_queries;196 $num_queries = get_num_queries(); 199 197 200 198 // Force last_changed to bump. 201 199 wp_delete_term( $terms[0]->term_id, 'post_tag' ); 202 200 203 $num_queries = $wpdb->num_queries;201 $num_queries = get_num_queries(); 204 202 $time2 = wp_cache_get( 'last_changed', 'terms' ); 205 203 $this->assertNotEquals( $time1, $time2 ); … … 209 207 $this->assertCount( 2, $terms ); 210 208 $this->assertSame( $time2, wp_cache_get( 'last_changed', 'terms' ) ); 211 $this->assertSame( $num_queries + 1, $wpdb->num_queries);212 213 $num_queries = $wpdb->num_queries;209 $this->assertSame( $num_queries + 1, get_num_queries() ); 210 211 $num_queries = get_num_queries(); 214 212 215 213 // Again. last_changed and num_queries should remain the same. … … 217 215 $this->assertCount( 2, $terms ); 218 216 $this->assertSame( $time2, wp_cache_get( 'last_changed', 'terms' ) ); 219 $this->assertSame( $num_queries, $wpdb->num_queries);217 $this->assertSame( $num_queries, get_num_queries() ); 220 218 221 219 // @todo Repeat with term insert and update. … … 849 847 */ 850 848 public function test_child_of_should_skip_query_when_specified_parent_is_not_found_in_hierarchy_cache() { 851 global $wpdb;852 853 849 register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) ); 854 850 855 851 $terms = self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax' ) ); 856 852 857 $num_queries = $wpdb->num_queries;853 $num_queries = get_num_queries(); 858 854 859 855 $found = get_terms( … … 866 862 867 863 $this->assertEmpty( $found ); 868 $this->assertSame( $num_queries, $wpdb->num_queries);864 $this->assertSame( $num_queries, get_num_queries() ); 869 865 } 870 866 … … 2474 2470 */ 2475 2471 public function test_parent_should_skip_query_when_specified_parent_is_not_found_in_hierarchy_cache() { 2476 global $wpdb;2477 2478 2472 register_taxonomy( 'wptests_tax', 'post', array( 'hierarchical' => true ) ); 2479 2473 2480 2474 $terms = self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax' ) ); 2481 2475 2482 $num_queries = $wpdb->num_queries;2476 $num_queries = get_num_queries(); 2483 2477 2484 2478 $found = get_terms( … … 2491 2485 2492 2486 $this->assertEmpty( $found ); 2493 $this->assertSame( $num_queries, $wpdb->num_queries);2487 $this->assertSame( $num_queries, get_num_queries() ); 2494 2488 } 2495 2489 … … 2774 2768 ); 2775 2769 2776 $num_queries = $wpdb->num_queries;2770 $num_queries = get_num_queries(); 2777 2771 2778 2772 foreach ( $terms as $t ) { … … 2780 2774 } 2781 2775 2782 $this->assertSame( $num_queries + 1, $wpdb->num_queries);2776 $this->assertSame( $num_queries + 1, get_num_queries() ); 2783 2777 } 2784 2778 … … 2804 2798 ); 2805 2799 2806 $num_queries = $wpdb->num_queries;2800 $num_queries = get_num_queries(); 2807 2801 2808 2802 foreach ( $terms as $t ) { … … 2810 2804 } 2811 2805 2812 $this->assertSame( $num_queries + 3, $wpdb->num_queries);2806 $this->assertSame( $num_queries + 3, get_num_queries() ); 2813 2807 } 2814 2808 … … 2909 2903 ); 2910 2904 2911 $num_queries = $wpdb->num_queries;2905 $num_queries = get_num_queries(); 2912 2906 2913 2907 $found = get_terms( … … 2919 2913 ); 2920 2914 2921 $this->assertSame( $num_queries, $wpdb->num_queries);2915 $this->assertSame( $num_queries, get_num_queries() ); 2922 2916 2923 2917 $this->assertNotEmpty( $found ); … … 2932 2926 */ 2933 2927 public function test_should_prime_individual_term_cache_when_fields_is_all() { 2934 global $wpdb;2935 2936 2928 register_taxonomy( 'wptests_tax', 'post' ); 2937 2929 $terms = self::factory()->term->create_many( 2, array( 'taxonomy' => 'wptests_tax' ) ); … … 2945 2937 ); 2946 2938 2947 $num_queries = $wpdb->num_queries;2939 $num_queries = get_num_queries(); 2948 2940 $term0 = get_term( $terms[0] ); 2949 $this->assertSame( $num_queries, $wpdb->num_queries);2941 $this->assertSame( $num_queries, get_num_queries() ); 2950 2942 2951 2943 } -
trunk/tests/phpunit/tests/term/getTheTerms.php
r52010 r55745 198 198 */ 199 199 public function test_uncached_terms_should_be_primed_with_a_single_query() { 200 global $wpdb;201 202 200 register_taxonomy( 'wptests_tax', 'post' ); 203 201 … … 211 209 clean_term_cache( array( $terms[0], $terms[1] ), 'wptests_tax', false ); 212 210 213 $num_queries = $wpdb->num_queries;211 $num_queries = get_num_queries(); 214 212 $found = get_the_terms( self::$post_ids[0], 'wptests_tax' ); 215 213 … … 217 215 218 216 $num_queries++; 219 $this->assertSame( $num_queries, $wpdb->num_queries);217 $this->assertSame( $num_queries, get_num_queries() ); 220 218 221 219 } -
trunk/tests/phpunit/tests/term/isObjectInTerm.php
r55365 r55745 136 136 */ 137 137 public function test_should_populate_and_hit_relationships_cache() { 138 global $wpdb;139 140 138 register_taxonomy( 'wptests_tax', 'post' ); 141 139 $terms = self::factory()->term->create_many( 2, array( 'taxonomy' => 'wptests_tax' ) ); … … 144 142 wp_set_object_terms( $o, $terms[0], 'wptests_tax' ); 145 143 146 $num_queries = $wpdb->num_queries;144 $num_queries = get_num_queries(); 147 145 $this->assertTrue( is_object_in_term( $o, 'wptests_tax', $terms[0] ) ); 148 146 $num_queries = $num_queries + 2; 149 $this->assertSame( $num_queries, $wpdb->num_queries);147 $this->assertSame( $num_queries, get_num_queries() ); 150 148 151 149 $this->assertFalse( is_object_in_term( $o, 'wptests_tax', $terms[1] ) ); 152 $this->assertSame( $num_queries, $wpdb->num_queries);150 $this->assertSame( $num_queries, get_num_queries() ); 153 151 } 154 152 … … 157 155 */ 158 156 public function test_should_not_be_fooled_by_a_stale_relationship_cache() { 159 global $wpdb;160 161 157 register_taxonomy( 'wptests_tax', 'post' ); 162 158 $terms = self::factory()->term->create_many( 2, array( 'taxonomy' => 'wptests_tax' ) ); … … 165 161 wp_set_object_terms( $o, $terms[0], 'wptests_tax' ); 166 162 167 $num_queries = $wpdb->num_queries;163 $num_queries = get_num_queries(); 168 164 $this->assertTrue( is_object_in_term( $o, 'wptests_tax', $terms[0] ) ); 169 165 $num_queries = $num_queries + 2; 170 $this->assertSame( $num_queries, $wpdb->num_queries);166 $this->assertSame( $num_queries, get_num_queries() ); 171 167 172 168 wp_set_object_terms( $o, $terms[1], 'wptests_tax' ); 173 169 174 $num_queries = $wpdb->num_queries;170 $num_queries = get_num_queries(); 175 171 $this->assertTrue( is_object_in_term( $o, 'wptests_tax', $terms[1] ) ); 176 172 $num_queries = $num_queries + 2; 177 $this->assertSame( $num_queries, $wpdb->num_queries);173 $this->assertSame( $num_queries, get_num_queries() ); 178 174 } 179 175 -
trunk/tests/phpunit/tests/term/meta.php
r55671 r55745 115 115 116 116 public function test_term_meta_should_be_lazy_loaded_for_all_terms_in_wp_query_loop() { 117 global $wpdb;118 119 117 $p = self::factory()->post->create( array( 'post_status' => 'publish' ) ); 120 118 … … 140 138 141 139 // First request will hit the database. 142 $num_queries = $wpdb->num_queries;140 $num_queries = get_num_queries(); 143 141 $this->assertSame( 'bar', get_term_meta( $terms[0], 'foo', true ) ); 144 142 $num_queries++; 145 $this->assertSame( $num_queries, $wpdb->num_queries);143 $this->assertSame( $num_queries, get_num_queries() ); 146 144 147 145 // Second and third requests should be in cache. 148 146 $this->assertSame( 'bar', get_term_meta( $terms[1], 'foo', true ) ); 149 147 $this->assertSame( 'bar', get_term_meta( $terms[2], 'foo', true ) ); 150 $this->assertSame( $num_queries, $wpdb->num_queries);148 $this->assertSame( $num_queries, get_num_queries() ); 151 149 152 150 // Querying a term not primed should result in a hit. 153 151 $num_queries++; 154 152 $this->assertSame( 'bar', get_term_meta( $orphan_term, 'foo', true ) ); 155 $this->assertSame( $num_queries, $wpdb->num_queries);153 $this->assertSame( $num_queries, get_num_queries() ); 156 154 } 157 155 } … … 187 185 */ 188 186 public function test_lazy_load_term_meta_false() { 189 global $wpdb;190 191 187 $p = self::factory()->post->create( array( 'post_status' => 'publish' ) ); 192 188 … … 211 207 212 208 // Requests will hit the database. 213 $num_queries = $wpdb->num_queries;209 $num_queries = get_num_queries(); 214 210 $this->assertSame( 'bar', get_term_meta( $terms[0], 'foo', true ) ); 215 211 $num_queries++; 216 $this->assertSame( $num_queries, $wpdb->num_queries);212 $this->assertSame( $num_queries, get_num_queries() ); 217 213 218 214 $this->assertSame( 'bar', get_term_meta( $terms[1], 'foo', true ) ); 219 215 $num_queries++; 220 $this->assertSame( $num_queries, $wpdb->num_queries);216 $this->assertSame( $num_queries, get_num_queries() ); 221 217 } 222 218 } -
trunk/tests/phpunit/tests/term/query.php
r55671 r55745 457 457 */ 458 458 public function test_count_query_should_be_cached() { 459 global $wpdb;460 461 459 register_taxonomy( 'wptests_tax_1', 'post' ); 462 460 … … 473 471 $this->assertEquals( 2, $count ); 474 472 475 $num_queries = $wpdb->num_queries;473 $num_queries = get_num_queries(); 476 474 477 475 $query = new WP_Term_Query( … … 484 482 $count = $query->get_terms(); 485 483 $this->assertEquals( 2, $count ); 486 $this->assertSame( $num_queries, $wpdb->num_queries);484 $this->assertSame( $num_queries, get_num_queries() ); 487 485 } 488 486 … … 804 802 */ 805 803 public function test_terms_pre_query_filter_should_bypass_database_query() { 806 global $wpdb;807 808 804 add_filter( 'terms_pre_query', array( __CLASS__, 'filter_terms_pre_query' ), 10, 2 ); 809 805 810 $num_queries = $wpdb->num_queries;806 $num_queries = get_num_queries(); 811 807 812 808 $q = new WP_Term_Query(); … … 820 816 821 817 // Make sure no queries were executed. 822 $this->assertSame( $num_queries, $wpdb->num_queries);818 $this->assertSame( $num_queries, get_num_queries() ); 823 819 824 820 // We manually inserted a non-existing term and overrode the results with it. -
trunk/tests/phpunit/tests/term/termExists.php
r52921 r55745 321 321 */ 322 322 public function test_term_exists_caching() { 323 global $wpdb;324 323 register_taxonomy( 'wptests_tax', 'post' ); 325 324 … … 332 331 ); 333 332 $this->assertEquals( $t, term_exists( $slug ) ); 334 $num_queries = $wpdb->num_queries;333 $num_queries = get_num_queries(); 335 334 $this->assertEquals( $t, term_exists( $slug ) ); 336 $this->assertSame( $num_queries, $wpdb->num_queries);335 $this->assertSame( $num_queries, get_num_queries() ); 337 336 338 337 $this->assertTrue( wp_delete_term( $t, 'wptests_tax' ) ); 339 $num_queries = $wpdb->num_queries;338 $num_queries = get_num_queries(); 340 339 $this->assertNull( term_exists( $slug ) ); 341 $this->assertSame( $num_queries + 2, $wpdb->num_queries);340 $this->assertSame( $num_queries + 2, get_num_queries() ); 342 341 343 342 // Clean up. … … 350 349 */ 351 350 public function test_term_exists_caching_suspend_cache_invalidation() { 352 global $wpdb;353 351 register_taxonomy( 'wptests_tax', 'post' ); 354 352 … … 363 361 364 362 $this->assertEquals( $t, term_exists( $slug ) ); 365 $num_queries = $wpdb->num_queries;363 $num_queries = get_num_queries(); 366 364 $this->assertEquals( $t, term_exists( $slug ) ); 367 $this->assertSame( $num_queries + 1, $wpdb->num_queries);365 $this->assertSame( $num_queries + 1, get_num_queries() ); 368 366 wp_suspend_cache_invalidation( false ); 369 367 -
trunk/tests/phpunit/tests/term/wpGetObjectTerms.php
r55671 r55745 617 617 */ 618 618 public function test_termmeta_cache_should_be_lazy_loaded_by_default() { 619 global $wpdb;620 621 619 register_taxonomy( 'wptests_tax', 'post' ); 622 620 $terms = self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax' ) ); … … 630 628 $found = wp_get_object_terms( $p, 'wptests_tax' ); 631 629 632 $num_queries = $wpdb->num_queries;630 $num_queries = get_num_queries(); 633 631 634 632 foreach ( $terms as $t ) { … … 636 634 } 637 635 638 $this->assertSame( $num_queries + 1, $wpdb->num_queries);636 $this->assertSame( $num_queries + 1, get_num_queries() ); 639 637 } 640 638 … … 643 641 */ 644 642 public function test_termmeta_cache_should_not_be_primed_when_update_term_meta_cache_is_false() { 645 global $wpdb;646 647 643 register_taxonomy( 'wptests_tax', 'post' ); 648 644 $terms = self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax' ) ); … … 662 658 ); 663 659 664 $num_queries = $wpdb->num_queries;660 $num_queries = get_num_queries(); 665 661 666 662 foreach ( $terms as $t ) { … … 668 664 } 669 665 670 $this->assertSame( $num_queries + 3, $wpdb->num_queries);666 $this->assertSame( $num_queries + 3, get_num_queries() ); 671 667 } 672 668 … … 675 671 */ 676 672 public function test_termmeta_cache_should_be_primed_when_fields_is_all_with_object_id() { 677 global $wpdb;678 679 673 register_taxonomy( 'wptests_tax', 'post' ); 680 674 $terms = self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax' ) ); … … 695 689 ); 696 690 697 $num_queries = $wpdb->num_queries;691 $num_queries = get_num_queries(); 698 692 699 693 foreach ( $terms as $t ) { … … 701 695 } 702 696 703 $this->assertSame( $num_queries + 1, $wpdb->num_queries);697 $this->assertSame( $num_queries + 1, get_num_queries() ); 704 698 } 705 699 … … 708 702 */ 709 703 public function test_termmeta_cache_should_be_primed_when_fields_is_ids() { 710 global $wpdb;711 712 704 register_taxonomy( 'wptests_tax', 'post' ); 713 705 $terms = self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax' ) ); … … 728 720 ); 729 721 730 $num_queries = $wpdb->num_queries;722 $num_queries = get_num_queries(); 731 723 732 724 foreach ( $terms as $t ) { … … 734 726 } 735 727 736 $this->assertSame( $num_queries + 1, $wpdb->num_queries);728 $this->assertSame( $num_queries + 1, get_num_queries() ); 737 729 } 738 730 … … 817 809 */ 818 810 public function test_should_prime_cache_for_found_terms() { 819 global $wpdb;820 821 811 register_taxonomy( 'wptests_tax', 'post' ); 822 812 $p = self::factory()->post->create(); … … 832 822 ); 833 823 834 $num_queries = $wpdb->num_queries;824 $num_queries = get_num_queries(); 835 825 $term = get_term( $t ); 836 $this->assertSame( $num_queries, $wpdb->num_queries);826 $this->assertSame( $num_queries, get_num_queries() ); 837 827 } 838 828 … … 866 856 */ 867 857 public function test_term_cache_should_be_primed_for_all_taxonomies() { 868 global $wpdb;869 870 858 register_taxonomy( 'wptests_tax1', 'post' ); 871 859 register_taxonomy( 'wptests_tax2', 'post' ); … … 889 877 $this->assertSameSets( array( $t1, $t2 ), wp_list_pluck( $found, 'term_id' ) ); 890 878 891 $num_queries = $wpdb->num_queries;879 $num_queries = get_num_queries(); 892 880 $term1 = get_term( $t1 ); 893 881 $term2 = get_term( $t2 ); 894 $this->assertSame( $num_queries, $wpdb->num_queries);882 $this->assertSame( $num_queries, get_num_queries() ); 895 883 } 896 884 -
trunk/tests/phpunit/tests/user/query.php
r55562 r55745 1721 1721 */ 1722 1722 public function test_users_pre_query_filter_should_bypass_database_query() { 1723 global $wpdb;1724 1725 1723 add_filter( 'users_pre_query', array( __CLASS__, 'filter_users_pre_query' ), 10, 2 ); 1726 1724 1727 $num_queries = $wpdb->num_queries;1725 $num_queries = get_num_queries(); 1728 1726 $q = new WP_User_Query( 1729 1727 array( … … 1735 1733 1736 1734 // Make sure no queries were executed. 1737 $this->assertSame( $num_queries, $wpdb->num_queries);1735 $this->assertSame( $num_queries, get_num_queries() ); 1738 1736 1739 1737 // We manually inserted a non-existing user and overrode the results with it.
Note: See TracChangeset
for help on using the changeset viewer.