Skip to content

Commit 1931906

Browse files
committed
Taxonomy: Test inserting a child term flushes queries by term ID.
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
1 parent f7d9b1b commit 1931906

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

tests/phpunit/tests/term/cache.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,4 +445,56 @@ public function test_get_object_term_cache_should_return_error_if_any_term_is_an
445445
$terms = get_the_terms( $p, 'wptests_tax' );
446446
$this->assertWPError( $terms );
447447
}
448+
449+
/**
450+
* Ensures that the term query cache is cleared when a child term is inserted.
451+
*
452+
* @ticket 62031
453+
*/
454+
public function test_inserting_child_term_clears_the_query_cache() {
455+
register_taxonomy(
456+
'wptests_tax',
457+
'post',
458+
array(
459+
'hierarchical' => true,
460+
)
461+
);
462+
463+
$parent = self::factory()->term->create(
464+
array(
465+
'taxonomy' => 'wptests_tax',
466+
)
467+
);
468+
469+
$children = get_terms(
470+
array(
471+
'taxonomy' => 'wptests_tax',
472+
'hide_empty' => false,
473+
'parent' => $parent,
474+
'fields' => 'ids',
475+
)
476+
);
477+
478+
$this->assertEmpty( $children, 'No child terms are expected to exist.' );
479+
480+
$child = wp_insert_term(
481+
'child-term-62031',
482+
'wptests_tax',
483+
array(
484+
'parent' => $parent,
485+
)
486+
);
487+
488+
$children = get_terms(
489+
array(
490+
'taxonomy' => 'wptests_tax',
491+
'hide_empty' => false,
492+
'parent' => $parent,
493+
'fields' => 'ids',
494+
)
495+
);
496+
497+
$this->assertNotEmpty( $children, 'Child terms are expected to exist.' );
498+
$this->assertContains( $child['term_id'], $children, 'Querying by parent ID is expected to include the new child term.' );
499+
}
448500
}

0 commit comments

Comments
 (0)