- Timestamp:
- 09/05/2025 01:28:20 PM (3 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/post/updateTermCountOnTransitionPostStatus.php
r60510 r60711 2 2 3 3 /** 4 * Tests for the _update_term_count_on_transition_post_statusfunction.4 * Tests for the `_update_term_count_on_transition_post_status()` function. 5 5 * 6 * See Tests_Term_WpSetObjectTermsfor tests that cover changing terms on a post when saving it.6 * See `Tests_Term_WpSetObjectTerms` for tests that cover changing terms on a post when saving it. 7 7 * 8 8 * @group taxonomy … … 140 140 */ 141 141 public function test_term_count_is_not_recalculated_when_status_does_not_change() { 142 // Create a mock action for `edited_term_taxonomy` to prevent flaky test. 143 $action = new MockAction(); 144 add_action( 'edited_term_taxonomy', array( $action, 'action' ) ); 142 // Create a mock action for checking the `edited_term_taxonomy` hook call count. 143 $edited_term_taxonomy_action = new MockAction(); 144 add_action( 'edited_term_taxonomy', array( $edited_term_taxonomy_action, 'action' ) ); 145 146 // Create a mock action for checking the `update_term_count` hook call count. 147 $update_term_count_action = new MockAction(); 148 add_action( 'update_term_count', array( $update_term_count_action, 'action' ) ); 145 149 146 150 $post_id = self::factory()->post->create( … … 156 160 self::$taxonomy 157 161 ); 158 $edited_term_taxonomy_count = $action->get_call_count(); 162 $edited_term_taxonomy_count = $edited_term_taxonomy_action->get_call_count(); 163 $update_term_count_action_count = $update_term_count_action->get_call_count(); 159 164 160 165 // Change something about the post but not its status. … … 166 171 ); 167 172 168 $this->assertSame( 0, $action->get_call_count() - $edited_term_taxonomy_count, 'Term taxonomy count should not be recalculated when post status does not change.' ); 173 $this->assertSame( 0, $edited_term_taxonomy_action->get_call_count() - $edited_term_taxonomy_count, 'Term taxonomy count should not be recalculated when post status does not change.' ); 174 $this->assertSame( 0, $update_term_count_action->get_call_count() - $update_term_count_action_count, 'The `update_term_count` action should not run when term taxonomy count is not recalculated.' ); 169 175 $this->assertTermCount( 2, self::$term_id ); 170 176 } … … 178 184 */ 179 185 public function test_term_count_is_not_recalculated_when_both_status_are_counted() { 180 // Create a mock action for `edited_term_taxonomy` to prevent flaky test. 181 $action = new MockAction(); 182 add_action( 'edited_term_taxonomy', array( $action, 'action' ) ); 186 // Create a mock action for checking the `edited_term_taxonomy` hook call count. 187 $edited_term_taxonomy_action = new MockAction(); 188 add_action( 'edited_term_taxonomy', array( $edited_term_taxonomy_action, 'action' ) ); 189 190 // Create a mock action for checking the `update_term_count` hook call count. 191 $update_term_count_action = new MockAction(); 192 add_action( 'update_term_count', array( $update_term_count_action, 'action' ) ); 183 193 184 194 // Register a custom status that is included in term counts. … … 207 217 ); 208 218 209 $this->assertSame( 0, $action->get_call_count(), 'Term taxonomy count should not be recalculated both statuses are included in term counts.' ); 219 $this->assertSame( 0, $edited_term_taxonomy_action->get_call_count(), 'Term taxonomy count should not be recalculated when both statuses are included in term counts.' ); 220 $this->assertSame( 0, $update_term_count_action->get_call_count(), 'The `update_term_count` action should not run when term taxonomy count is not recalculated.' ); 210 221 $this->assertTermCount( 1, self::$term_id, 'Term count should remain unchanged when transitioning between post statuses that are counted.' ); 211 222 } … … 219 230 */ 220 231 public function test_term_count_is_not_recalculated_when_neither_status_is_counted() { 221 // Create a mock action for `edited_term_taxonomy` to prevent flaky test. 222 $action = new MockAction(); 223 add_action( 'edited_term_taxonomy', array( $action, 'action' ) ); 232 // Create a mock action for checking the `edited_term_taxonomy` hook call count. 233 $edited_term_taxonomy_action = new MockAction(); 234 add_action( 'edited_term_taxonomy', array( $edited_term_taxonomy_action, 'action' ) ); 235 236 // Create a mock action for checking the `update_term_count` hook call count. 237 $update_term_count_action = new MockAction(); 238 add_action( 'update_term_count', array( $update_term_count_action, 'action' ) ); 224 239 225 240 // Change post status to draft. … … 231 246 ); 232 247 233 $edited_term_taxonomy_count = $action->get_call_count(); 248 $edited_term_taxonomy_count = $edited_term_taxonomy_action->get_call_count(); 249 $update_term_count_action_count = $update_term_count_action->get_call_count(); 234 250 235 251 // Change the post to another status that is not included in term counts. … … 241 257 ); 242 258 243 $this->assertSame( 0, $action->get_call_count() - $edited_term_taxonomy_count, 'Term taxonomy count should not be recalculated when neither new nor old post status is included in term counts.' ); 259 $this->assertSame( 0, $edited_term_taxonomy_action->get_call_count() - $edited_term_taxonomy_count, 'Term taxonomy count should not be recalculated when neither new nor old post status is included in term counts.' ); 260 $this->assertSame( 0, $update_term_count_action->get_call_count() - $update_term_count_action_count, 'The `update_term_count` action should not run when term taxonomy count is not recalculated.' ); 244 261 $this->assertTermCount( 0, self::$term_id, 'Term count should remain unchanged when transitioning between post statuses that are not counted.' ); 245 262 } … … 251 268 */ 252 269 public function test_update_post_term_count_statuses_filter_is_respected() { 253 // Create a mock action for `edited_term_taxonomy` to prevent flaky test. 254 $action = new MockAction(); 255 add_action( 'edited_term_taxonomy', array( $action, 'action' ) ); 270 // Create a mock action for checking the `edited_term_taxonomy` hook call count. 271 $edited_term_taxonomy_action = new MockAction(); 272 add_action( 'edited_term_taxonomy', array( $edited_term_taxonomy_action, 'action' ) ); 273 274 // Create a mock action for checking the `update_term_count` hook call count. 275 $update_term_count_action = new MockAction(); 276 add_action( 'update_term_count', array( $update_term_count_action, 'action' ) ); 256 277 257 278 $custom_taxonomy = 'category_with_pending'; … … 294 315 ); 295 316 296 $edited_term_taxonomy_count = $action->get_call_count(); 317 $edited_term_taxonomy_count = $edited_term_taxonomy_action->get_call_count(); 318 $update_term_count_action_count = $update_term_count_action->get_call_count(); 297 319 298 320 // Change the post to another status that is included in term counts for one of its two taxonomies. … … 304 326 ); 305 327 306 $this->assertSame( 1, $action->get_call_count() - $edited_term_taxonomy_count, 'Term taxonomy count should respect the statuses returned by the update_post_term_count_statuses filter.' ); 328 $this->assertSame( 1, $edited_term_taxonomy_action->get_call_count() - $edited_term_taxonomy_count, 'Term taxonomy count should respect the statuses returned by the update_post_term_count_statuses filter.' ); 329 $this->assertSame( 1, $update_term_count_action->get_call_count() - $update_term_count_action_count, 'The `update_term_count` action should run when term taxonomy count is recalculated.' ); 307 330 $this->assertTermCount( 0, self::$term_id, 'Term count for the default taxonomy should remain zero since "pending" is not included in its countable statuses.' ); 308 331 $this->assertTermCount( 1, $custom_term_id, 'Term count for the custom taxonomy should be updated to 1 because the "pending" status is included via the update_post_term_count_statuses filter.' );
Note: See TracChangeset
for help on using the changeset viewer.