Repository navigation
Tests: Cover the early return in paginate_links() when total is less than 2 - #16229
shail-mehta wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
🟢 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
0and1as 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
|
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: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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
|
Addressed the feedback:
Ready for another look. |
lancewillett
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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

What
Trac ticket: #66827
Adds a unit test for the one-page boundary in
paginate_links(). The function returnsnullwhen(int) $args['total'] < 2, because there is nothing to paginate.Why
Existing tests always pass a
totalof 2 or higher. When I removed the early return so that atotalof1continued into link generation, those tests still passed.How
This adds
test_paginate_links_returns_null_when_total_less_than_two(). It asserts thatpaginate_links()returnsnullfor'total' => '1', which also exercises the(int)cast.The expected value is the fixed
nullreturn, 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.$total < 2early return removed, the test fails.$total < 1, the test fails.Use of AI Tools