Skip to content
Closed
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
Next Next commit
Introduce data provider to allow extending test coverage
  • Loading branch information
ockham committed Aug 13, 2025
commit 2d7b4f3f06beab2859f24afef76774661bff3f6a
42 changes: 31 additions & 11 deletions tests/phpunit/tests/block-bindings/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,30 @@ public static function wpTearDownAfterClass() {
unregister_block_type( 'test/block' );
}

public function data_update_block_with_value_from_source() {
return array(
'paragraph block' => array(
'content',
<<<HTML
<!-- wp:paragraph -->
<p>This should not appear</p>
<!-- /wp:paragraph -->
HTML,
'<p>test source value</p>'
)
);
}

/**
* Test if the block content is updated with the value returned by the source.
*
* @ticket 60282
*
* @covers ::register_block_bindings_source
*
* @dataProvider data_update_block_with_value_from_source
*/
public function test_update_block_with_value_from_source() {
public function test_update_block_with_value_from_source( $bound_attribute, $block_content, $expected_result ) {
$get_value_callback = function () {
return 'test source value';
};
Expand All @@ -81,22 +97,26 @@ public function test_update_block_with_value_from_source() {
)
);

$block_content = <<<HTML
<!-- wp:paragraph {"metadata":{"bindings":{"content":{"source":"test/source"}}}} -->
<p>This should not appear</p>
<!-- /wp:paragraph -->
HTML;
$parsed_blocks = parse_blocks( $block_content );
$block = new WP_Block( $parsed_blocks[0] );
$result = $block->render();

$parsed_blocks[0]['attrs']['metadata'] = array(
'bindings' => array(
$bound_attribute => array(
'source' => self::SOURCE_NAME,
),
)
);

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

$this->assertSame(
'test source value',
$block->attributes['content'],
"The 'content' attribute should be updated with the value returned by the source."
$block->attributes[ $bound_attribute ],
"The '{$bound_attribute}' attribute should be updated with the value returned by the source."
);
$this->assertSame(
'<p>test source value</p>',
$expected_result,
trim( $result ),
'The block content should be updated with the value returned by the source.'
);
Expand Down