| 194 | |
| 195 | public function test_defer_term_counting_term_cache( $value = null ) { |
| 196 | // Temporarily disable term counting. |
| 197 | wp_defer_term_counting( true ); |
| 198 | |
| 199 | // Create Test Category. |
| 200 | $term_id = self::factory()->category->create( array( |
| 201 | 'slug' => 'uncounted-category', |
| 202 | ) ); |
| 203 | |
| 204 | // Create the blank post object to mimic the "Write" screen. |
| 205 | $post = get_default_post_to_edit( 'post', true ); |
| 206 | |
| 207 | // Save a draft of the post. |
| 208 | wp_update_post( array( |
| 209 | 'ID' => $post->ID, |
| 210 | 'post_status' => 'draft', |
| 211 | 'post_title' => 'some-post', |
| 212 | 'post_type' => 'post', |
| 213 | 'post_content' => 'some_content', |
| 214 | 'post_category' => array( $term_id ), |
| 215 | ) ); |
| 216 | |
| 217 | // Ensure that caches were cleared. |
| 218 | $terms = get_the_terms( $post->ID, 'category' ); |
| 219 | |
| 220 | // Re-activate term counting so this doesn't affect other tests. This |
| 221 | // doesn't affect the assertions because `$terms` is already populated. |
| 222 | wp_defer_term_counting( false ); |
| 223 | |
| 224 | $this->assertTrue( is_array( $terms ) ); |
| 225 | $this->assertSame( array( $term_id ), wp_list_pluck( $terms, 'term_id' ) ); |
| 226 | } |