diff --git a/src/wp-includes/block-bindings.php b/src/wp-includes/block-bindings.php index 5a20c023149d7..e4a371bdfa0b8 100644 --- a/src/wp-includes/block-bindings.php +++ b/src/wp-includes/block-bindings.php @@ -135,6 +135,7 @@ function get_block_bindings_source( string $source_name ) { * * @since 6.9.0 * @since 7.1.0 Added support for the List Item block. + * @since 7.1.0 Added support for the Icon block. * * @param string $block_type The block type whose supported attributes are being retrieved. * @return array The list of block attributes that are supported by block bindings. @@ -149,6 +150,7 @@ function get_block_bindings_supported_attributes( $block_type ) { 'core/post-date' => array( 'datetime' ), 'core/navigation-link' => array( 'url' ), 'core/navigation-submenu' => array( 'url' ), + 'core/icon' => array( 'icon' ), ); $supported_block_attributes = diff --git a/tests/phpunit/tests/block-bindings/render.php b/tests/phpunit/tests/block-bindings/render.php index 3ce1993e4c351..f363cd6cf2019 100644 --- a/tests/phpunit/tests/block-bindings/render.php +++ b/tests/phpunit/tests/block-bindings/render.php @@ -351,6 +351,71 @@ public function test_update_block_with_value_from_source_image_placeholder() { ); } + /** + * Tests if the Icon block's icon attribute is updated with the value + * returned by a block bindings source. + * + * @ticket 65725 + * + * @covers ::register_block_bindings_source + */ + public function test_update_icon_block_with_value_from_source() { + $get_value_callback = function () { + return 'test-icons/test-icon'; + }; + + wp_register_icon_collection( + 'test-icons', + array( 'label' => 'Test Icons' ) + ); + + wp_register_icon( + 'test-icons/test-icon', + array( + 'label' => 'Test Icon', + 'content' => '', + ) + ); + + register_block_bindings_source( + self::SOURCE_NAME, + array( + 'label' => self::SOURCE_LABEL, + 'get_value_callback' => $get_value_callback, + ) + ); + + try { + $block_content = << +
+ +HTML; + $parsed_blocks = parse_blocks( $block_content ); + $block = new WP_Block( $parsed_blocks[0] ); + $result = $block->render(); + + $this->assertSame( + 'test-icons/test-icon', + $block->attributes['icon'], + "The 'icon' attribute should be updated with the value returned by the source." + ); + $this->assertStringContainsString( + 'assertStringContainsString( + 'wp-block-icon', + $result, + 'The rendered output should contain the wp-block-icon class.' + ); + } finally { + wp_unregister_icon( 'test-icons/test-icon' ); + wp_unregister_icon_collection( 'test-icons' ); + } + } + /** * Tests if the `__default` attribute is replaced with real attributes for * pattern overrides.