Skip to content

Tests: Add unit tests for the server-side rendering of the Post Navigation Link block - #15682

Closed
hmbashar wants to merge 3 commits into
WordPress:trunkfrom
hmbashar:66547-post-navigation-link-block-tests
Closed

hmbashar wants to merge 3 commits into
WordPress:trunkfrom
hmbashar:66547-post-navigation-link-block-tests

Conversation

@hmbashar

@hmbashar hmbashar commented Nov 6, 2026

Copy link
Copy Markdown

Adds unit tests for render_block_core_post_navigation_link(), block_core_post_navigation_link_get_support_styles() and register_block_core_post_navigation_link() in src/wp-includes/blocks/post-navigation-link.php, which were not referenced by any test. No behavior is changed.

The new test class tests/phpunit/tests/blocks/renderPostNavigationLink.php (48 tests) covers:

  • Nothing is rendered outside a single post or for a type that is not next or previous. The default is the next post.
  • The link to the next or the previous post with its rel and its label (Next or Previous), or the label of the block (cleaned with wp_kses_post()).
  • The title of the post: alone, with a label that is linked, with a label that is not linked, and the default label (Next: or Previous:).
  • The arrows (arrow and chevron, after the next link and before the previous one), and no arrow for none or an arrow that is not known.
  • The taxonomy of the block (the categories and the tags), so only the posts of the same term are linked.
  • The wrapper without a link when there is no adjacent post, or when a filter returns null, without the styles.
  • The classes of the wrapper (the type, the text alignment, the border color) and the styles of the block supports.
  • block_core_post_navigation_link_get_support_styles(): the border (a number is converted to pixels, the style, the color and the sides), the background image with its size and position defaults, the gradient, the minimum dimensions, the shadow and the spacing.
  • The block is registered with the render callback.

The function reads $attributes['linkLabel'] without checking that it is set (the block provides a default), so the tests pass it.

Testing:

  • vendor/bin/phpunit --filter 'Tests_Blocks_RenderPostNavigationLink::'
  • vendor/bin/phpunit -c tests/phpunit/multisite.xml --filter 'Tests_Blocks_RenderPostNavigationLink::'
  • vendor/bin/phpcs tests/phpunit/tests/blocks/renderPostNavigationLink.php

I also temporarily broke the functions in about 45 ways (each check, the labels and the arrows, the link function and the taxonomy, the cast of the content, each style of the support and its defaults, and the registration) and confirmed that a new test fails for each one, except for two mutants that do not change the result: the strict comparison of in_array() (a value of another type never matches the names of the types in PHP 8) and the check that has-background is not added twice (the style engine does not add it to the classes in those cases).

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

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, huzaifaalmesbah.

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.

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

When the block is already registered, the test fails to restore its original instance, leaving subsequent tests with a replacement that lacks bootstrapped support attributes.

1 open issue
What changed in this PR

Adds PHPUnit coverage for the Post Navigation Link block’s server-side rendering, support styles, and registration without changing production code.

Changes:

  • Tests navigation links, labels, titles, arrows, taxonomy restrictions, and empty output.
  • Verifies wrapper classes and styles, including borders, backgrounds, dimensions, shadows, and spacing.
  • Checks that the block is registered with the expected render callback.
File Description
tests/​phpunit/​tests/​blocks/​renderPostNavigationLink.php Adds fixtures and 48 test cases covering rendering, support styles, and registration.

Review effort: Balanced

@huzaifaalmesbah huzaifaalmesbah 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 for working on this, @hmbashar! I really appreciate you taking the time to cover the server-side rendering of the Post Navigation Link block (render_block_core_post_navigation_link(), block_core_post_navigation_link_get_support_styles(), and block registration). Local PHPUnit suite (48 tests, 52 assertions) and PHPCS/ESLint both pass cleanly.

I left a few small notes inline.

AI Review: Gemini 3.8 Flash

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

3 participants