Skip to content
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add unit test for processing
  • Loading branch information
SantosGuillamot committed Jul 1, 2024
commit 632e0154c121fe1ddfe0e611271e3d75f7898a76
37 changes: 37 additions & 0 deletions tests/phpunit/tests/block-bindings/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,41 @@ public function test_default_binding_for_pattern_overrides() {
'The `__default` attribute should be replaced with the real attribute prior to the callback.'
);
}

/**
* Tests that replacing inner text for bound attributes works as expected.
*
* @ticket 61466
*
* @covers WP_Block::process_block_bindings
*/
public function test_replacing_inner_text_with_block_bindings_value() {
$get_value_callback = function () {
return '$12.50';
};

register_block_bindings_source(
self::SOURCE_NAME,
array(
'label' => self::SOURCE_LABEL,
'get_value_callback' => $get_value_callback,
)
);

$block_content = <<<HTML
<!-- wp:image {"metadata":{"bindings":{"caption":{"source":"test/source"}}}} -->
<figure class="wp-block-image"><img src="https://example.com/image.jpg" /><figcaption class="wp-element-caption">Default value</figcaption></figure>
<!-- /wp:image -->
HTML;

$parsed_blocks = parse_blocks( $block_content );
$block = new WP_Block( $parsed_blocks[0] );
$result = $block->render();

$this->assertSame(
'<figure class="wp-block-image"><img src="https://example.com/image.jpg" /><figcaption class="wp-element-caption">$12.50</figcaption></figure>',
trim( $result ),
'The image caption should be updated with the value returned by the source.'
);
}
}