Skip to content

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

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

shail-mehta wants to merge 1 commit 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: #66757

paginate_links() 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 0 or 1 continued into link generation, those tests still passed.

How?

This adds test_paginate_links_returns_null_when_total_less_than_two(). It asserts null for:

Case total
Zero 0
One 1
String zero '0'
String one '1'

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: 4 tests pass.
  • With the $total < 2 early return removed, all four cases fail.
  • 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

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.

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.

/**
* Data provider for test_paginate_links_returns_null_when_total_less_than_two().
*
* @return array[]

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 other provider in this file documents its shape (line 560). For consistency:

Suggested change
* @return array[]
* @return array<string, array{ 0: int|string }>

@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

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.

4 participants