Skip to content

Commit

Permalink
Merge branch 'trunk' into hotfix/content-parser-selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
alecgeatches authored Jul 29, 2024
2 parents 17c947b + adeae66 commit 7d1041b
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions tests/parser/test-content-parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,63 @@ public function test_parse_multiple_blocks() {
$this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) );
$this->assertArraySubset( $expected_blocks, $blocks['blocks'], true );
}

/* Default values and missing values */

public function test_parse_block_missing_attributes_and_defaults() {
$this->register_block_with_attributes( 'test/block-with-empty-attributes', [
'attributeOneWithDefaultValueAndSource' => [
'type' => 'string',
'source' => 'attribute',
'selector' => 'div',
'attribute' => 'data-attr-one',
'default' => 'Default Attribute 1 Value',
],
'attributeTwoWithDefaultValueAndNoSource' => [
'type' => 'string',
'source' => 'attribute',
'selector' => 'div',
'attribute' => 'data-attr-two',
'default' => 'Default Attribute 2 Value',
],
'attributeThreeWithNoDefaultValueAndSource' => [
'type' => 'string',
'source' => 'attribute',
'selector' => 'div',
'attribute' => 'data-attr-three',
],
'attributeFourWithNoDefaultValueAndNoSource' => [
'type' => 'string',
'source' => 'attribute',
'selector' => 'div',
'attribute' => 'data-attr-four',
],
] );

$html = '
<!-- wp:test/block-with-empty-attributes -->
<div
data-attr-one="Attribute 1 Value"
data-attr-three="Attribute 3 Value"
>Content</div>
<!-- /wp:test/block-with-empty-attributes -->
';

$expected_blocks = [
[
'name' => 'test/block-with-empty-attributes',
'attributes' => [
'attributeOneWithDefaultValueAndSource' => 'Attribute 1 Value',
'attributeTwoWithDefaultValueAndNoSource' => 'Default Attribute 2 Value',
'attributeThreeWithNoDefaultValueAndSource' => 'Attribute 3 Value',
// attributeFourWithNoDefaultValueAndNoSource has no default, not represented
],
],
];

$content_parser = new ContentParser( $this->registry );
$blocks = $content_parser->parse( $html );
$this->assertArrayHasKey( 'blocks', $blocks, sprintf( 'Unexpected parser output: %s', wp_json_encode( $blocks ) ) );
$this->assertArraySubset( $expected_blocks, $blocks['blocks'], true );
}
}

0 comments on commit 7d1041b

Please sign in to comment.