Changeset 55745 for trunk/tests/phpunit/tests/comment/metaCache.php
- Timestamp:
- 05/11/2023 10:05:51 AM (3 years ago)
- File:
-
- 1 edited
-
trunk/tests/phpunit/tests/comment/metaCache.php (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.