Skip to content

Tests: Add unit tests for the server-side rendering of the Site Logo block - #15648

Closed
hmbashar wants to merge 2 commits into
WordPress:trunkfrom
hmbashar:66532-site-logo-render-tests
Closed

hmbashar wants to merge 2 commits into
WordPress:trunkfrom
hmbashar:66532-site-logo-render-tests

Conversation

@hmbashar

@hmbashar hmbashar commented Nov 6, 2026

Copy link
Copy Markdown

Adds unit tests for render_block_core_site_logo(), register_block_core_site_logo() and the two settings in src/wp-includes/blocks/site-logo.php, which were not referenced by any test. No behavior is changed. This is the first part of the ticket: the functions that keep the site_logo option and the custom_logo theme modification in sync are covered in a separate pull request.

The new test class tests/phpunit/tests/blocks/renderSiteLogo.php (19 tests) covers:

  • Nothing is rendered without a logo.
  • The logo is rendered in a <div> with the is-default-size class, with a link to the home page (rel="home").
  • isLink false removes the link and keeps the image, and the target is not used without a link.
  • linkTarget _blank adds target="_blank" and the "(Home link, opens in a new tab)" label, only when the link has the home rel.
  • The width attribute sets the width of the image and keeps the ratio for the height (and the source of the image), the default size class is not added with a width and is added for an empty width (null, zero, an empty string or '0'), and the size of an image without dimensions is not changed.
  • The filter that sets the size is removed after the block is rendered.
  • The block, the site_logo setting (integer, in the REST API as site_logo) and the site_icon setting (integer, in the REST API) are registered, and the settings are hooked to rest_api_init.

Testing:

  • vendor/bin/phpunit --filter Tests_Blocks_RenderSiteLogo
  • vendor/bin/phpunit -c tests/phpunit/multisite.xml --filter Tests_Blocks_RenderSiteLogo
  • vendor/bin/phpcs tests/phpunit/tests/blocks/renderSiteLogo.php

I also temporarily broke the functions (each check of the width and of the image in the filter, the calculation of the height, the filter that is added and removed, the check of an empty logo, the removal of the link, each condition of the target, the label, the default size class, the wrapper, each argument of the two settings and their hooks, and the render callback) and confirmed that a new test fails for each one, except for two mutants that do not change the output: the check that the image is not empty (the checks of its dimensions already return the image) and the isLink check of the target (the link is already removed in that case).

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

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.

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

1 participant