Repository navigation
Tests: Add unit test coverage for cat_is_ancestor_of() - #14430
rejaulalomkhan wants to merge 2 commits into
Conversation
Adds comprehensive PHPUnit tests covering direct parent and grandparent category ancestor checks, non-ancestor hierarchies, self-comparison, category ID and WP_Term object parameter variations, non-existent categories, invalid and empty inputs, and terms from different taxonomies. See #65819.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
There was a problem hiding this comment.
🟡 Changes recommended
The replacement taxonomy checks lose existing regression coverage for the category-only restriction.
1 open issue
What changed in this PR
Expands and reorganizes PHPUnit coverage for cat_is_ancestor_of() without changing production code.
Changes:
- Splits hierarchy checks into focused tests.
- Adds data providers for parameter types and invalid inputs.
- Adds missing-category and cross-taxonomy cases.
| File | Description |
|---|---|
| tests/phpunit/tests/category/catIsAncestorOf.php | Refactors fixtures and expands category ancestry tests. |
Review effort: Balanced
| $this->assertFalse( cat_is_ancestor_of( self::$tag_id, self::$child_id ) ); | ||
| $this->assertFalse( cat_is_ancestor_of( self::$parent_id, self::$tag_id ) ); |
lancewillett
left a comment
There was a problem hiding this comment.
Please retain the existing cross-taxonomy regression test. The replacement checks weaken that protection even though they pass.
Reviewed with the unit-tests audit and the fresh Copilot review.
AI review · gpt-6
| * @ticket 65819 | ||
| */ | ||
| public function test_returns_false_for_term_from_different_taxonomy() { | ||
| $this->assertFalse( cat_is_ancestor_of( self::$tag_id, self::$child_id ) ); |
There was a problem hiding this comment.
Please restore test_returns_false_for_term_ids_from_another_taxonomy() with a real parent–child pair in another hierarchical taxonomy. These new tag/category pairs are unrelated, so they still return false if taxonomy lookup is accidentally unrestricted. The deleted related-term fixture would detect that regression.
The tag/category checks use unrelated terms, so they still pass if the taxonomy lookup is accidentally unrestricted. A real parent-child pair in another hierarchical taxonomy catches that regression. See #65819.
|
@lancewillett Thanks for the review! Addressed in bd939b7:
|

Adds unit test coverage for
cat_is_ancestor_of()insrc/wp-includes/category.php.Test scenarios covered:
parent -> child,grandparent -> parent).grandparent -> child).cat1 === cat2returnsfalse).WP_Termobjects, and mixed ID/object inputs via@dataProvider.0,'',null,false) via@dataProvider.post_tag).Verification:
OK (16 tests, 23 assertions)OK (16 tests, 23 assertions)OK (16 tests, 23 assertions)0 errors, 0 warnings)Trac ticket: https://core.trac.wordpress.org/ticket/65819
Use of AI Tools: Antigravity (Gemini 2.5) was used to assist in test case ideation, code scaffolding, and formatting to WordPress core standards. All assertions and test outcomes were verified locally through PHPUnit and PHPCS.
Use of AI Tools
AI assistance: Yes
Tool(s): Antigravity
Model(s): Gemini 2.5
Used for: Writing PHPUnit unit test coverage for cat_is_ancestor_of(), running test assertions, PHPCS, and quality gate checks. All code was reviewed and verified.