Skip to content

Tests: Add unit tests for the helper functions of the Post Featured Image block - #15680

Closed
hmbashar wants to merge 1 commit into
WordPress:trunkfrom
hmbashar:66546-post-featured-image-helpers-tests
Closed

hmbashar wants to merge 1 commit into
WordPress:trunkfrom
hmbashar:66546-post-featured-image-helpers-tests

Conversation

@hmbashar

@hmbashar hmbashar commented Nov 6, 2026

Copy link
Copy Markdown

Adds unit tests for the helper functions of src/wp-includes/blocks/post-featured-image.php, get_block_core_post_featured_image_border_attributes() and get_block_core_post_featured_image_overlay_element_markup(), which were not referenced by any test. No behavior is changed. This is the first part of the ticket: the render callback is covered in a separate pull request.

The new test class tests/phpunit/tests/blocks/postFeaturedImageHelpers.php (21 tests) covers:

  • The attributes of the border of the image: the radius, the width and the style, a custom color (with has-border-color), a named color (which takes precedence over a custom one), the style of a side, and nothing for other styles.
  • The markup of the overlay: the dim ratio classes, a named color, a custom color, a named gradient (with has-background-gradient), a custom gradient, everything together with the border styles, the border classes, and the escaping of the classes.
  • No overlay without a dim ratio (missing, zero or null), even with colors.

Testing:

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

I also temporarily broke the functions (each part of the border, the precedence of the colors, each side, the classes and the styles that are returned, the check of the dim ratio, each class and style of the overlay and the escaping) and confirmed that a new test fails for each one.

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

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 remain for the added Post Featured Image helper tests.

No open issues 🎉

What changed in this PR

Adds unit tests for the Post Featured Image block’s border and overlay helpers, addressing the helper-testing portion of ticket #66546 without changing production behavior. Render callback coverage remains in a separate pull request.

Changes:

  • Adds 21 test cases covering border attributes, color precedence, overlay classes and styles, and class escaping.
  • Verifies that missing, zero, or null dim ratios produce no overlay.
  • Saves and restores block-support state to isolate the tests.
File Description
tests/​phpunit/​tests/​blocks/​postFeaturedImageHelpers.php Adds coverage for border attributes and overlay markup helpers.

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