Skip to content

Tests: Add tests for get_boundary_post() working on non-singular pages - #9200

Closed
Adi-ty wants to merge 5 commits into
WordPress:trunkfrom
Adi-ty:test/get-boundary-post-non-singular-pages
Closed

Adi-ty wants to merge 5 commits into
WordPress:trunkfrom
Adi-ty:test/get-boundary-post-non-singular-pages

Conversation

@Adi-ty

@Adi-ty Adi-ty commented Jul 4, 2025

Copy link
Copy Markdown

Trac ticket: #22957

Patch used: #9040


Description

Added unit tests that verify get_boundary_post() works correctly from non-singular pages (homepage, archive pages) and maintains backward compatibility with single post pages.

Testing Instructions:

Run the following command to verify the tests:

npm run test:php -- --filter=Tests_Link_GetBoundaryPost

This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions

github-actions Bot commented Jul 4, 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.

Applies patch from WordPress#9040 to fix get_boundary_post() function when called from non-singular pages
@Adi-ty
Adi-ty marked this pull request as ready for review July 7, 2025 04:58
@github-actions

github-actions Bot commented Jul 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 iamadisingh, 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.

@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.

Removing the ! $post guard also allows get_boundary_post( true ) to continue without a current post. The same-term branch then dereferences $post->ID. Please retain a missing-post guard for that path and cover it alongside the intended non-singular success case.

AI review · gpt-6

@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 missing-post guard is restored, and the new regression exercises the exact failing path. The boundary and neighboring adjacent-post tests pass locally in randomized single-site and multisite runs: 22 tests, 114 assertions per mode, with no skips. Removing only the guard reproduces the null-property error; restoring it passes the same focused case. Current CI is green.

Optional: the existing adjacent-post suite already covers single-post and same-term first/last IDs, so those overlapping assertions can be trimmed without adding more cases. The missing-post and non-singular checks provide the useful new coverage.

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.

🟡 Changes recommended

The tests omit boundary-post retrieval without a current post when $in_same_term = false, allowing an unconditional ! $post guard regression to pass unnoticed.

1 open issue
What changed in this PR

Extends get_boundary_post() to work on non-singular pages, addressing Trac #22957, and adds regression tests for boundary selection and existing behavior.

Changes:

  • Removes the single-post restriction and requires a current post only for same-term queries.
  • Adds tests for homepage, archive, single-post, same-term, missing-post, and invalid-taxonomy behavior.
File Description
tests/​phpunit/​tests/​link/​getBoundaryPost.php Adds boundary-post tests across page contexts and parameter combinations.
src/​wp-includes/​link-template.php Relaxes page-context restrictions while retaining taxonomy and same-term validation.

Review effort: Balanced

$this->go_to( home_url( '/?s=no-matching-posts' ) );
$this->assertNull( get_post(), 'This test should be running without a current post.' );

$this->assertNull( get_boundary_post( true ) );
wporg-sync pushed a commit that referenced this pull request Oct 31, 2026
Allow `get_boundary_post()` to return the first or last post on non-singular pages. Retain the missing-post guard when `$in_same_term` needs a current post, and continue rejecting unknown taxonomies.

Add coverage for non-singular lookups and the missing-post case.

Developed in: #9200, #9040

Props pathawks, sirlouen, iamadisingh, mukesh27, devasheeshkaul.
Fixes #22957.


git-svn-id: https://develop.svn.wordpress.org/trunk@65151 602fd350-edb4-49c9-b593-d223f7449a82
@github-actions

Copy link
Copy Markdown

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 65151
GitHub commit: 890e607

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions Bot closed this Oct 31, 2026
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Oct 31, 2026
Allow `get_boundary_post()` to return the first or last post on non-singular pages. Retain the missing-post guard when `$in_same_term` needs a current post, and continue rejecting unknown taxonomies.

Add coverage for non-singular lookups and the missing-post case.

Developed in: WordPress/wordpress-develop#9200, WordPress/wordpress-develop#9040

Props pathawks, sirlouen, iamadisingh, mukesh27, devasheeshkaul.
Fixes #22957.

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


git-svn-id: http://core.svn.wordpress.org/trunk@64300 1a063a9b-81f0-0310-95a4-ce76da25c4cd
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