Skip to content

Commit

Permalink
Add tests and other general doc updates
Browse files Browse the repository at this point in the history
  • Loading branch information
talldan committed Sep 18, 2024
1 parent 11c72a7 commit e6d9c31
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/wp-includes/class-wp-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ public function __get( $name ) {
*
* @since 6.5.0
* @since 6.6.0 Handle the `__default` attribute for pattern overrides.
* @since 6.7.0 Return any updated bindings metadata in the computed attributes.
*
* @return array The computed block attributes for the provided block bindings.
*/
Expand Down Expand Up @@ -310,8 +311,8 @@ private function process_block_bindings() {
}
}

// Update the bindings in the computed attributes.
// This ensures the block receives the expanded __default binding when it renders.
// Update the bindings metadata in the computed attributes.
// This ensures the block receives the expanded __default binding metadata when it renders.
$computed_attributes['metadata'] = array_merge(
$parsed_block['attrs']['metadata'],
array( 'bindings' => $bindings )
Expand Down
22 changes: 16 additions & 6 deletions tests/phpunit/tests/block-bindings/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,31 +272,41 @@ public function test_using_symbols_in_block_bindings_value() {
}

/**
* Tests if the `__default` attribute is replaced with real attribues for
* Tests if the `__default` attribute is replaced with real attributes for
* pattern overrides.
*
* @ticket 61333
* @ticket 62069
*
* @covers WP_Block::process_block_bindings
*/
public function test_default_binding_for_pattern_overrides() {
$expected_content = 'This is the content value';

$block_content = <<<HTML
<!-- 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], array( 'pattern/overrides' => array( 'Test' => array( 'content' => $expected_content ) ) ) );
$result = $block->render();
$expected_content = 'This is the content value';
$parsed_blocks = parse_blocks( $block_content );
$block = new WP_Block( $parsed_blocks[0], array( 'pattern/overrides' => array( 'Test' => array( 'content' => $expected_content ) ) ) );

$result = $block->render();

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

$expected_bindings_metadata = array(
'content' => array( 'source' => 'core/pattern-overrides' ),
);
$this->assertSame(
$expected_bindings_metadata,
$block->attributes['metadata']['bindings'],
'The __default binding should be updated with the individual binding attributes in the block metadata.'
);
}

/**
Expand Down

0 comments on commit e6d9c31

Please sign in to comment.