Changeset 49451 for trunk/tests/phpunit/tests/term/termCounts.php
- Timestamp:
- 10/30/2020 04:57:16 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/term/termCounts.php
r49305 r49451 80 80 81 81 /** 82 * Term counts are not doubleincremented when post created.83 * 84 * @covers ::wp_ modify_term_count_by82 * Term counts are incremented when post created. 83 * 84 * @covers ::wp_update_term_count 85 85 * @dataProvider data_term_count_changes_for_post_statuses 86 * @ticket 4035187 86 * 88 87 * @param string $post_status New post status. … … 123 122 * 124 123 * @covers ::wp_publish_post 125 * @covers ::wp_ modify_term_count_by124 * @covers ::wp_update_term_count 126 125 * @dataProvider data_term_counts_incremented_on_publish 127 * @ticket 40351128 126 * @ticket 51292 129 127 * … … 165 163 * Test post status transition update term counts correctly. 166 164 * 167 * @covers ::wp_ modify_term_count_by165 * @covers ::wp_update_term_count 168 166 * @dataProvider data_term_count_transitions_update_term_counts 169 * @ticket 40351170 167 * 171 168 * @param string $original_post_status Post status upon create. … … 229 226 230 227 /** 231 * Term counts are not double incremented when post created.232 * 233 * @covers ::wp_ modify_term_count_by228 * Term counts incremented correctly for posts with attachment. 229 * 230 * @covers ::wp_update_term_count 234 231 * @dataProvider data_term_count_changes_for_post_statuses_with_attachments 235 * @ticket 40351236 232 * 237 233 * @param string $post_status New post status. … … 278 274 279 275 /** 280 * Term counts increments correctly when post statusbecomes published.276 * Term counts increments correctly when post with attachment becomes published. 281 277 * 282 278 * @covers ::wp_publish_post 283 * @covers ::wp_ modify_term_count_by279 * @covers ::wp_update_term_count 284 280 * @dataProvider data_term_counts_incremented_on_publish_with_attachments 285 * @ticket 40351286 281 * @ticket 51292 287 282 * … … 330 325 331 326 /** 332 * Test post status transition update term counts correctly .333 * 334 * @covers ::wp_ modify_term_count_by327 * Test post status transition update term counts correctly for posts with attachments. 328 * 329 * @covers ::wp_update_term_count 335 330 * @dataProvider data_term_count_transitions_update_term_counts_with_attachments 336 * @ticket 40351337 331 * 338 332 * @param string $original_post_status Post status upon create. … … 405 399 406 400 /** 407 * Term counts are not double incremented when post created. 408 * 409 * @covers ::wp_modify_term_count_by 410 * @dataProvider data_term_count_changes_for_post_statuses_with_untermed_attachments 411 * @ticket 40351 412 * 413 * @param string $post_status New post status. 414 * @param int $change Expected change. 415 */ 416 public function test_term_count_changes_for_post_statuses_with_untermed_attachments( $post_status, $change ) { 417 $term_count = get_term( self::$attachment_term )->count; 418 // Do not use shared fixture for this test as it relies on a new post. 419 $post_id = $this->factory()->post->create( array( 'post_status' => $post_status ) ); 420 wp_add_object_terms( $post_id, self::$attachment_term, 'wp_test_tax_counts' ); 421 $attachment_id = self::factory()->attachment->create_object( 422 array( 423 'file' => 'image.jpg', 424 'post_parent' => $post_id, 425 'post_status' => 'inherit', 426 ) 427 ); 428 429 $expected = $term_count + $change; 430 $this->assertSame( $expected, get_term( self::$attachment_term )->count ); 431 } 432 433 /** 434 * Data provider for test_term_count_changes_for_post_statuses_with_untermed_attachments. 435 * 436 * @return array[] { 437 * @type string $post_status New post status. 438 * @type int $change Expected change. 439 * } 440 */ 441 function data_term_count_changes_for_post_statuses_with_untermed_attachments() { 442 return array( 443 // 0. Published post 444 array( 'publish', 1 ), 445 // 1. Auto draft 446 array( 'auto-draft', 0 ), 447 // 2. Draft 448 array( 'draft', 0 ), 449 // 3. Private post 450 array( 'private', 0 ), 451 ); 452 } 453 454 /** 455 * Term counts increments correctly when post status becomes published. 456 * 457 * @covers ::wp_modify_term_count_by 401 * Term counts increments correctly when post with attachment becomes published. 402 * 403 * @covers ::wp_update_term_count 458 404 * @covers ::wp_publish_post 459 405 * @dataProvider data_term_counts_incremented_on_publish_with_untermed_attachments 460 * @ticket 40351461 406 * @ticket 51292 462 407 * … … 504 449 505 450 /** 506 * Test post status transition update term counts correctly .507 * 508 * @covers ::wp_ modify_term_count_by451 * Test post status transition update term counts correctly on post with attachment. 452 * 453 * @covers ::wp_update_term_count 509 454 * @dataProvider data_term_count_transitions_update_term_counts_with_untermed_attachments 510 * @ticket 40351511 455 * 512 456 * @param string $original_post_status Post status upon create. … … 580 524 * User taxonomy term counts increments when added to an account. 581 525 * 582 * @covers ::wp_ modify_term_count_by526 * @covers ::wp_update_term_count 583 527 * @ticket 51292 584 528 */ … … 594 538 * User taxonomy term counts decrement when term deleted from user. 595 539 * 596 * @covers ::wp_ modify_term_count_by540 * @covers ::wp_update_term_count 597 541 * @ticket 51292 598 542 */ … … 605 549 $this->assertSame( $expected, get_term( self::$user_term )->count ); 606 550 } 607 608 /**609 * Ensure DB queries for deferred counts are nullified for net zero gain.610 *611 * @covers ::wp_modify_term_count_by612 * @covers ::wp_defer_term_counting613 * @ticket 51292614 */615 public function test_counts_after_deferral_net_zero() {616 $post_one = self::$post_ids['publish'];617 $post_two = self::$post_ids['publish_two'];618 $terms = self::$tag_ids;619 620 wp_set_object_terms( $post_one, $terms[0], 'post_tag', true );621 622 // Net gain 0;623 wp_defer_term_counting( true );624 wp_remove_object_terms( $post_one, $terms[0], 'post_tag' );625 wp_set_object_terms( $post_two, $terms[0], 'post_tag', true );626 $num_queries = get_num_queries();627 wp_defer_term_counting( false );628 // Ensure number of queries unchanged.629 $this->assertSame( $num_queries, get_num_queries() );630 }631 632 /**633 * Ensure full recounts follow modify by X recounts to avoid miscounts.634 *635 * @covers ::wp_modify_term_count_by636 * @covers ::wp_update_term_count637 * @covers ::wp_defer_term_counting638 * @ticket 51292639 */640 public function test_counts_after_deferral_full_before_partial() {641 $post_one = self::$post_ids['publish'];642 $terms = self::$tag_ids;643 $term_count = get_term( $terms[0] )->count;644 645 // Net gain 1;646 wp_defer_term_counting( true );647 wp_set_object_terms( $post_one, $terms[0], 'post_tag', true );648 wp_update_term_count( get_term( $terms[0] )->term_taxonomy_id, 'post_tag' );649 wp_defer_term_counting( false );650 651 // Ensure term count is correct.652 $expected = $term_count + 1;653 $this->assertSame( $expected, get_term( $terms[0] )->count );654 }655 656 /**657 * Ensure DB queries for deferred counts are combined.658 *659 * @covers ::wp_modify_term_count_by660 * @covers ::wp_defer_term_counting661 * @ticket 51292662 */663 public function test_counts_after_deferral_matching_changes() {664 $post_one = self::$post_ids['publish'];665 $post_two = self::$post_ids['publish_two'];666 $terms = self::$tag_ids;667 668 wp_set_object_terms( $post_one, $terms[0], 'post_tag', true );669 670 // Net gain 0:671 wp_defer_term_counting( true );672 wp_remove_object_terms( $post_one, $terms[0], 'post_tag' );673 wp_set_object_terms( $post_two, $terms[0], 'post_tag', true );674 675 // Net gain 1:676 wp_set_object_terms( $post_one, $terms[1], 'post_tag', true );677 wp_set_object_terms( $post_two, $terms[2], 'post_tag', true );678 679 // Net gain 2:680 wp_set_object_terms( $post_one, array( $terms[3], $terms[4] ), 'post_tag', true );681 wp_set_object_terms( $post_two, array( $terms[3], $terms[4] ), 'post_tag', true );682 683 $num_queries = get_num_queries();684 wp_defer_term_counting( false );685 686 /*687 * Each count is expected to produce two queries:688 * 1) The count update689 * 2) The SELECT in `clean_term_cache()`.690 */691 $expected = $num_queries + ( 2 * 2 );692 // Ensure number of queries correct.693 $this->assertSame( $expected, get_num_queries() );694 }695 551 }
Note: See TracChangeset
for help on using the changeset viewer.