Changeset 49451 for trunk/tests/phpunit/tests/taxonomy.php
- Timestamp:
- 10/30/2020 04:57:16 AM (6 years ago)
- File:
-
- 1 edited
-
trunk/tests/phpunit/tests/taxonomy.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/taxonomy.php
r49328 r49451 5 5 */ 6 6 class Tests_Taxonomy extends WP_UnitTestCase { 7 8 /**9 * Number of times full count callback has been called.10 *11 * @var int12 */13 public $full_count_cb_called = 0;14 15 /**16 * Number of times partial count callback has been called.17 *18 * @var int19 */20 public $partial_count_cb_called = 0;21 22 7 function test_get_post_taxonomies() { 23 8 $this->assertSame( array( 'category', 'post_tag', 'post_format' ), get_object_taxonomies( 'post' ) ); … … 1068 1053 $this->assertContains( $tax2, $taxonomies ); 1069 1054 } 1070 1071 /**1072 * Ensure custom callbacks are used when registered.1073 *1074 * @covers ::register_taxonomy1075 * @ticket 403511076 */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, therefore1145 * 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, therefore1158 * 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 }1167 1055 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)