Skip to content

Commit

Permalink
Taxonomy: Test inserting a child term flushes queries by term ID.
Browse files Browse the repository at this point in the history
Adds a test to ensure that interting a child term invalidates the cache of a `get_terms()` query by the parent ID.

Props Dekadinious, peterwilsoncc.
See #62031, #61530.



git-svn-id: https://develop.svn.wordpress.org/trunk@59015 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
peterwilsoncc committed Sep 11, 2024
1 parent f7d9b1b commit 1931906
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions tests/phpunit/tests/term/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.' );
}
}

0 comments on commit 1931906

Please sign in to comment.