Make WordPress Core


Ignore:
Timestamp:
10/30/2020 04:57:16 AM (6 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/taxonomy.php

    r49328 r49451  
    55 */
    66class Tests_Taxonomy extends WP_UnitTestCase {
    7 
    8         /**
    9          * Number of times full count callback has been called.
    10          *
    11          * @var int
    12          */
    13         public $full_count_cb_called = 0;
    14 
    15         /**
    16          * Number of times partial count callback has been called.
    17          *
    18          * @var int
    19          */
    20         public $partial_count_cb_called = 0;
    21 
    227        function test_get_post_taxonomies() {
    238                $this->assertSame( array( 'category', 'post_tag', 'post_format' ), get_object_taxonomies( 'post' ) );
    … …  
    10681053                $this->assertContains( $tax2, $taxonomies );
    10691054        }
    1070 
    1071         /**
    1072          * Ensure custom callbacks are used when registered.
    1073          *
    1074          * @covers ::register_taxonomy
    1075          * @ticket 40351
    1076          */
    1077         function test_register_taxonomy_counting_callbacks() {
    1078                 $post_id = self::factory()->post->create();
    1079 
    1080                 register_taxonomy(
    1081                         'wp_tax_40351_full_only',
    1082                         'post',
    1083                         array(
    1084                                 'update_count_callback' => array( $this, 'cb_register_taxonomy_full_count_callback' ),
    1085                         )
    1086                 );
    1087                 $full_term    = self::factory()->term->create_and_get(
    1088                         array(
    1089                                 'taxonomy' => 'wp_tax_40351_full_only',
    1090                         )
    1091                 );
    1092                 $full_term_id = $full_term->term_id;
    1093 
    1094                 register_taxonomy(
    1095                         'wp_tax_40351_partial_only',
    1096                         'post',
    1097                         array(
    1098                                 'update_count_by_callback' => array( $this, 'cb_register_taxonomy_partial_count_callback' ),
    1099                         )
    1100                 );
    1101                 $partial_term    = self::factory()->term->create_and_get(
    1102                         array(
    1103                                 'taxonomy' => 'wp_tax_40351_partial_only',
    1104                         )
    1105                 );
    1106                 $partial_term_id = $partial_term->term_id;
    1107 
    1108                 register_taxonomy(
    1109                         'wp_tax_40351_both',
    1110                         'post',
    1111                         array(
    1112                                 'update_count_callback'    => array( $this, 'cb_register_taxonomy_full_count_callback' ),
    1113                                 'update_count_by_callback' => array( $this, 'cb_register_taxonomy_partial_count_callback' ),
    1114                         )
    1115                 );
    1116                 $both_term      = self::factory()->term->create_and_get(
    1117                         array(
    1118                                 'taxonomy' => 'wp_tax_40351_both',
    1119                         )
    1120                 );
    1121                 $both_term_id   = $both_term->term_id;
    1122                 $both_term_ttid = $both_term->term_taxonomy_id;
    1123 
    1124                 wp_set_post_terms( $post_id, $full_term_id, 'wp_tax_40351_full_only' );
    1125                 $this->assertSame( 0, $this->partial_count_cb_called );
    1126                 $this->assertSame( 1, $this->full_count_cb_called );
    1127 
    1128                 wp_set_post_terms( $post_id, $partial_term_id, 'wp_tax_40351_partial_only' );
    1129                 $this->assertSame( 1, $this->partial_count_cb_called );
    1130                 $this->assertSame( 1, $this->full_count_cb_called );
    1131 
    1132                 wp_set_post_terms( $post_id, $both_term_id, 'wp_tax_40351_both' );
    1133                 $this->assertSame( 2, $this->partial_count_cb_called );
    1134                 $this->assertSame( 1, $this->full_count_cb_called );
    1135 
    1136                 // Force a full recount `$both_term` to ensure callback is called.
    1137                 wp_update_term_count( $both_term_ttid, 'wp_tax_40351_both' );
    1138                 $this->assertSame( 2, $this->full_count_cb_called );
    1139         }
    1140 
    1141         /**
    1142          * Custom full count callback for `test_register_taxonomy_counting_callbacks()`.
    1143          *
    1144          * For the purpose of this test no database modifications are required, therefore
    1145          * the parameters passed are unused.
    1146          *
    1147          * @param int|array $tt_ids   The term_taxonomy_id of the terms.
    1148          * @param string    $taxonomy The context of the term.
    1149          */
    1150         function cb_register_taxonomy_full_count_callback( $tt_ids, $taxonomy ) {
    1151                 $this->full_count_cb_called++;
    1152         }
    1153 
    1154         /**
    1155          * Custom partial count callback for `test_register_taxonomy_counting_callbacks()`.
    1156          *
    1157          * For the purpose of this test no database modifications are required, therefore
    1158          * the parameters passed are unused.
    1159          *
    1160          * @param int|array $tt_ids    The term_taxonomy_id of the terms.
    1161          * @param string    $taxonomy  The context of the term.
    1162          * @param int       $modify_by By how many the term count is to be modified.
    1163          */
    1164         function cb_register_taxonomy_partial_count_callback( $tt_ids, $taxonomy, $modify_by ) {
    1165                 $this->partial_count_cb_called++;
    1166         }
    11671055}
Note: See TracChangeset for help on using the changeset viewer.