Changeset 42343 for trunk/tests/phpunit/tests/query.php
- Timestamp:
- 11/30/2017 11:09:33 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/query.php
r38654 r42343 12 12 /** 13 13 * @ticket 24785 14 *15 14 */ 16 15 function test_nested_loop_reset_postdata() { 17 $post_id = self::factory()->post->create();16 $post_id = self::factory()->post->create(); 18 17 $nested_post_id = self::factory()->post->create(); 19 18 20 19 $first_query = new WP_Query( array( 'post__in' => array( $post_id ) ) ); 21 while ( $first_query->have_posts() ) { $first_query->the_post(); 20 while ( $first_query->have_posts() ) { 21 $first_query->the_post(); 22 22 $second_query = new WP_Query( array( 'post__in' => array( $nested_post_id ) ) ); 23 23 while ( $second_query->have_posts() ) { … … 95 95 remove_action( 'pre_get_posts', array( $this, 'pre_get_posts_tax_category_tax_query' ) ); 96 96 register_taxonomy( 'wptests_tax', 'post' ); 97 $terms = self::factory()->term->create_many( 2, array( 98 'taxonomy' => 'wptests_tax', 99 ) ); 97 $terms = self::factory()->term->create_many( 98 2, array( 99 'taxonomy' => 'wptests_tax', 100 ) 101 ); 100 102 101 103 $posts = self::factory()->post->create_many( 2 ); … … 105 107 106 108 add_action( 'parse_query', array( $this, 'filter_parse_query_to_remove_tax' ) ); 107 $q = new WP_Query( array( 108 'fields' => 'ids', 109 'wptests_tax' => $terms[1], 110 ) ); 109 $q = new WP_Query( 110 array( 111 'fields' => 'ids', 112 'wptests_tax' => $terms[1], 113 ) 114 ); 111 115 112 116 remove_action( 'parse_query', array( $this, 'filter_parse_query_to_remove_tax' ) ); … … 125 129 register_taxonomy( 'wptests_tax', 'post' ); 126 130 127 $q = new WP_Query( array( 128 'tax_query' => array( 129 array( 130 'taxonomy' => 'wptests_tax', 131 'operator' => 'NOT EXISTS', 131 $q = new WP_Query( 132 array( 133 'tax_query' => array( 134 array( 135 'taxonomy' => 'wptests_tax', 136 'operator' => 'NOT EXISTS', 137 ), 132 138 ), 133 ) ,134 ) );139 ) 140 ); 135 141 136 142 $queried_object = $q->get_queried_object(); … … 141 147 global $wpdb; 142 148 143 $q = new WP_Query( array( 144 'orderby' => 'title date', 145 'order' => 'DESC', 146 ) ); 149 $q = new WP_Query( 150 array( 151 'orderby' => 'title date', 152 'order' => 'DESC', 153 ) 154 ); 147 155 148 156 $this->assertContains( "ORDER BY $wpdb->posts.post_title DESC, $wpdb->posts.post_date DESC", $q->request ); … … 150 158 151 159 public function test_cat_querystring_single_term() { 152 $c1 = self::factory()->category->create( array( 153 'name' => 'Test Category 1', 154 'slug' => 'test1', 155 ) ); 156 $c2 = self::factory()->category->create( array( 157 'name' => 'Test Category 2', 158 'slug' => 'test2', 159 ) ); 160 $c1 = self::factory()->category->create( 161 array( 162 'name' => 'Test Category 1', 163 'slug' => 'test1', 164 ) 165 ); 166 $c2 = self::factory()->category->create( 167 array( 168 'name' => 'Test Category 2', 169 'slug' => 'test2', 170 ) 171 ); 160 172 161 173 $p1 = self::factory()->post->create(); … … 167 179 wp_set_object_terms( $p3, $c2, 'category' ); 168 180 169 $url = add_query_arg( array( 170 'cat' => $c1, 171 ), '/' ); 181 $url = add_query_arg( 182 array( 183 'cat' => $c1, 184 ), '/' 185 ); 172 186 173 187 $this->go_to( $url ); … … 179 193 180 194 public function test_category_querystring_multiple_terms_comma_separated() { 181 $c1 = self::factory()->category->create( array( 182 'name' => 'Test Category 1', 183 'slug' => 'test1', 184 ) ); 185 $c2 = self::factory()->category->create( array( 186 'name' => 'Test Category 2', 187 'slug' => 'test2', 188 ) ); 189 $c3 = self::factory()->category->create( array( 190 'name' => 'Test Category 3', 191 'slug' => 'test3', 192 ) ); 195 $c1 = self::factory()->category->create( 196 array( 197 'name' => 'Test Category 1', 198 'slug' => 'test1', 199 ) 200 ); 201 $c2 = self::factory()->category->create( 202 array( 203 'name' => 'Test Category 2', 204 'slug' => 'test2', 205 ) 206 ); 207 $c3 = self::factory()->category->create( 208 array( 209 'name' => 'Test Category 3', 210 'slug' => 'test3', 211 ) 212 ); 193 213 194 214 $p1 = self::factory()->post->create(); … … 202 222 wp_set_object_terms( $p4, $c3, 'category' ); 203 223 204 $url = add_query_arg( array( 205 'cat' => implode( ',',array( $c1,$c2 ) ), 206 ), '/' ); 224 $url = add_query_arg( 225 array( 226 'cat' => implode( ',', array( $c1, $c2 ) ), 227 ), '/' 228 ); 207 229 208 230 $this->go_to( $url ); … … 217 239 */ 218 240 public function test_category_querystring_multiple_terms_formatted_as_array() { 219 $c1 = self::factory()->category->create( array( 220 'name' => 'Test Category 1', 221 'slug' => 'test1', 222 ) ); 223 $c2 = self::factory()->category->create( array( 224 'name' => 'Test Category 2', 225 'slug' => 'test2', 226 ) ); 227 $c3 = self::factory()->category->create( array( 228 'name' => 'Test Category 3', 229 'slug' => 'test3', 230 ) ); 241 $c1 = self::factory()->category->create( 242 array( 243 'name' => 'Test Category 1', 244 'slug' => 'test1', 245 ) 246 ); 247 $c2 = self::factory()->category->create( 248 array( 249 'name' => 'Test Category 2', 250 'slug' => 'test2', 251 ) 252 ); 253 $c3 = self::factory()->category->create( 254 array( 255 'name' => 'Test Category 3', 256 'slug' => 'test3', 257 ) 258 ); 231 259 232 260 $p1 = self::factory()->post->create(); … … 240 268 wp_set_object_terms( $p4, $c3, 'category' ); 241 269 242 $url = add_query_arg( array( 243 'cat' => array( $c1, $c2 ), 244 ), '/' ); 270 $url = add_query_arg( 271 array( 272 'cat' => array( $c1, $c2 ), 273 ), '/' 274 ); 245 275 246 276 $this->go_to( $url ); … … 253 283 254 284 public function test_tag_querystring_single_term() { 255 $t1 = self::factory()->tag->create_and_get( array( 256 'name' => 'Test Tag 1', 257 'slug' => 'test1', 258 ) ); 259 $t2 = self::factory()->tag->create_and_get( array( 260 'name' => 'Test Tag 2', 261 'slug' => 'test2', 262 ) ); 285 $t1 = self::factory()->tag->create_and_get( 286 array( 287 'name' => 'Test Tag 1', 288 'slug' => 'test1', 289 ) 290 ); 291 $t2 = self::factory()->tag->create_and_get( 292 array( 293 'name' => 'Test Tag 2', 294 'slug' => 'test2', 295 ) 296 ); 263 297 264 298 $p1 = self::factory()->post->create(); … … 270 304 wp_set_object_terms( $p3, $t2->slug, 'post_tag' ); 271 305 272 $url = add_query_arg( array( 273 'tag' => $t1->slug, 274 ), '/' ); 306 $url = add_query_arg( 307 array( 308 'tag' => $t1->slug, 309 ), '/' 310 ); 275 311 276 312 $this->go_to( $url ); … … 282 318 283 319 public function test_tag_querystring_multiple_terms_comma_separated() { 284 $c1 = self::factory()->tag->create_and_get( array( 285 'name' => 'Test Tag 1', 286 'slug' => 'test1', 287 ) ); 288 $c2 = self::factory()->tag->create_and_get( array( 289 'name' => 'Test Tag 2', 290 'slug' => 'test2', 291 ) ); 292 $c3 = self::factory()->tag->create_and_get( array( 293 'name' => 'Test Tag 3', 294 'slug' => 'test3', 295 ) ); 320 $c1 = self::factory()->tag->create_and_get( 321 array( 322 'name' => 'Test Tag 1', 323 'slug' => 'test1', 324 ) 325 ); 326 $c2 = self::factory()->tag->create_and_get( 327 array( 328 'name' => 'Test Tag 2', 329 'slug' => 'test2', 330 ) 331 ); 332 $c3 = self::factory()->tag->create_and_get( 333 array( 334 'name' => 'Test Tag 3', 335 'slug' => 'test3', 336 ) 337 ); 296 338 297 339 $p1 = self::factory()->post->create(); … … 305 347 wp_set_object_terms( $p4, $c3->slug, 'post_tag' ); 306 348 307 $url = add_query_arg( array( 308 'tag' => implode( ',',array( $c1->slug,$c2->slug ) ), 309 ), '/' ); 349 $url = add_query_arg( 350 array( 351 'tag' => implode( ',', array( $c1->slug, $c2->slug ) ), 352 ), '/' 353 ); 310 354 311 355 $this->go_to( $url ); … … 320 364 */ 321 365 public function test_tag_querystring_multiple_terms_formatted_as_array() { 322 $c1 = self::factory()->tag->create_and_get( array( 323 'name' => 'Test Tag 1', 324 'slug' => 'test1', 325 ) ); 326 $c2 = self::factory()->tag->create_and_get( array( 327 'name' => 'Test Tag 2', 328 'slug' => 'test2', 329 ) ); 330 $c3 = self::factory()->tag->create_and_get( array( 331 'name' => 'Test Tag 3', 332 'slug' => 'test3', 333 ) ); 366 $c1 = self::factory()->tag->create_and_get( 367 array( 368 'name' => 'Test Tag 1', 369 'slug' => 'test1', 370 ) 371 ); 372 $c2 = self::factory()->tag->create_and_get( 373 array( 374 'name' => 'Test Tag 2', 375 'slug' => 'test2', 376 ) 377 ); 378 $c3 = self::factory()->tag->create_and_get( 379 array( 380 'name' => 'Test Tag 3', 381 'slug' => 'test3', 382 ) 383 ); 334 384 335 385 $p1 = self::factory()->post->create(); … … 343 393 wp_set_object_terms( $p4, $c3->slug, 'post_tag' ); 344 394 345 $url = add_query_arg( array( 346 'tag' => array($c1->slug,$c2->slug), 347 ), '/' ); 395 $url = add_query_arg( 396 array( 397 'tag' => array( $c1->slug, $c2->slug ), 398 ), '/' 399 ); 348 400 349 401 $this->go_to( $url ); … … 369 421 wp_set_object_terms( $p3, 'test2', 'test_tax_cat' ); 370 422 371 $url = add_query_arg( array( 372 'test_tax_cat' => 'test1', 373 ), '/' ); 423 $url = add_query_arg( 424 array( 425 'test_tax_cat' => 'test1', 426 ), '/' 427 ); 374 428 375 429 $this->go_to( $url ); … … 393 447 wp_set_object_terms( $p2, array( 'test1', 'test2' ), 'test_tax_cat' ); 394 448 wp_set_object_terms( $p3, 'test2', 'test_tax_cat' ); 395 wp_set_object_terms( $p4, "test3", 'test_tax_cat' ); 396 397 $url = add_query_arg( array( 398 'test_tax_cat' => 'test1,test2', 399 ), '/' ); 449 wp_set_object_terms( $p4, 'test3', 'test_tax_cat' ); 450 451 $url = add_query_arg( 452 array( 453 'test_tax_cat' => 'test1,test2', 454 ), '/' 455 ); 400 456 401 457 $this->go_to( $url ); … … 422 478 wp_set_object_terms( $p2, array( 'test1', 'test2' ), 'test_tax_cat' ); 423 479 wp_set_object_terms( $p3, 'test2', 'test_tax_cat' ); 424 wp_set_object_terms( $p4, "test3", 'test_tax_cat' ); 425 426 $url = add_query_arg( array( 427 'test_tax_cat' => array( 'test1', 'test2' ), 428 ), '/' ); 480 wp_set_object_terms( $p4, 'test3', 'test_tax_cat' ); 481 482 $url = add_query_arg( 483 array( 484 'test_tax_cat' => array( 'test1', 'test2' ), 485 ), '/' 486 ); 429 487 430 488 $this->go_to( $url ); … … 437 495 */ 438 496 public function test_pages_dont_404_when_queried_post_id_is_modified() { 439 $post_id = self::factory()->post->create( array( 'post_title' => 'A Test Page', 'post_type' => 'page' ) ); 497 $post_id = self::factory()->post->create( 498 array( 499 'post_title' => 'A Test Page', 500 'post_type' => 'page', 501 ) 502 ); 440 503 441 504 add_action( 'parse_query', array( $this, 'filter_parse_query_to_modify_queried_post_id' ) ); … … 456 519 global $wp_rewrite; 457 520 458 register_post_type( 'guide', array( 'name' => 'Guide', 'public' => true, 'hierarchical' => true ) ); 521 register_post_type( 522 'guide', array( 523 'name' => 'Guide', 524 'public' => true, 525 'hierarchical' => true, 526 ) 527 ); 459 528 $wp_rewrite->flush_rules(); 460 $post_id = self::factory()->post->create( array( 'post_title' => 'A Test Guide', 'post_type' => 'guide' ) ); 529 $post_id = self::factory()->post->create( 530 array( 531 'post_title' => 'A Test Guide', 532 'post_type' => 'guide', 533 ) 534 ); 461 535 462 536 add_action( 'parse_query', array( $this, 'filter_parse_query_to_modify_queried_post_id' ) ); … … 479 553 */ 480 554 public function test_offset_0_should_override_page() { 481 $q = new WP_Query( array( 482 'paged' => 2, 483 'posts_per_page' => 5, 484 'offset' => 0, 485 ) ); 555 $q = new WP_Query( 556 array( 557 'paged' => 2, 558 'posts_per_page' => 5, 559 'offset' => 0, 560 ) 561 ); 486 562 487 563 $this->assertContains( 'LIMIT 0, 5', $q->request ); … … 492 568 */ 493 569 public function test_offset_should_be_ignored_when_not_set() { 494 $q = new WP_Query( array( 495 'paged' => 2, 496 'posts_per_page' => 5, 497 ) ); 570 $q = new WP_Query( 571 array( 572 'paged' => 2, 573 'posts_per_page' => 5, 574 ) 575 ); 498 576 499 577 $this->assertContains( 'LIMIT 5, 5', $q->request ); … … 504 582 */ 505 583 public function test_offset_should_be_ignored_when_passed_a_non_numeric_value() { 506 $q = new WP_Query( array( 507 'paged' => 2, 508 'posts_per_page' => 5, 509 'offset' => '', 510 ) ); 584 $q = new WP_Query( 585 array( 586 'paged' => 2, 587 'posts_per_page' => 5, 588 'offset' => '', 589 ) 590 ); 511 591 512 592 $this->assertContains( 'LIMIT 5, 5', $q->request ); … … 520 600 $p2 = self::factory()->post->create( array( 'comment_status' => 'closed' ) ); 521 601 522 $q = new WP_Query( array( 523 'fields' => 'ids', 524 'comment_status' => 'closed', 525 ) ); 602 $q = new WP_Query( 603 array( 604 'fields' => 'ids', 605 'comment_status' => 'closed', 606 ) 607 ); 526 608 527 609 $this->assertSame( array( $p2 ), $q->posts ); … … 535 617 $p2 = self::factory()->post->create( array( 'ping_status' => 'closed' ) ); 536 618 537 $q = new WP_Query( array( 538 'fields' => 'ids', 539 'ping_status' => 'closed', 540 ) ); 619 $q = new WP_Query( 620 array( 621 'fields' => 'ids', 622 'ping_status' => 'closed', 623 ) 624 ); 541 625 542 626 $this->assertSame( array( $p2 ), $q->posts ); … … 550 634 register_taxonomy( 'tax2', 'post' ); 551 635 552 $term1 = $this->factory->term->create( array( 'taxonomy' => 'tax1', 'name' => 'term1' ) ); 553 $term2 = $this->factory->term->create( array( 'taxonomy' => 'tax2', 'name' => 'term2' ) ); 636 $term1 = $this->factory->term->create( 637 array( 638 'taxonomy' => 'tax1', 639 'name' => 'term1', 640 ) 641 ); 642 $term2 = $this->factory->term->create( 643 array( 644 'taxonomy' => 'tax2', 645 'name' => 'term2', 646 ) 647 ); 554 648 $post_id = $this->factory->post->create(); 555 649 wp_set_object_terms( $post_id, 'term1', 'tax1' ); … … 570 664 register_taxonomy( 'tax2', 'post' ); 571 665 572 $term1 = $this->factory->term->create( array( 'taxonomy' => 'tax1', 'name' => 'term1' ) ); 573 $term2 = $this->factory->term->create( array( 'taxonomy' => 'tax2', 'name' => 'term2' ) ); 666 $term1 = $this->factory->term->create( 667 array( 668 'taxonomy' => 'tax1', 669 'name' => 'term1', 670 ) 671 ); 672 $term2 = $this->factory->term->create( 673 array( 674 'taxonomy' => 'tax2', 675 'name' => 'term2', 676 ) 677 ); 574 678 $post_id = $this->factory->post->create(); 575 679 wp_set_object_terms( $post_id, 'term1', 'tax1' );
Note: See TracChangeset
for help on using the changeset viewer.