Repository navigation
Conversation
…To Read block. See #66545.
|
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.
🟡 Changes recommended
Test cleanup leaks an altered block schema into subsequent tests instead of restoring the original object, and fractional non-range rounding lacks coverage.
2 open issues
What changed in this PR
Adds PHPUnit coverage for the Post Time To Read block’s server-side functions, addressing the first part of ticket #66545 without changing production code.
Changes:
- Tests word and character counting across HTML, whitespace, punctuation, entities, and Unicode.
- Covers reading-time output, ranges, custom speeds, count displays, missing post context, and text alignment.
- Verifies block registration and its render callback.
| File | Description |
|---|---|
tests/phpunit/tests/blocks/renderPostTimeToRead.php |
Adds 45 test cases for counting, server-side rendering, and block registration. |
Review effort: Balanced
… time to read tests. See #66545.


Adds unit tests for
block_core_post_time_to_read_word_count(),render_block_core_post_time_to_read()andregister_block_core_post_time_to_read()insrc/wp-includes/blocks/post-time-to-read.php, which were not referenced by any test. No behavior is changed. This is the first part of the ticket: the Post Terms block is covered in a separate pull request.The new test class
tests/phpunit/tests/blocks/renderPostTimeToRead.php(45 tests) covers:4–6 minutes, and a minimum of one with the maximum at least one more).1 word,12 words,1,200 words) and the number of characters for a language that counts them. An empty text is rendered for a display mode that is not known.has-text-align-*class and the registration of the block.Testing:
vendor/bin/phpunit --filter 'Tests_Blocks_RenderPostTimeToRead::'vendor/bin/phpunit -c tests/phpunit/multisite.xml --filter 'Tests_Blocks_RenderPostTimeToRead::'vendor/bin/phpcs tests/phpunit/tests/blocks/renderPostTimeToRead.phpI also temporarily broke the functions (each regular expression and step of the count, the check of the type, the check of the post, the default speed and display mode, each limit and calculation of the minutes and of the range, the texts of the words and the characters, the class and the registration) and confirmed that a new test fails for each one, except for two mutants that do not change the result: the early return for an empty text (the count of an empty text is zero anyway) and the replacement of astral characters (the regular expressions already count a code point as one).
Trac ticket: https://core.trac.wordpress.org/ticket/66545
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.