Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/wp-includes/class-wp-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class WP_Block {
private const BLOCK_BINDINGS_SUPPORTED_ATTRIBUTES = array(
'core/paragraph' => array( 'content' ),
'core/heading' => array( 'content' ),
'core/image' => array( 'id', 'url', 'title', 'alt' ),
'core/image' => array( 'id', 'url', 'title', 'alt', 'caption' ),
'core/button' => array( 'url', 'text', 'linkTarget', 'rel' ),
'core/post-date' => array( 'datetime' ),
);
Expand Down
33 changes: 28 additions & 5 deletions tests/phpunit/tests/block-bindings/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ public function data_update_block_with_value_from_source() {
,
'<div class="wp-block-button"><a class="wp-block-button__link wp-element-button">test source value</a></div>',
),
'image block' => array(
'caption',
<<<HTML
<!-- wp:image {"id":66,"sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large"><img src="breakfast.jpg" alt="" class="wp-image-1"/><figcaption class="wp-element-caption">Breakfast at a <em>café</em> in Wrocław.</figcaption></figure>
<!-- /wp:image -->
HTML
,
'<figure class="wp-block-image size-large"><img src="breakfast.jpg" alt="" class="wp-image-1"/><figcaption class="wp-element-caption">test source value</figcaption></figure>',
),
'test block' => array(
'myAttribute',
<<<HTML
Expand Down Expand Up @@ -282,13 +292,21 @@ public function test_passing_uses_context_to_source() {
* Tests if the block content is updated with the value returned by the source
* for the Image block in the placeholder state.
*
* Furthermore tests if the caption attribute is correctly processed.
*
* @ticket 60282
* @ticket 64031
*
* @covers ::register_block_bindings_source
*/
public function test_update_block_with_value_from_source_image_placeholder() {
$get_value_callback = function () {
return 'https://example.com/image.jpg';
$get_value_callback = function ( $source_args, $block_instance, $attribute_name ) {
if ( 'url' === $attribute_name ) {
return 'https://example.com/image.jpg';
}
if ( 'caption' === $attribute_name ) {
return 'Example Image';
}
};

register_block_bindings_source(
Expand All @@ -300,8 +318,8 @@ public function test_update_block_with_value_from_source_image_placeholder() {
);

$block_content = <<<HTML
<!-- wp:image {"metadata":{"bindings":{"url":{"source":"test/source"}}}} -->
<figure class="wp-block-image"><img alt=""/></figure>
<!-- wp:image {"metadata":{"bindings":{"url":{"source":"test/source"},"caption":{"source":"test/source"}}}} -->
<figure class="wp-block-image"><img alt=""/><figcaption class="wp-element-caption"></figcaption></figure>
<!-- /wp:image -->
HTML;
$parsed_blocks = parse_blocks( $block_content );
Expand All @@ -314,7 +332,12 @@ public function test_update_block_with_value_from_source_image_placeholder() {
"The 'url' attribute should be updated with the value returned by the source."
);
$this->assertSame(
'<figure class="wp-block-image"><img src="https://example.com/image.jpg" alt=""/></figure>',
'Example Image',
$block->attributes['caption'],
"The 'caption' attribute should be updated with the value returned by the source."
);
$this->assertSame(
'<figure class="wp-block-image"><img src="https://example.com/image.jpg" alt=""/><figcaption class="wp-element-caption">Example Image</figcaption></figure>',
trim( $result ),
'The block content should be updated with the value returned by the source.'
);
Expand Down
Loading