Opened 102 minutes ago
Last modified 93 minutes ago
#66599 new enhancement
Tests: Add unit tests for the server-side rendering of the Button 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 Button block (core/button) is rendered on the server by render_block_core_button() in src/wp-includes/blocks/button.php. The function has no tests.
This ticket adds tests that cover:
- an empty button (or content without a link or button) being handled: nothing is rendered for an empty button, and the content is returned as it is without a link or button;
- the background: the image, size, position, repeat, attachment and gradient being added to the link, merged with its style, with the defaults for the size and the position;
- the width: a percentage (with the legacy classes), a fixed value and a preset, as the classes and the style of the wrapper.
Change History (1)
This ticket was mentioned in PR #15812 on WordPress/wordpress-develop by @hmbashar.
93 minutes ago
#1
- Keywords has-patch has-unit-tests added
Note:
See TracTickets
for help on using tickets.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Summary
Adds tests for
render_block_core_button(), the server-side rendering of the Button block, which had no tests.cover, the position of a contained image, the repeat, the attachment and the gradient, merged with the style of the element, and the classhas-background. Only the first link is changed, and a background without styles changes nothing.The test removes the presets it adds from the cached theme data.
Testing
Mutation check: 46 changes to the function (every branch of the empty check, the background and the width) were each caught by a test.
Not asserted: content that has tags but no link or button (for example a
divwith aspan) gives an empty string today, while the comment in the code says that content without a button is returned as it is. Only content without any tag is returned as it is.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.