Changeset 42343 for trunk/tests/phpunit/tests/comment/getPageOfComment.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/comment/getPageOfComment.php
r39663 r42343 29 29 $comment_first = self::factory()->comment->create_post_comments( $p, 1, array( 'comment_date' => '2013-09-14 00:00:00' ) ); 30 30 31 $this->assertEquals( 4, get_page_of_comment( $comment_last[0], array( 'per_page' =>3 ) ) );32 $this->assertEquals( 2, get_page_of_comment( $comment_last[0], array( 'per_page' => 10 ) ) );33 34 $this->assertEquals( 1, get_page_of_comment( $comment_first[0], array( 'per_page' => 3 ) ) );31 $this->assertEquals( 4, get_page_of_comment( $comment_last[0], array( 'per_page' => 3 ) ) ); 32 $this->assertEquals( 2, get_page_of_comment( $comment_last[0], array( 'per_page' => 10 ) ) ); 33 34 $this->assertEquals( 1, get_page_of_comment( $comment_first[0], array( 'per_page' => 3 ) ) ); 35 35 $this->assertEquals( 1, get_page_of_comment( $comment_first[0], array( 'per_page' => 10 ) ) ); 36 36 } 37 37 38 38 public function test_type_pings() { 39 $p = self::factory()->post->create();39 $p = self::factory()->post->create(); 40 40 $now = time(); 41 41 42 42 $trackbacks = array(); 43 43 for ( $i = 0; $i <= 3; $i++ ) { 44 $trackbacks[ $i ] = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_type' => 'trackback', 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now ) ) ); 45 $now -= 10 * $i; 44 $trackbacks[ $i ] = self::factory()->comment->create( 45 array( 46 'comment_post_ID' => $p, 47 'comment_type' => 'trackback', 48 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now ), 49 ) 50 ); 51 $now -= 10 * $i; 46 52 } 47 53 48 54 $pingbacks = array(); 49 55 for ( $i = 0; $i <= 6; $i++ ) { 50 $pingbacks[ $i ] = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_type' => 'pingback', 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now ) ) ); 51 $now -= 10 * $i; 52 } 53 54 $this->assertEquals( 2, get_page_of_comment( $trackbacks[0], array( 'per_page' => 2, 'type' => 'trackback' ) ) ); 55 $this->assertEquals( 3, get_page_of_comment( $pingbacks[0], array( 'per_page' => 2, 'type' => 'pingback' ) ) ); 56 $this->assertEquals( 5, get_page_of_comment( $trackbacks[0], array( 'per_page' => 2, 'type' => 'pings' ) ) ); 56 $pingbacks[ $i ] = self::factory()->comment->create( 57 array( 58 'comment_post_ID' => $p, 59 'comment_type' => 'pingback', 60 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now ), 61 ) 62 ); 63 $now -= 10 * $i; 64 } 65 66 $this->assertEquals( 67 2, get_page_of_comment( 68 $trackbacks[0], array( 69 'per_page' => 2, 70 'type' => 'trackback', 71 ) 72 ) 73 ); 74 $this->assertEquals( 75 3, get_page_of_comment( 76 $pingbacks[0], array( 77 'per_page' => 2, 78 'type' => 'pingback', 79 ) 80 ) 81 ); 82 $this->assertEquals( 83 5, get_page_of_comment( 84 $trackbacks[0], array( 85 'per_page' => 2, 86 'type' => 'pings', 87 ) 88 ) 89 ); 57 90 } 58 91 … … 70 103 71 104 $num_queries = $wpdb->num_queries; 72 $page_2 = get_page_of_comment( $c, array( 'per_page' => 3 ) );105 $page_2 = get_page_of_comment( $c, array( 'per_page' => 3 ) ); 73 106 74 107 $this->assertSame( $page_1, $page_2 ); … … 82 115 global $wpdb; 83 116 84 $p = self::factory()->post->create(); 85 $comment = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_type' => 'comment' ) ); 86 87 $now = time(); 117 $p = self::factory()->post->create(); 118 $comment = self::factory()->comment->create( 119 array( 120 'comment_post_ID' => $p, 121 'comment_type' => 'comment', 122 ) 123 ); 124 125 $now = time(); 88 126 $trackbacks = array(); 89 127 for ( $i = 0; $i <= 5; $i++ ) { 90 $trackbacks[ $i ] = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_type' => 'trackback', 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - ( 10 * $i ) ) ) ); 128 $trackbacks[ $i ] = self::factory()->comment->create( 129 array( 130 'comment_post_ID' => $p, 131 'comment_type' => 'trackback', 132 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - ( 10 * $i ) ), 133 ) 134 ); 91 135 } 92 136 93 137 // Prime cache for trackbacks. 94 $page_trackbacks = get_page_of_comment( $trackbacks[1], array( 'per_page' => 3, 'type' => 'trackback' ) ); 138 $page_trackbacks = get_page_of_comment( 139 $trackbacks[1], array( 140 'per_page' => 3, 141 'type' => 'trackback', 142 ) 143 ); 95 144 $this->assertEquals( 2, $page_trackbacks ); 96 145 97 $num_queries = $wpdb->num_queries; 98 $page_comments = get_page_of_comment( $comment, array( 'per_page' => 3, 'type' => 'comment' ) ); 146 $num_queries = $wpdb->num_queries; 147 $page_comments = get_page_of_comment( 148 $comment, array( 149 'per_page' => 3, 150 'type' => 'comment', 151 ) 152 ); 99 153 $this->assertEquals( 1, $page_comments ); 100 154 … … 107 161 public function test_cache_should_be_invalidated_when_comment_is_approved() { 108 162 $p = self::factory()->post->create(); 109 $c = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_approved' => 0 ) ); 163 $c = self::factory()->comment->create( 164 array( 165 'comment_post_ID' => $p, 166 'comment_approved' => 0, 167 ) 168 ); 110 169 111 170 // Prime cache. … … 156 215 $now = time(); 157 216 158 $p = self::factory()->post->create(); 159 $c1 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now ) ) ); 160 $c2 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 20 ) ) ); 161 $c3 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_approved' => 0, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 30 ) ) ); 217 $p = self::factory()->post->create(); 218 $c1 = self::factory()->comment->create( 219 array( 220 'comment_post_ID' => $p, 221 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now ), 222 ) 223 ); 224 $c2 = self::factory()->comment->create( 225 array( 226 'comment_post_ID' => $p, 227 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 20 ), 228 ) 229 ); 230 $c3 = self::factory()->comment->create( 231 array( 232 'comment_post_ID' => $p, 233 'comment_approved' => 0, 234 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 30 ), 235 ) 236 ); 162 237 163 238 $this->assertEquals( 1, get_page_of_comment( $c1, array( 'per_page' => 2 ) ) ); … … 174 249 $posts = self::factory()->post->create_many( 2 ); 175 250 176 $now = time();251 $now = time(); 177 252 $comments_0 = $comments_1 = array(); 178 253 for ( $i = 0; $i < 5; $i++ ) { 179 $comments_0[] = self::factory()->comment->create( array( 'comment_post_ID' => $posts[0], 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - ( $i * 60 ) ) ) ); 180 $comments_1[] = self::factory()->comment->create( array( 'comment_post_ID' => $posts[1], 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - ( $i * 60 ) ) ) ); 254 $comments_0[] = self::factory()->comment->create( 255 array( 256 'comment_post_ID' => $posts[0], 257 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - ( $i * 60 ) ), 258 ) 259 ); 260 $comments_1[] = self::factory()->comment->create( 261 array( 262 'comment_post_ID' => $posts[1], 263 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - ( $i * 60 ) ), 264 ) 265 ); 181 266 } 182 267 … … 194 279 $post = self::factory()->post->create(); 195 280 196 $now = time();281 $now = time(); 197 282 $comment_parents = $comment_children = array(); 198 283 for ( $i = 0; $i < 5; $i++ ) { 199 $parent = self::factory()->comment->create( array( 'comment_post_ID' => $post, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - ( $i * 60 ) ) ) ); 284 $parent = self::factory()->comment->create( 285 array( 286 'comment_post_ID' => $post, 287 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - ( $i * 60 ) ), 288 ) 289 ); 200 290 $comment_parents[ $i ] = $parent; 201 291 202 $child = self::factory()->comment->create( array( 'comment_post_ID' => $post, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - ( $i * 59 ) ), 'comment_parent' => $parent ) ); 292 $child = self::factory()->comment->create( 293 array( 294 'comment_post_ID' => $post, 295 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - ( $i * 59 ) ), 296 'comment_parent' => $parent, 297 ) 298 ); 203 299 $comment_children[ $i ] = $child; 204 300 } … … 208 304 209 305 $args = array( 210 'per_page' => 3,306 'per_page' => 3, 211 307 'max_depth' => 2, 212 308 ); … … 229 325 $now = time(); 230 326 231 $p = self::factory()->post->create(); 232 $c1 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now ) ) ); 233 $c2 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 20 ) ) ); 234 $c3 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 30 ) ) ); 327 $p = self::factory()->post->create(); 328 $c1 = self::factory()->comment->create( 329 array( 330 'comment_post_ID' => $p, 331 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now ), 332 ) 333 ); 334 $c2 = self::factory()->comment->create( 335 array( 336 'comment_post_ID' => $p, 337 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 20 ), 338 ) 339 ); 340 $c3 = self::factory()->comment->create( 341 array( 342 'comment_post_ID' => $p, 343 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 30 ), 344 ) 345 ); 235 346 236 347 update_option( 'page_comments', 1 ); … … 247 358 $now = time(); 248 359 249 $p = self::factory()->post->create(); 250 $c1 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now ) ) ); 251 $c2 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 20 ) ) ); 252 $c3 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 30 ) ) ); 253 $c4 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 40 ) ) ); 360 $p = self::factory()->post->create(); 361 $c1 = self::factory()->comment->create( 362 array( 363 'comment_post_ID' => $p, 364 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now ), 365 ) 366 ); 367 $c2 = self::factory()->comment->create( 368 array( 369 'comment_post_ID' => $p, 370 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 20 ), 371 ) 372 ); 373 $c3 = self::factory()->comment->create( 374 array( 375 'comment_post_ID' => $p, 376 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 30 ), 377 ) 378 ); 379 $c4 = self::factory()->comment->create( 380 array( 381 'comment_post_ID' => $p, 382 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 40 ), 383 ) 384 ); 254 385 255 386 update_option( 'comment_order', 'desc' ); … … 267 398 $now = time(); 268 399 269 $p = self::factory()->post->create(); 270 $c1 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now ) ) ); 271 $c2 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 20 ) ) ); 272 $c3 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 30 ) ) ); 273 $c4 = self::factory()->comment->create( array( 'comment_post_ID' => $p, 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 40 ) ) ); 400 $p = self::factory()->post->create(); 401 $c1 = self::factory()->comment->create( 402 array( 403 'comment_post_ID' => $p, 404 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now ), 405 ) 406 ); 407 $c2 = self::factory()->comment->create( 408 array( 409 'comment_post_ID' => $p, 410 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 20 ), 411 ) 412 ); 413 $c3 = self::factory()->comment->create( 414 array( 415 'comment_post_ID' => $p, 416 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 30 ), 417 ) 418 ); 419 $c4 = self::factory()->comment->create( 420 array( 421 'comment_post_ID' => $p, 422 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - 40 ), 423 ) 424 ); 274 425 275 426 update_option( 'default_comment_page', 'newest' );
Note: See TracChangeset
for help on using the changeset viewer.