diff --git a/tests/phpunit/tests/term/cache.php b/tests/phpunit/tests/term/cache.php index f299bf9bed643..99a73f7823e71 100644 --- a/tests/phpunit/tests/term/cache.php +++ b/tests/phpunit/tests/term/cache.php @@ -445,4 +445,56 @@ public function test_get_object_term_cache_should_return_error_if_any_term_is_an $terms = get_the_terms( $p, 'wptests_tax' ); $this->assertWPError( $terms ); } + + /** + * Ensures that the term query cache is cleared when a child term is inserted. + * + * @ticket 62031 + */ + public function test_inserting_child_term_clears_the_query_cache() { + register_taxonomy( + 'wptests_tax', + 'post', + array( + 'hierarchical' => true, + ) + ); + + $parent = self::factory()->term->create( + array( + 'taxonomy' => 'wptests_tax', + ) + ); + + $children = get_terms( + array( + 'taxonomy' => 'wptests_tax', + 'hide_empty' => false, + 'parent' => $parent, + 'fields' => 'ids', + ) + ); + + $this->assertEmpty( $children, 'No child terms are expected to exist.' ); + + $child = wp_insert_term( + 'child-term-62031', + 'wptests_tax', + array( + 'parent' => $parent, + ) + ); + + $children = get_terms( + array( + 'taxonomy' => 'wptests_tax', + 'hide_empty' => false, + 'parent' => $parent, + 'fields' => 'ids', + ) + ); + + $this->assertNotEmpty( $children, 'Child terms are expected to exist.' ); + $this->assertContains( $child['term_id'], $children, 'Querying by parent ID is expected to include the new child term.' ); + } }