Changeset 55749 for trunk/tests/phpunit/tests/comment/metaCache.php
- Timestamp:
- 05/11/2023 12:25:51 PM (3 years ago)
- File:
-
- 1 edited
-
trunk/tests/phpunit/tests/comment/metaCache.php (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/comment/metaCache.php
r55745 r55749 12 12 * @covers ::update_comment_meta 13 13 */ 14 public function test_update_comment_meta_cache_should_default_to_ true() {14 public function test_update_comment_meta_cache_should_default_to_lazy_loading() { 15 15 $p = self::factory()->post->create( array( 'post_status' => 'publish' ) ); 16 16 $comment_ids = self::factory()->comment->create_post_comments( $p, 3 ); … … 23 23 clean_comment_cache( $comment_ids ); 24 24 25 $q = new WP_Comment_Query( 25 $num_queries = get_num_queries(); 26 $q = new WP_Comment_Query( 26 27 array( 27 28 'post_ID' => $p, … … 29 30 ); 30 31 32 $this->assertSame( 2, get_num_queries() - $num_queries, 'Querying comments is expected to make two queries' ); 33 31 34 $num_queries = get_num_queries(); 32 35 foreach ( $comment_ids as $cid ) { … … 34 37 } 35 38 36 $this->assertSame( $num_queries, get_num_queries());37 } 38 39 /** 40 * @ticket 1689441 * 42 * @covers :: update_comment_meta43 */ 44 public function test_update_comment_meta_cache_ true() {39 $this->assertSame( 1, get_num_queries() - $num_queries, 'Querying comments is expected to make two queries' ); 40 } 41 42 /** 43 * @ticket 57801 44 * 45 * @covers ::wp_lazyload_comment_meta 46 */ 47 public function test_update_comment_meta_cache_should_default_to_lazy_loading_fields_id() { 45 48 $p = self::factory()->post->create( array( 'post_status' => 'publish' ) ); 46 49 $comment_ids = self::factory()->comment->create_post_comments( $p, 3 ); … … 53 56 clean_comment_cache( $comment_ids ); 54 57 55 $q = new WP_Comment_Query( 58 $num_queries = get_num_queries(); 59 $q = new WP_Comment_Query( 60 array( 61 'post_ID' => $p, 62 'fields' => 'ids', 63 ) 64 ); 65 66 $this->assertSame( 1, get_num_queries() - $num_queries, 'Querying comments is expected to make two queries' ); 67 68 $num_queries = get_num_queries(); 69 foreach ( $comment_ids as $cid ) { 70 get_comment_meta( $cid, 'foo', 'bar' ); 71 } 72 73 $this->assertSame( 1, get_num_queries() - $num_queries, 'Comment meta is expected to be lazy loaded' ); 74 } 75 76 /** 77 * @ticket 16894 78 * 79 * @covers ::update_comment_meta 80 */ 81 public function test_update_comment_meta_cache_true() { 82 $p = self::factory()->post->create( array( 'post_status' => 'publish' ) ); 83 $comment_ids = self::factory()->comment->create_post_comments( $p, 3 ); 84 85 foreach ( $comment_ids as $cid ) { 86 update_comment_meta( $cid, 'foo', 'bar' ); 87 } 88 89 // Clear comment cache, just in case. 90 clean_comment_cache( $comment_ids ); 91 92 $num_queries = get_num_queries(); 93 $q = new WP_Comment_Query( 56 94 array( 57 95 'post_ID' => $p, … … 59 97 ) 60 98 ); 99 $this->assertSame( 2, get_num_queries() - $num_queries, 'Comments should be queries and primed in two database queries' ); 61 100 62 101 $num_queries = get_num_queries(); … … 65 104 } 66 105 67 $this->assertSame( $num_queries, get_num_queries() ); 106 $this->assertSame( 1, get_num_queries() - $num_queries, 'Comment meta should be loaded in one database query' ); 107 } 108 109 /** 110 * @ticket 57801 111 * 112 * @covers ::update_comment_meta 113 */ 114 public function test_update_comment_meta_cache_true_multiple() { 115 $posts = self::factory()->post->create_many( 3 ); 116 $all_comment_ids = array(); 117 foreach ( $posts as $p ) { 118 $comment_ids = self::factory()->comment->create_post_comments( $p, 3 ); 119 120 foreach ( $comment_ids as $cid ) { 121 update_comment_meta( $cid, 'foo', 'bar' ); 122 $all_comment_ids[] = $cid; 123 } 124 125 $num_queries = get_num_queries(); 126 $q = new WP_Comment_Query( 127 array( 128 'post_ID' => $p, 129 'update_comment_meta_cache' => true, 130 ) 131 ); 132 $this->assertSame( 1, get_num_queries() - $num_queries, 'Comment query should only add one query' ); 133 } 134 135 $filter = new MockAction(); 136 add_filter( 'update_comment_metadata_cache', array( $filter, 'filter' ), 10, 2 ); 137 $num_queries = get_num_queries(); 138 get_comment_meta( $comment_ids[0], 'foo', 'bar' ); 139 140 $this->assertSame( 1, get_num_queries() - $num_queries, 'Comment meta should be loaded in one database query' ); 141 $args = $filter->get_args(); 142 $first = reset( $args ); 143 $prime_comment_ids = end( $first ); 144 $this->assertSameSets( $prime_comment_ids, $all_comment_ids, 'All comment meta should be loaded all at once' ); 68 145 } 69 146 … … 93 170 } 94 171 95 $this->assertSame( $num_queries + 3, get_num_queries());172 $this->assertSame( 3, get_num_queries() - $num_queries ); 96 173 } 97 174 … … 121 198 $num_queries = get_num_queries(); 122 199 get_comment_meta( $comment_ids[0], 'sauce' ); 123 $this->assertSame( $num_queries + 1, get_num_queries());200 $this->assertSame( 1, get_num_queries() - $num_queries ); 124 201 125 202 // Second and third requests should be in cache. 126 203 get_comment_meta( $comment_ids[1], 'sauce' ); 127 204 get_comment_meta( $comment_ids[2], 'sauce' ); 128 $this->assertSame( $num_queries + 1, get_num_queries());205 $this->assertSame( 1, get_num_queries() - $num_queries ); 129 206 } 130 207 } … … 135 212 * 136 213 * @covers ::get_comment_meta 214 * @covers ::wp_lazyload_comment_meta 137 215 */ 138 216 public function test_comment_meta_should_be_lazy_loaded_in_comment_feed_queries() { … … 183 261 * 184 262 * @covers ::get_comment_meta 263 * @covers ::wp_lazyload_comment_meta 185 264 */ 186 265 public function test_comment_meta_should_be_lazy_loaded_in_single_post_comment_feed_queries() {
Note: See TracChangeset
for help on using the changeset viewer.