Opened 2 hours ago
Last modified 2 hours ago
#66598 new enhancement
Tests: Add unit tests for the server-side rendering of the Calendar block
| Reported by: | hmbashar | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Editor | Version: | |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: |
Description
The Calendar block (core/calendar) is rendered on the server by the functions in src/wp-includes/blocks/calendar.php. They have no tests.
This ticket adds tests for the functions of the file, in separate pull requests:
render_block_core_calendar(): nothing for a site without published posts (and the notice for a logged in user), the colors, the link color, the month and the year of the attributes with the permalink structure, and the restoring of the globals;block_core_calendar_has_published_posts()and the functions that keep its flag up to date on single sites:block_core_calendar_update_has_published_posts(),block_core_calendar_update_has_published_post_on_delete()andblock_core_calendar_update_has_published_post_on_transition_post_status().
Change History (2)
This ticket was mentioned in PR #15810 on WordPress/wordpress-develop by @hmbashar.
2 hours ago
#1
- Keywords has-patch has-unit-tests added
This ticket was mentioned in PR #15811 on WordPress/wordpress-develop by @hmbashar.
2 hours ago
#2
Summary
Adds tests for the functions of the Calendar block that keep the flag of the published posts up to date on single sites. This is the second pull request for the ticket; the first one covers the rendering of the block and the check for published posts. The functions are only defined on single sites, so the test class is in the ms-excluded group.
block_core_calendar_update_has_published_post_on_delete(): the flag is updated for a published post, and not for a draft, a private post, a page or a post that does not exist.block_core_calendar_update_has_published_post_on_transition_post_status(): the flag is updated when a post is published or unpublished (including from or to private), and not when the status is the same, when neither status ispublish, or for a page.- The functions are hooked to
delete_postandtransition_post_status, and the flag follows a post that is created as published, published and unpublished.
Testing
vendor/bin/phpunit --filter 'Tests_Blocks_CalendarPublishedPostsFlag::' vendor/bin/phpcs tests/phpunit/tests/blocks/calendarPublishedPostsFlag.php
Mutation check: 13 changes to the two functions and their hooks were each caught by a test.
Not asserted: block_core_calendar_update_has_published_post_on_delete() runs on delete_post, before the post is deleted, so the post is still counted when the flag is updated. The tests call the function directly.
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.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Summary
Adds tests for
render_block_core_calendar()and the check for published posts,block_core_calendar_has_published_posts()andblock_core_calendar_update_has_published_posts(), which had no tests. This is the first pull request for the ticket; the handlers that keep the flag up to date on single sites follow in a separate one.$monthnumand$yearglobals.block_core_calendar_has_published_posts(): thepost_countoption on a multisite, the cached option on a single site, and the query and the saved flag when the option is missing.block_core_calendar_update_has_published_posts(): only published posts count, not drafts or pages.The tests that depend on a single site or on a multisite use the
ms-excludedandms-requiredgroups.Testing
Mutation check: 34 changes to the functions were each caught by a test (the two for the multisite branch with the multisite configuration).
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.