Skip to content

Block Bindings: Add unit tests for the list-item content-binding shim - #79854

Closed
cbravobernal wants to merge 1 commit into
trunkfrom
add/list-item-binding-shim-tests
Closed

cbravobernal wants to merge 1 commit into
trunkfrom
add/list-item-binding-shim-tests

Conversation

@cbravobernal

Copy link
Copy Markdown
Contributor

What?

Adds unit tests for gutenberg_restore_list_item_inner_blocks_after_binding, the WordPress 7.1 compat shim that restores a List Item's nested inner blocks after a content binding replaces the whole <li>.

Why?

The shim landed in #78947 / #79346 without unit tests. Extracted from #79852 to keep that PR focused on the innerBlocks binding mechanism.

How?

Two tests pinning the shim's behaviors:

  • On WP 6.9/7.0, where WP_Block::replace_html() lacks the inner-blocks fix (wordpress-develop#12113) and the content binding wipes the whole <li> inner HTML, the shim re-appends the instance's rendered inner blocks (called directly with the wiped state those cores produce).
  • End-to-end via render_block(): a content-bound List Item keeps its nested list, rendered exactly once (the str_contains guard prevents a double-append on fixed cores).

Testing Instructions

npx wp-env run --env-cwd='wp-content/plugins/gutenberg' tests-wordpress vendor/bin/phpunit -c phpunit.xml.dist --filter 'Tests_Block_Bindings_List_Item'

🤖 Generated with Claude Code

The gutenberg_restore_list_item_inner_blocks_after_binding shim (WP 7.1
compat, added in #78947/#79346) merged without unit tests. Pin its two
behaviors: restoring the nested inner blocks when the content binding
wipes the whole <li> on WP 6.9/7.0, and rendering them exactly once on
cores where WP_Block::replace_html() already preserves them.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jul 3, 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. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: cbravobernal <cbravobernal@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link
Copy Markdown
Contributor Author

Closing this as unnecessary.

The compat shim behavior is already covered by the existing list-item block bindings tests in phpunit/block-bindings-test.php, including nested list preservation, empty values, non-list inner blocks, and pattern overrides. Keeping this separate function-level test file would mostly duplicate that coverage and add maintenance surface without protecting additional behavior.

The shim itself still remains needed while Gutenberg supports WordPress versions where WP_Block::replace_html() drops nested inner blocks.

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