Changeset 42343 for trunk/tests/phpunit/tests/post/getPages.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
-
trunk/tests/phpunit/tests/post/getPages.php (modified) (30 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/post/getPages.php
r41849 r42343 23 23 $this->assertEquals( 3, count( $pages ) ); 24 24 $this->assertNotEmpty( $time1 = wp_cache_get( 'last_changed', 'posts' ) ); 25 $num_queries = $wpdb->num_queries;26 foreach ( $pages as $page ) 25 $num_queries = $wpdb->num_queries; 26 foreach ( $pages as $page ) { 27 27 $this->assertInstanceOf( 'WP_Post', $page ); 28 } 28 29 29 30 // Again. num_queries and last_changed should remain the same. … … 32 33 $this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) ); 33 34 $this->assertEquals( $num_queries, $wpdb->num_queries ); 34 foreach ( $pages as $page ) 35 foreach ( $pages as $page ) { 35 36 $this->assertInstanceOf( 'WP_Post', $page ); 37 } 36 38 37 39 // Again with different args. last_changed should not increment because of … … 41 43 $this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) ); 42 44 $this->assertEquals( $num_queries + 1, $wpdb->num_queries ); 43 foreach ( $pages as $page ) 45 foreach ( $pages as $page ) { 44 46 $this->assertInstanceOf( 'WP_Post', $page ); 47 } 45 48 46 49 $num_queries = $wpdb->num_queries; … … 51 54 $this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) ); 52 55 $this->assertEquals( $num_queries, $wpdb->num_queries ); 53 foreach ( $pages as $page ) 56 foreach ( $pages as $page ) { 54 57 $this->assertInstanceOf( 'WP_Post', $page ); 58 } 55 59 56 60 // Do the first query again. The interim queries should not affect it. … … 59 63 $this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) ); 60 64 $this->assertEquals( $num_queries, $wpdb->num_queries ); 61 foreach ( $pages as $page ) 65 foreach ( $pages as $page ) { 62 66 $this->assertInstanceOf( 'WP_Post', $page ); 67 } 63 68 64 69 // Force last_changed to increment. … … 73 78 $this->assertEquals( $time2, wp_cache_get( 'last_changed', 'posts' ) ); 74 79 $this->assertEquals( $num_queries + 1, $wpdb->num_queries ); 75 foreach ( $pages as $page ) 80 foreach ( $pages as $page ) { 76 81 $this->assertInstanceOf( 'WP_Post', $page ); 82 } 77 83 78 84 $last_changed = wp_cache_get( 'last_changed', 'posts' ); … … 84 90 $this->assertGreaterThan( $old_changed_float, $new_changed_float ); 85 91 86 $num_queries = $wpdb->num_queries;92 $num_queries = $wpdb->num_queries; 87 93 $last_changed = wp_cache_get( 'last_changed', 'posts' ); 88 94 … … 92 98 $this->assertEquals( $last_changed, wp_cache_get( 'last_changed', 'posts' ) ); 93 99 $this->assertEquals( $num_queries + 1, $wpdb->num_queries ); 94 foreach ( $pages as $page ) 100 foreach ( $pages as $page ) { 95 101 $this->assertInstanceOf( 'WP_Post', $page ); 102 } 96 103 } 97 104 … … 100 107 */ 101 108 public function test_cache_should_be_invalidated_by_add_post_meta() { 102 $posts = self::factory()->post->create_many( 2, array( 103 'post_type' => 'page', 104 ) ); 109 $posts = self::factory()->post->create_many( 110 2, array( 111 'post_type' => 'page', 112 ) 113 ); 105 114 106 115 add_post_meta( $posts[0], 'foo', 'bar' ); 107 116 108 $cached = get_pages( array( 109 'meta_key' => 'foo', 110 'meta_value' => 'bar', 111 ) ); 117 $cached = get_pages( 118 array( 119 'meta_key' => 'foo', 120 'meta_value' => 'bar', 121 ) 122 ); 112 123 113 124 $cached_ids = wp_list_pluck( $cached, 'ID' ); … … 116 127 add_post_meta( $posts[1], 'foo', 'bar' ); 117 128 118 $found = get_pages( array( 119 'meta_key' => 'foo', 120 'meta_value' => 'bar', 121 ) ); 129 $found = get_pages( 130 array( 131 'meta_key' => 'foo', 132 'meta_value' => 'bar', 133 ) 134 ); 122 135 123 136 $found_ids = wp_list_pluck( $found, 'ID' ); … … 129 142 */ 130 143 public function test_cache_should_be_invalidated_by_update_post_meta() { 131 $posts = self::factory()->post->create_many( 2, array( 132 'post_type' => 'page', 133 ) ); 144 $posts = self::factory()->post->create_many( 145 2, array( 146 'post_type' => 'page', 147 ) 148 ); 134 149 135 150 add_post_meta( $posts[0], 'foo', 'bar' ); 136 151 add_post_meta( $posts[1], 'foo', 'bar' ); 137 152 138 $cached = get_pages( array( 139 'meta_key' => 'foo', 140 'meta_value' => 'bar', 141 ) ); 153 $cached = get_pages( 154 array( 155 'meta_key' => 'foo', 156 'meta_value' => 'bar', 157 ) 158 ); 142 159 143 160 $cached_ids = wp_list_pluck( $cached, 'ID' ); … … 146 163 update_post_meta( $posts[1], 'foo', 'baz' ); 147 164 148 $found = get_pages( array( 149 'meta_key' => 'foo', 150 'meta_value' => 'bar', 151 ) ); 165 $found = get_pages( 166 array( 167 'meta_key' => 'foo', 168 'meta_value' => 'bar', 169 ) 170 ); 152 171 153 172 $found_ids = wp_list_pluck( $found, 'ID' ); … … 159 178 */ 160 179 public function test_cache_should_be_invalidated_by_delete_post_meta() { 161 $posts = self::factory()->post->create_many( 2, array( 162 'post_type' => 'page', 163 ) ); 180 $posts = self::factory()->post->create_many( 181 2, array( 182 'post_type' => 'page', 183 ) 184 ); 164 185 165 186 add_post_meta( $posts[0], 'foo', 'bar' ); 166 187 add_post_meta( $posts[1], 'foo', 'bar' ); 167 188 168 $cached = get_pages( array( 169 'meta_key' => 'foo', 170 'meta_value' => 'bar', 171 ) ); 189 $cached = get_pages( 190 array( 191 'meta_key' => 'foo', 192 'meta_value' => 'bar', 193 ) 194 ); 172 195 173 196 $cached_ids = wp_list_pluck( $cached, 'ID' ); … … 176 199 delete_post_meta( $posts[1], 'foo' ); 177 200 178 $found = get_pages( array( 179 'meta_key' => 'foo', 180 'meta_value' => 'bar', 181 ) ); 201 $found = get_pages( 202 array( 203 'meta_key' => 'foo', 204 'meta_value' => 'bar', 205 ) 206 ); 182 207 183 208 $found_ids = wp_list_pluck( $found, 'ID' ); … … 189 214 */ 190 215 public function test_cache_should_be_invalidated_by_delete_post_meta_by_key() { 191 $posts = self::factory()->post->create_many( 2, array( 192 'post_type' => 'page', 193 ) ); 216 $posts = self::factory()->post->create_many( 217 2, array( 218 'post_type' => 'page', 219 ) 220 ); 194 221 195 222 add_post_meta( $posts[0], 'foo', 'bar' ); 196 223 add_post_meta( $posts[1], 'foo', 'bar' ); 197 224 198 $cached = get_pages( array( 199 'meta_key' => 'foo', 200 'meta_value' => 'bar', 201 ) ); 225 $cached = get_pages( 226 array( 227 'meta_key' => 'foo', 228 'meta_value' => 'bar', 229 ) 230 ); 202 231 203 232 $cached_ids = wp_list_pluck( $cached, 'ID' ); … … 206 235 delete_post_meta_by_key( 'foo' ); 207 236 208 $found = get_pages( array( 209 'meta_key' => 'foo', 210 'meta_value' => 'bar', 211 ) ); 237 $found = get_pages( 238 array( 239 'meta_key' => 'foo', 240 'meta_value' => 'bar', 241 ) 242 ); 212 243 213 244 $found_ids = wp_list_pluck( $found, 'ID' ); … … 224 255 add_post_meta( $posts[2], 'some-meta-key', '1' ); 225 256 226 $this->assertEquals( 1, count( get_pages( array( 'meta_key' => 'some-meta-key', 'meta_value' => '0' ) ) ) ); 227 $this->assertEquals( 1, count( get_pages( array( 'meta_key' => 'some-meta-key', 'meta_value' => '1' ) ) ) ); 257 $this->assertEquals( 258 1, count( 259 get_pages( 260 array( 261 'meta_key' => 'some-meta-key', 262 'meta_value' => '0', 263 ) 264 ) 265 ) 266 ); 267 $this->assertEquals( 268 1, count( 269 get_pages( 270 array( 271 'meta_key' => 'some-meta-key', 272 'meta_value' => '1', 273 ) 274 ) 275 ) 276 ); 228 277 $this->assertEquals( 3, count( get_pages( array( 'meta_key' => 'some-meta-key' ) ) ) ); 229 278 } … … 235 284 $page_ids = array(); 236 285 237 foreach ( range( 1, 20 ) as $i ) 286 foreach ( range( 1, 20 ) as $i ) { 238 287 $page_ids[] = self::factory()->post->create( array( 'post_type' => 'page' ) ); 288 } 239 289 240 290 $inc = array_slice( $page_ids, 0, 10 ); … … 243 293 sort( $exc ); 244 294 245 $include = get_pages( array( 'include' => $inc ) );295 $include = get_pages( array( 'include' => $inc ) ); 246 296 $inc_result = wp_list_pluck( $include, 'ID' ); 247 297 sort( $inc_result ); 248 298 $this->assertEquals( $inc, $inc_result ); 249 299 250 $exclude = get_pages( array( 'exclude' => $exc ) );300 $exclude = get_pages( array( 'exclude' => $exc ) ); 251 301 $exc_result = wp_list_pluck( $exclude, 'ID' ); 252 302 sort( $exc_result ); … … 259 309 function test_get_pages_parent() { 260 310 $page_id1 = self::factory()->post->create( array( 'post_type' => 'page' ) ); 261 $page_id2 = self::factory()->post->create( array( 'post_type' => 'page', 'post_parent' => $page_id1 ) ); 262 $page_id3 = self::factory()->post->create( array( 'post_type' => 'page', 'post_parent' => $page_id2 ) ); 263 $page_id4 = self::factory()->post->create( array( 'post_type' => 'page', 'post_parent' => $page_id1 ) ); 264 265 $pages = get_pages( array( 'parent' => 0, 'hierarchical' => false ) ); 311 $page_id2 = self::factory()->post->create( 312 array( 313 'post_type' => 'page', 314 'post_parent' => $page_id1, 315 ) 316 ); 317 $page_id3 = self::factory()->post->create( 318 array( 319 'post_type' => 'page', 320 'post_parent' => $page_id2, 321 ) 322 ); 323 $page_id4 = self::factory()->post->create( 324 array( 325 'post_type' => 'page', 326 'post_parent' => $page_id1, 327 ) 328 ); 329 330 $pages = get_pages( 331 array( 332 'parent' => 0, 333 'hierarchical' => false, 334 ) 335 ); 266 336 $this->assertEqualSets( array( $page_id1 ), wp_list_pluck( $pages, 'ID' ) ); 267 337 268 $pages = get_pages( array( 'parent' => $page_id1, 'hierarchical' => false ) ); 338 $pages = get_pages( 339 array( 340 'parent' => $page_id1, 341 'hierarchical' => false, 342 ) 343 ); 269 344 $this->assertEqualSets( array( $page_id2, $page_id4 ), wp_list_pluck( $pages, 'ID' ) ); 270 345 271 $pages = get_pages( array( 'parent' => array( $page_id1, $page_id2 ), 'hierarchical' => false ) ); 346 $pages = get_pages( 347 array( 348 'parent' => array( $page_id1, $page_id2 ), 349 'hierarchical' => false, 350 ) 351 ); 272 352 $this->assertEqualSets( array( $page_id2, $page_id3, $page_id4 ), wp_list_pluck( $pages, 'ID' ) ); 273 353 … … 297 377 */ 298 378 function test_get_chidren_fields_ids() { 299 $post_id = self::factory()->post->create();379 $post_id = self::factory()->post->create(); 300 380 $child_ids = self::factory()->post->create_many( 5, array( 'post_parent' => $post_id ) ); 301 381 302 $post_ids = get_children( array( 'fields' => 'ids', 'post_parent' => $post_id ) ); 382 $post_ids = get_children( 383 array( 384 'fields' => 'ids', 385 'post_parent' => $post_id, 386 ) 387 ); 303 388 $this->assertEqualSets( $child_ids, $post_ids ); 304 389 } … … 310 395 global $wpdb; 311 396 $page_1 = self::factory()->post->create( array( 'post_type' => 'page' ) ); 312 $page_2 = self::factory()->post->create( array( 'post_type' => 'page', 'post_parent' => $page_1 ) ); 313 $page_3 = self::factory()->post->create( array( 'post_type' => 'page', 'post_parent' => $page_1 ) ); 314 $page_4 = self::factory()->post->create( array( 'post_type' => 'page', 'post_parent' => $page_2 ) ); 315 316 $pages = get_pages(); // Defaults: hierarchical = true, parent = -1 317 $pages_default_args = get_pages( array( 'hierarchical' => true, 'parent' => -1 ) ); 397 $page_2 = self::factory()->post->create( 398 array( 399 'post_type' => 'page', 400 'post_parent' => $page_1, 401 ) 402 ); 403 $page_3 = self::factory()->post->create( 404 array( 405 'post_type' => 'page', 406 'post_parent' => $page_1, 407 ) 408 ); 409 $page_4 = self::factory()->post->create( 410 array( 411 'post_type' => 'page', 412 'post_parent' => $page_2, 413 ) 414 ); 415 416 $pages = get_pages(); // Defaults: hierarchical = true, parent = -1 417 $pages_default_args = get_pages( 418 array( 419 'hierarchical' => true, 420 'parent' => -1, 421 ) 422 ); 318 423 // Confirm the defaults. 319 424 $this->assertEquals( $pages, $pages_default_args ); … … 340 445 $page_1 = self::factory()->post->create( array( 'post_type' => 'page' ) ); 341 446 $page_2 = self::factory()->post->create( array( 'post_type' => 'page' ) ); 342 $page_3 = self::factory()->post->create( array( 'post_type' => 'page', 'post_parent' => $page_1 ) ); 343 $page_4 = self::factory()->post->create( array( 'post_type' => 'page', 'post_parent' => $page_1 ) ); 344 345 $pages = get_pages(); // Defaults: hierarchical = true, child_of = '', parent = -1 346 $default_args = get_pages( array( 347 'hierarchical' => true, 348 'child_of' => '' 349 ) ); 447 $page_3 = self::factory()->post->create( 448 array( 449 'post_type' => 'page', 450 'post_parent' => $page_1, 451 ) 452 ); 453 $page_4 = self::factory()->post->create( 454 array( 455 'post_type' => 'page', 456 'post_parent' => $page_1, 457 ) 458 ); 459 460 $pages = get_pages(); // Defaults: hierarchical = true, child_of = '', parent = -1 461 $default_args = get_pages( 462 array( 463 'hierarchical' => true, 464 'child_of' => '', 465 ) 466 ); 350 467 351 468 $this->assertEquals( $pages, $default_args ); … … 374 491 $page_1 = self::factory()->post->create( array( 'post_type' => 'page' ) ); 375 492 $page_2 = self::factory()->post->create( array( 'post_type' => 'page' ) ); 376 $page_3 = self::factory()->post->create( array( 'post_type' => 'page', 'post_parent' => $page_1 ) ); 377 $page_4 = self::factory()->post->create( array( 'post_type' => 'page', 'post_parent' => $page_1 ) ); 493 $page_3 = self::factory()->post->create( 494 array( 495 'post_type' => 'page', 496 'post_parent' => $page_1, 497 ) 498 ); 499 $page_4 = self::factory()->post->create( 500 array( 501 'post_type' => 'page', 502 'post_parent' => $page_1, 503 ) 504 ); 378 505 379 506 $pages = get_pages( array( 'hierarchical' => false ) ); // child_of = '', parent = -1 … … 400 527 $page_1 = self::factory()->post->create( array( 'post_type' => 'page' ) ); 401 528 $page_2 = self::factory()->post->create( array( 'post_type' => 'page' ) ); 402 $page_3 = self::factory()->post->create( array( 'post_type' => 'page', 'post_parent' => $page_1 ) ); 403 $page_4 = self::factory()->post->create( array( 'post_type' => 'page', 'post_parent' => $page_3 ) ); 404 $page_5 = self::factory()->post->create( array( 'post_type' => 'page', 'post_parent' => $page_1 ) ); 529 $page_3 = self::factory()->post->create( 530 array( 531 'post_type' => 'page', 532 'post_parent' => $page_1, 533 ) 534 ); 535 $page_4 = self::factory()->post->create( 536 array( 537 'post_type' => 'page', 538 'post_parent' => $page_3, 539 ) 540 ); 541 $page_5 = self::factory()->post->create( 542 array( 543 'post_type' => 'page', 544 'post_parent' => $page_1, 545 ) 546 ); 405 547 406 548 $pages = get_pages( array( 'child_of' => $page_1 ) ); // Defaults: hierarchical = true, parent = -1. … … 428 570 $page_1 = self::factory()->post->create( array( 'post_type' => 'page' ) ); 429 571 $page_2 = self::factory()->post->create( array( 'post_type' => 'page' ) ); 430 $page_3 = self::factory()->post->create( array( 'post_type' => 'page', 'post_parent' => $page_1 ) ); 431 $page_4 = self::factory()->post->create( array( 'post_type' => 'page', 'post_parent' => $page_3 ) ); 432 $page_5 = self::factory()->post->create( array( 'post_type' => 'page', 'post_parent' => $page_1 ) ); 433 434 $pages = get_pages( array( 'hierarchical' => false, 'child_of' => $page_1 ) ); 572 $page_3 = self::factory()->post->create( 573 array( 574 'post_type' => 'page', 575 'post_parent' => $page_1, 576 ) 577 ); 578 $page_4 = self::factory()->post->create( 579 array( 580 'post_type' => 'page', 581 'post_parent' => $page_3, 582 ) 583 ); 584 $page_5 = self::factory()->post->create( 585 array( 586 'post_type' => 'page', 587 'post_parent' => $page_1, 588 ) 589 ); 590 591 $pages = get_pages( 592 array( 593 'hierarchical' => false, 594 'child_of' => $page_1, 595 ) 596 ); 435 597 436 598 /* … … 456 618 function test_wp_list_pages_classes() { 457 619 $type = 'taco'; 458 register_post_type( $type, array( 'hierarchical' => true, 'public' => true ) ); 459 460 $posts = self::factory()->post->create_many( 2, array( 'post_type' => $type ) ); 620 register_post_type( 621 $type, array( 622 'hierarchical' => true, 623 'public' => true, 624 ) 625 ); 626 627 $posts = self::factory()->post->create_many( 2, array( 'post_type' => $type ) ); 461 628 $post_id = reset( $posts ); 462 629 … … 465 632 $this->assertEquals( $post_id, get_queried_object_id() ); 466 633 467 $output = wp_list_pages( array( 468 'echo' => false, 469 'title_li' => '', 470 'post_type' => $type 471 ) ); 634 $output = wp_list_pages( 635 array( 636 'echo' => false, 637 'title_li' => '', 638 'post_type' => $type, 639 ) 640 ); 472 641 473 642 $this->assertNotEmpty( $output ); … … 481 650 function test_exclude_tree() { 482 651 $post_id1 = self::factory()->post->create( array( 'post_type' => 'page' ) ); 483 $post_id2 = self::factory()->post->create( array( 'post_type' => 'page', 'post_parent' => $post_id1 ) ); 652 $post_id2 = self::factory()->post->create( 653 array( 654 'post_type' => 'page', 655 'post_parent' => $post_id1, 656 ) 657 ); 484 658 $post_id3 = self::factory()->post->create( array( 'post_type' => 'page' ) ); 485 $post_id4 = self::factory()->post->create( array( 'post_type' => 'page', 'post_parent' => $post_id3 ) ); 659 $post_id4 = self::factory()->post->create( 660 array( 661 'post_type' => 'page', 662 'post_parent' => $post_id3, 663 ) 664 ); 486 665 487 666 $all = get_pages(); … … 505 684 506 685 $post_id5 = self::factory()->post->create( array( 'post_type' => 'page' ) ); 507 $post_id6 = self::factory()->post->create( array( 'post_type' => 'page', 'post_parent' => $post_id5 ) ); 686 $post_id6 = self::factory()->post->create( 687 array( 688 'post_type' => 'page', 689 'post_parent' => $post_id5, 690 ) 691 ); 508 692 509 693 $exclude6 = get_pages( array( 'exclude_tree' => array( $post_id1, $post_id3 ) ) );
Note: See TracChangeset
for help on using the changeset viewer.