Make WordPress Core


Ignore:
Timestamp:
10/30/2020 04:57:16 AM (4 years ago)
Author:
peterwilsoncc
Message:

Taxonomy: Revert Light-weight/partial term counts.

Partial revert of [49141], [49171], [49316].

All functional changes are removed, appropriate term counting unit tests are retained.

See #40351.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/term/termCounts.php

    r49305 r49451  
    8080
    8181    /**
    82      * Term counts are not double incremented when post created.
    83      *
    84      * @covers ::wp_modify_term_count_by
     82     * Term counts are incremented when post created.
     83     *
     84     * @covers ::wp_update_term_count
    8585     * @dataProvider data_term_count_changes_for_post_statuses
    86      * @ticket 40351
    8786     *
    8887     * @param string $post_status New post status.
     
    123122     *
    124123     * @covers ::wp_publish_post
    125      * @covers ::wp_modify_term_count_by
     124     * @covers ::wp_update_term_count
    126125     * @dataProvider data_term_counts_incremented_on_publish
    127      * @ticket 40351
    128126     * @ticket 51292
    129127     *
     
    165163     * Test post status transition update term counts correctly.
    166164     *
    167      * @covers ::wp_modify_term_count_by
     165     * @covers ::wp_update_term_count
    168166     * @dataProvider data_term_count_transitions_update_term_counts
    169      * @ticket 40351
    170167     *
    171168     * @param string $original_post_status Post status upon create.
     
    229226
    230227    /**
    231      * Term counts are not double incremented when post created.
    232      *
    233      * @covers ::wp_modify_term_count_by
     228     * Term counts incremented correctly for posts with attachment.
     229     *
     230     * @covers ::wp_update_term_count
    234231     * @dataProvider data_term_count_changes_for_post_statuses_with_attachments
    235      * @ticket 40351
    236232     *
    237233     * @param string $post_status New post status.
     
    278274
    279275    /**
    280      * Term counts increments correctly when post status becomes published.
     276     * Term counts increments correctly when post with attachment becomes published.
    281277     *
    282278     * @covers ::wp_publish_post
    283      * @covers ::wp_modify_term_count_by
     279     * @covers ::wp_update_term_count
    284280     * @dataProvider data_term_counts_incremented_on_publish_with_attachments
    285      * @ticket 40351
    286281     * @ticket 51292
    287282     *
     
    330325
    331326    /**
    332      * Test post status transition update term counts correctly.
    333      *
    334      * @covers ::wp_modify_term_count_by
     327     * Test post status transition update term counts correctly for posts with attachments.
     328     *
     329     * @covers ::wp_update_term_count
    335330     * @dataProvider data_term_count_transitions_update_term_counts_with_attachments
    336      * @ticket 40351
    337331     *
    338332     * @param string $original_post_status Post status upon create.
     
    405399
    406400    /**
    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
    458404     * @covers ::wp_publish_post
    459405     * @dataProvider data_term_counts_incremented_on_publish_with_untermed_attachments
    460      * @ticket 40351
    461406     * @ticket 51292
    462407     *
     
    504449
    505450    /**
    506      * Test post status transition update term counts correctly.
    507      *
    508      * @covers ::wp_modify_term_count_by
     451     * Test post status transition update term counts correctly on post with attachment.
     452     *
     453     * @covers ::wp_update_term_count
    509454     * @dataProvider data_term_count_transitions_update_term_counts_with_untermed_attachments
    510      * @ticket 40351
    511455     *
    512456     * @param string $original_post_status Post status upon create.
     
    580524     * User taxonomy term counts increments when added to an account.
    581525     *
    582      * @covers ::wp_modify_term_count_by
     526     * @covers ::wp_update_term_count
    583527     * @ticket 51292
    584528     */
     
    594538     * User taxonomy term counts decrement when term deleted from user.
    595539     *
    596      * @covers ::wp_modify_term_count_by
     540     * @covers ::wp_update_term_count
    597541     * @ticket 51292
    598542     */
     
    605549        $this->assertSame( $expected, get_term( self::$user_term )->count );
    606550    }
    607 
    608     /**
    609      * Ensure DB queries for deferred counts are nullified for net zero gain.
    610      *
    611      * @covers ::wp_modify_term_count_by
    612      * @covers ::wp_defer_term_counting
    613      * @ticket 51292
    614      */
    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_by
    636      * @covers ::wp_update_term_count
    637      * @covers ::wp_defer_term_counting
    638      * @ticket 51292
    639      */
    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_by
    660      * @covers ::wp_defer_term_counting
    661      * @ticket 51292
    662      */
    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 update
    689          * 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     }
    695551}
Note: See TracChangeset for help on using the changeset viewer.