@@ -102,6 +102,16 @@ public function data_update_block_with_value_from_source() {
102102 ,
103103 '<div class="wp-block-button"><a class="wp-block-button__link wp-element-button">test source value</a></div> ' ,
104104 ),
105+ 'image block ' => array (
106+ 'caption ' ,
107+ <<<HTML
108+ <!-- wp:image {"id":66,"sizeSlug":"large","linkDestination":"none"} -->
109+ <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>
110+ <!-- /wp:image -->
111+ HTML
112+ ,
113+ '<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> ' ,
114+ ),
105115 'test block ' => array (
106116 'myAttribute ' ,
107117 <<<HTML
@@ -282,13 +292,21 @@ public function test_passing_uses_context_to_source() {
282292 * Tests if the block content is updated with the value returned by the source
283293 * for the Image block in the placeholder state.
284294 *
295+ * Furthermore tests if the caption attribute is correctly processed.
296+ *
285297 * @ticket 60282
298+ * @ticket 64031
286299 *
287300 * @covers ::register_block_bindings_source
288301 */
289302 public function test_update_block_with_value_from_source_image_placeholder () {
290- $ get_value_callback = function () {
291- return 'https://example.com/image.jpg ' ;
303+ $ get_value_callback = function ( $ source_args , $ block_instance , $ attribute_name ) {
304+ if ( 'url ' === $ attribute_name ) {
305+ return 'https://example.com/image.jpg ' ;
306+ }
307+ if ( 'caption ' === $ attribute_name ) {
308+ return 'Example Image ' ;
309+ }
292310 };
293311
294312 register_block_bindings_source (
@@ -300,8 +318,8 @@ public function test_update_block_with_value_from_source_image_placeholder() {
300318 );
301319
302320 $ block_content = <<<HTML
303- <!-- wp:image {"metadata":{"bindings":{"url":{"source":"test/source"}}}} -->
304- <figure class="wp-block-image"><img alt=""/></figure>
321+ <!-- wp:image {"metadata":{"bindings":{"url":{"source":"test/source"},"caption":{"source":"test/source"} }}} -->
322+ <figure class="wp-block-image"><img alt=""/><figcaption class="wp-element-caption"></figcaption>< /figure>
305323<!-- /wp:image -->
306324HTML ;
307325 $ parsed_blocks = parse_blocks ( $ block_content );
@@ -314,7 +332,12 @@ public function test_update_block_with_value_from_source_image_placeholder() {
314332 "The 'url' attribute should be updated with the value returned by the source. "
315333 );
316334 $ this ->assertSame (
317- '<figure class="wp-block-image"><img src="https://example.com/image.jpg" alt=""/></figure> ' ,
335+ 'Example Image ' ,
336+ $ block ->attributes ['caption ' ],
337+ "The 'caption' attribute should be updated with the value returned by the source. "
338+ );
339+ $ this ->assertSame (
340+ '<figure class="wp-block-image"><img src="https://example.com/image.jpg" alt=""/><figcaption class="wp-element-caption">Example Image</figcaption></figure> ' ,
318341 trim ( $ result ),
319342 'The block content should be updated with the value returned by the source. '
320343 );
0 commit comments