Skip to content

Tests: Add unit tests for the server-side rendering of the Video block - #15628

Closed
hmbashar wants to merge 2 commits into
WordPress:trunkfrom
hmbashar:66515-video-block-tests
Closed

hmbashar wants to merge 2 commits into
WordPress:trunkfrom
hmbashar:66515-video-block-tests

Conversation

@hmbashar

@hmbashar hmbashar commented Nov 6, 2026

Copy link
Copy Markdown

Adds unit tests for render_block_core_video() in src/wp-includes/blocks/video.php, which was not referenced by any test. No behavior is changed.

The new test class tests/phpunit/tests/blocks/renderVideo.php covers:

  • Content without a <video tag is returned unchanged and enqueues nothing (the check is case-insensitive, so <VIDEO> is handled).
  • The width, height and aspect-ratio style are added from the attachment metadata, replace existing dimensions, are placed before an existing style, replace a style attribute without a value, and are only added to the first video.
  • The dimensions are not added when the id is missing, null, zero, negative, a numeric string, a float or an array, when the current post is set and the id is zero, when the id is a post that is not an attachment or does not exist, or when the metadata has no valid dimensions (missing, zero, negative, string, float or null).
  • A video with the autoplay attribute (boolean, empty, uppercase or with a value) gets data-wp-interactive="core/video" and data-wp-init="callbacks.stopAutoplay" and enqueues the @wordpress/block-library/video/view script module. A video without it, or an autoplay that is only on a second video, does not.
  • The directives and the dimensions are both added to a video that autoplays and has an attachment.

The tests check the attributes of the video with WP_HTML_Tag_Processor instead of comparing the whole markup, because the order in which the processor adds new attributes is not part of the contract.

register_block_core_video() is not tested here, because it needs the built block.json of the block.

Testing:

  • vendor/bin/phpunit --filter Tests_Blocks_RenderVideo
  • vendor/bin/phpunit -c tests/phpunit/multisite.xml --filter Tests_Blocks_RenderVideo
  • vendor/bin/phpcs tests/phpunit/tests/blocks/renderVideo.php

I also temporarily broke the function (the case-insensitive check, the autoplay check, the enqueue, each directive, the update of the content, the type check of the id, the zero check, the attachment check, the integer and positive checks of the dimensions, each attribute, the order of the style, the order of the ratio and the string check of the style) and confirmed that a new test fails for each one, except for removing the early return for content without a video, which does not change the result because the tag processor finds no video.

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

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.

🟡 Changes recommended

The fixture lacks a commented-out autoplay video, so it does not verify that such content remains unchanged and no module is enqueued.

1 open issue
What changed in this PR

Adds unit tests for render_block_core_video(), expanding coverage of server-side Video block rendering without changing production behavior.

Changes:

  • Tests attachment dimensions, existing styles, and invalid IDs or metadata.
  • Covers autoplay directives, script-module enqueueing, and first-video-only handling.
  • Uses HTML attribute assertions to avoid depending on attribute order.
File Description
tests/​phpunit/​tests/​blocks/​renderVideo.php Adds Video block rendering tests with attachment fixtures and isolated script-module state.

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