Skip to content

Tests: Cover the early return in paginate_links() when total is less than 2 - #16229

Open
shail-mehta wants to merge 5 commits into
WordPress:trunkfrom
shail-mehta:tests/66757-paginate-links-total
Open

shail-mehta wants to merge 5 commits into
WordPress:trunkfrom
shail-mehta:tests/66757-paginate-links-total

Conversation

@shail-mehta

@shail-mehta shail-mehta commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

What

Trac ticket: #66827

Adds a unit test for the one-page boundary in paginate_links(). The function returns null when (int) $args['total'] < 2, because there is nothing to paginate.

Why

Existing tests always pass a total of 2 or higher. When I removed the early return so that a total of 1 continued into link generation, those tests still passed.

How

This adds test_paginate_links_returns_null_when_total_less_than_two(). It asserts that paginate_links() returns null for 'total' => '1', which also exercises the (int) cast.

The expected value is the fixed null return, not markup derived from the function under test.

Testing Instructions

  • npm run test:php -- --filter test_paginate_links_returns_null_when_total_less_than_two: 1 test passes.
  • With the $total < 2 early return removed, the test fails.
  • With the guard changed to $total < 1, the test fails.
  • PHPCS reports no issues.

Use of AI Tools

  • Cursor

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 are recorded for the regression tests covering paginate_links()’s null return when fewer than two pages exist.

No open issues 🎉

What changed in this PR

Adds regression coverage for WordPress’s paginate_links() early return when fewer than two pages exist, addressing Trac #66757 without changing production code.

Changes:

  • Adds a data-driven test asserting that the result is specifically null.
  • Covers totals of 0 and 1 as both integers and numeric strings.
File Description
tests/​phpunit/​tests/​general/​paginateLinks.php Adds the null-return assertion and a provider containing four below-threshold cases.

Review effort: Balanced

@shail-mehta
shail-mehta marked this pull request as ready for review November 25, 2026 14:32
@github-actions

github-actions Bot commented Nov 25, 2026 •

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 shailu25, mukesh27, 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 or WordPress.org 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.

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

Thanks, @shail-mehta. I confirmed the gap: with the $total < 2 early return removed, the existing paginate_links() tests still pass and only these four cases fail. LGTM.

@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 boundary is worth covering. Changing the guard to $total < 1 failed the two one-page rows and passed both zero-page rows. Core casts the argument before comparing it. Please keep the one-page boundary as a single assertion (a numeric string is fine) and drop the four-row provider. The existing tests cover totals that produce links.

Before landing, please link a ticket in the component that owns the code under test, per the 7.3 ticket guidance. Related coverage can share a component ticket.

AI review · gpt-6.2-astra

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 pagination test covers only '1', leaving 0, 1, and '0' untested and allowing a regression in zero-page pagination to pass.

1 open issue

Review effort: Balanced

@shail-mehta

Copy link
Copy Markdown
Member Author

Addressed the feedback:

  • Dropped the four-row data provider; the test now asserts null for the one-page boundary ('total' => '1').
  • Linked the General component ticket: #66827.

Ready for another look.

@shail-mehta shail-mehta self-assigned this Nov 26, 2026

@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 single one-page case catches the boundary error: changing the comparison from less than two to less than one failed this assertion. The focused class passed in both site modes, and the PR now links its component ticket.

AI review · gpt-6.2-astra

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

Still LGTM after the update. The single 'total' => '1' case fails when the guard is changed to $total < 1, so it guards the exact boundary. My earlier provider suggestion no longer applies.

Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>

@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 new method name matches its single one-page case. The renamed test passed on single-site and multisite.

AI review · gpt-6.2-astra

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

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

4 participants