Skip to content

Tests: Add unit tests for the links and the numbers of the Comments Pagination blocks - #15659

Closed
hmbashar wants to merge 2 commits into
WordPress:trunkfrom
hmbashar:66538-comments-pagination-links-tests
Closed

hmbashar wants to merge 2 commits into
WordPress:trunkfrom
hmbashar:66538-comments-pagination-links-tests

Conversation

@hmbashar

@hmbashar hmbashar commented Nov 6, 2026

Copy link
Copy Markdown

Adds unit tests for the next link, the previous link and the page numbers of the Comments Pagination blocks (render_block_core_comments_pagination_next(), render_block_core_comments_pagination_previous() and render_block_core_comments_pagination_numbers()), which were not referenced by any test. No behavior is changed. This is the second part of the ticket: the wrapper is covered in a separate pull request.

The new test class tests/phpunit/tests/blocks/renderCommentsPaginationLinks.php (25 tests) uses a post with five comments, two comments for each page, and covers:

  • Next link: it links to the next page with the label Newer Comments (or the label of the block, escaped, or the default for an empty label) and the arrow or chevron of the context after the label. Nothing is rendered on the last page or without a postId.
  • Previous link: it links to the previous page with the label Older Comments (or the one of the block) and the arrow or chevron before the label. Nothing is rendered on the first page.
  • When the newest comments are the default and the page is not in the URL, the next link is not rendered and the previous link goes to the page before the last one.
  • Page numbers: one for each page, the current one marked, no previous and next links, nothing for a single page or without a postId.
  • The three blocks are registered with their render callbacks.

render_block_core_comments_pagination_next() removes the filter next_posts_link_attributes instead of next_comments_link_attributes after it adds the second one, so the filter is not removed. I did not assert that.

Testing:

  • vendor/bin/phpunit --filter Tests_Blocks_RenderCommentsPaginationLinks
  • vendor/bin/phpunit -c tests/phpunit/multisite.xml --filter Tests_Blocks_RenderCommentsPaginationLinks
  • vendor/bin/phpcs tests/phpunit/tests/blocks/renderCommentsPaginationLinks.php

I also temporarily broke the three functions (the check of the post, the labels, the arrows and their order, the escaping, the total, the current page and the page of the query, the options of the numbers, the empty checks, the tag and the render callbacks) and confirmed that a new test fails for each one.

Trac ticket: https://core.trac.wordpress.org/ticket/66538

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Sonnet 5.5
Used for: Written with AI and manually reviewed by me.


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 Nov 6, 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 hmbashar.

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.

@hmbashar hmbashar closed this Nov 7, 2026
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.

1 participant