Repository navigation
Tests: Cover the early return in paginate_links() when total is less than 2 - #16229
shail-mehta wants to merge 1 commit 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.
| /** | ||
| * Data provider for test_paginate_links_returns_null_when_total_less_than_two(). | ||
| * | ||
| * @return array[] |
There was a problem hiding this comment.
The other provider in this file documents its shape (line 560). For consistency:
| * @return array[] | |
| * @return array<string, array{ 0: int|string }> |
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
What
Trac ticket: #66757
paginate_links()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 atotalof0or1continued into link generation, those tests still passed.How?
This adds
test_paginate_links_returns_null_when_total_less_than_two(). It assertsnullfor:total01'0''1'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: 4 tests pass.$total < 2early return removed, all four cases fail.Use of AI Tools