Skip to content

Commit

Permalink
Maybe pattern overrides is registered for the test?
Browse files Browse the repository at this point in the history
  • Loading branch information
talldan committed May 31, 2024
1 parent 3dd8a2b commit 3faccb6
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions tests/phpunit/tests/block-bindings/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,29 +243,20 @@ public function test_source_value_with_unsafe_html_is_sanitized() {
* @covers ::register_block_bindings_source
*/
public function test_default_binding_for_pattern_overrides() {
$get_value_callback = function ( $source_args, $block_instance, $attribute_name ) {
return "The attribute name is '$attribute_name'";
};

register_block_bindings_source(
'core/pattern-overrides',
array(
'label' => self::SOURCE_LABEL,
'get_value_callback' => $get_value_callback,
)
);
$expected_content = 'This is the content value';

$block_content = <<<HTML
<!-- wp:paragraph {"metadata":{"bindings":{"__default":{"source":"core/pattern-overrides"}}}} -->
<!-- wp:paragraph {"metadata":{"bindings":{"__default":{"source":"core/pattern-overrides"}}, "name":"Test"}} -->
<p>This should not appear</p>
<!-- /wp:paragraph -->
HTML;

$parsed_blocks = parse_blocks( $block_content );
$block = new WP_Block( $parsed_blocks[0] );
$block = new WP_Block( $parsed_blocks[0], array( 'pattern/overrides' => array( 'Test' => array( 'content' => $expected_content ) ) ) );
$result = $block->render();

$this->assertSame(
"<p>The attribute name is 'content'</p>",
"<p>$expected_content</p>",
trim( $result ),
'The `__default` attribute should be replaced with the real attribute prior to the callback.'
);
Expand Down

0 comments on commit 3faccb6

Please sign in to comment.