Skip to content

Tests: Add unit tests for the server-side rendering of the Post Date block - #15671

Closed
hmbashar wants to merge 1 commit into
WordPress:trunkfrom
hmbashar:66543-post-date-block-tests
Closed

hmbashar wants to merge 1 commit into
WordPress:trunkfrom
hmbashar:66543-post-date-block-tests

Conversation

@hmbashar

@hmbashar hmbashar commented Nov 6, 2026

Copy link
Copy Markdown

Adds unit tests for render_block_core_post_date() and register_block_core_post_date() in src/wp-includes/blocks/post-date.php, which were not referenced by any test. No behavior is changed. This is the first part of the ticket: the Post Excerpt block is covered in a separate pull request.

The new test class tests/phpunit/tests/blocks/renderPostDate.php (26 tests) covers:

  • The publish date of the post of the context (from the block bindings source core/post-data), the modified date for displayType modified (with the wp-block-post-date__modified-date class), and the datetime attribute when it is set. A binding that is complete does not replace it, and an incomplete one does not stop the date of the post from being used.
  • Nothing is rendered for an empty datetime.
  • The format: the one of the site, an empty one, or the one of the block (also a time), the time difference of a past (... ago) and of a future date (... from now), and the formatted date and the datetime attribute are escaped.
  • isLink links the date to the post (with an escaped URL), and not without a post or when it is false.
  • The classes: has-text-align-*, has-link-color, both together, and none for another element.
  • The block is registered with the render callback.

Testing:

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

I also temporarily broke the function (each part of the check of the bindings, the field and the class of the modified date, the empty check, the format and its default, the time difference and its texts, the escaping, the link and the classes) and confirmed that a new test fails for each one.

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

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.

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 reported for the added Post Date rendering and registration tests.

No open issues 🎉

What changed in this PR

Adds unit tests for the Post Date block’s server-side rendering and registration, addressing the Post Date portion of Trac #66543 without changing production behavior.

Changes:

  • Covers publish and modified dates, binding fallback, empty dates, formatting, and relative dates.
  • Checks escaping, post links, and attribute-driven CSS classes.
  • Verifies registration with the expected render callback.
File Description
tests/​phpunit/​tests/​blocks/​renderPostDate.php Adds 26 test cases covering Post Date rendering and block registration.

Review effort: Balanced

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

2 participants