Skip to content

Tests: Add test cases for wp_find_hierarchy_loop() - #8091

Closed
Sukhendu2002 wants to merge 2 commits into
WordPress:trunkfrom
Sukhendu2002:try/59901-tests-for-wp-find-hierarchy-loop
Closed

Sukhendu2002 wants to merge 2 commits into
WordPress:trunkfrom
Sukhendu2002:try/59901-tests-for-wp-find-hierarchy-loop

Conversation

@Sukhendu2002

@Sukhendu2002 Sukhendu2002 commented Jan 7, 2025 •

Copy link
Copy Markdown

Adds two cases for wp_find_hierarchy_loop(): a terminating hierarchy returns no loop, and a cycle reached through a noncycle node returns only its members.

Preserves the two tests already landed in [65146], removes duplicate self-loop and longer terminating-chain cases, and corrects the group annotation to functions.

Trac ticket: https://core.trac.wordpress.org/ticket/59901

@github-actions

github-actions Bot commented Jan 7, 2025

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@Sukhendu2002
Sukhendu2002 marked this pull request as ready for review January 7, 2025 06:24
@github-actions

github-actions Bot commented Jan 7, 2025 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props sukhendu2002, lancewillett.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The six new tests use the wrong PHPUnit group, so they will be skipped when running with --group functions; the annotation should be changed to @group functions.

1 open issue
What changed in this PR

Adds PHPUnit coverage for wp_find_hierarchy_loop() as part of WordPress Core’s function tests, addressing Trac ticket #59901.

Changes:

  • Adds six tests covering basic cycles, null-parent handling, self-references, and acyclic hierarchies.
  • Checks detection of a cycle reached after traversing multiple hierarchy levels.
File Description
tests/​phpunit/​tests/​functions/​wpFindHierarchyLoop.php Adds hierarchy-loop detection tests and expected-result assertions.

Review effort: Balanced

@lancewillett lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The affected classes pass locally in single-site and multisite. Before approval, please fix @group Functions.php to @group functions, as Copilot noted; the current annotation omits these cases from the normal functions group. Optional: collapse the duplicate self-loop and terminating-chain scenarios, retaining the four distinct outcomes.

AI review · gpt-6

@lancewillett

Copy link
Copy Markdown
Member

Refreshed against trunk in f9a7491, preserving the two tests already landed and retaining only two distinct additions. Fixed the functions group annotation and removed the duplicate self-loop and longer terminating-chain cases.

All four cases pass in randomized single-site and multisite runs; PHPCS passes. Controlled mutations confirmed each new case catches a different regression that the existing two do not: an incorrect no-loop result, or inclusion of a node outside the cycle. The mutations were removed after validation. Fresh CI remains pending.

AI review · gpt-6

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the added hierarchy-loop tests and corrected test-group annotation.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@lancewillett lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The refresh preserves the two landed cases and adds two distinct checks: a terminating hierarchy and a cycle reached through a node outside that cycle. The duplicate cases are gone.

All four cases pass locally in randomized single-site and multisite runs. Two controlled mutations each failed only the corresponding new case, confirming that these assertions add protection. PHPCS passes, and current-head CI finished with 75 successful checks and 13 skipped.

The Trac milestone still needs updating before the SVN commit.

AI review · gpt-6

wporg-sync pushed a commit that referenced this pull request Nov 1, 2026
…the loop.

Verify that `wp_find_hierarchy_loop()` returns an empty array for a terminating chain and excludes a leading noncycle node from the returned cycle members. Preserve the existing loop cases and correct the `functions` group annotation.

Developed in: #8091

Props sukhendu2002.

See #59901.


git-svn-id: https://develop.svn.wordpress.org/trunk@65179 602fd350-edb4-49c9-b593-d223f7449a82
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Nov 1, 2026
…the loop.

Verify that `wp_find_hierarchy_loop()` returns an empty array for a terminating chain and excludes a leading noncycle node from the returned cycle members. Preserve the existing loop cases and correct the `functions` group annotation.

Developed in: WordPress/wordpress-develop#8091

Props sukhendu2002.

See #59901.

Built from https://develop.svn.wordpress.org/trunk@65179


git-svn-id: http://core.svn.wordpress.org/trunk@64328 1a063a9b-81f0-0310-95a4-ce76da25c4cd
@lancewillett

Copy link
Copy Markdown
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants