Skip to content

Commit a640eaa

Browse files
committed
Add custom metadata support for block patterns in unit tests
Introduces a new block pattern 'core/with-custom-metadata' with custom metadata keys. Updates the unit tests to ensure that custom metadata is preserved when resolving patterns, enhancing the test coverage for metadata handling in block patterns.
1 parent ad370df commit a640eaa

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tests/phpunit/tests/blocks/resolvePatternBlocks.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ public function set_up() {
7878
'content' => '<!-- wp:paragraph {"metadata":{"patternName":"core/existing-metadata-should-not-overwrite","description":"A existing metadata pattern.","categories":["cake"]}} -->Existing metadata content<!-- /wp:paragraph -->',
7979
)
8080
);
81+
register_block_pattern(
82+
'core/with-custom-metadata',
83+
array(
84+
'title' => 'Pattern With Custom Metadata',
85+
'content' => '<!-- wp:paragraph {"metadata":{"customKey":"customValue","anotherKey":123,"booleanKey":true}} -->Content with custom metadata<!-- /wp:paragraph -->',
86+
'description' => 'A pattern with custom metadata keys.',
87+
'categories' => array( 'test' ),
88+
)
89+
);
8190
}
8291

8392
public function tear_down() {
@@ -88,6 +97,7 @@ public function tear_down() {
8897
unregister_block_pattern( 'core/with-attrs' );
8998
unregister_block_pattern( 'core/nested-single' );
9099
unregister_block_pattern( 'core/existing-metadata' );
100+
unregister_block_pattern( 'core/with-custom-metadata' );
91101
parent::tear_down();
92102
}
93103

@@ -156,6 +166,11 @@ public function data_should_resolve_pattern_blocks_as_expected() {
156166
'<!-- wp:pattern {"slug":"core/existing-metadata"} /-->',
157167
'<!-- wp:paragraph {"metadata":{"patternName":"core/existing-metadata","description":"A existing metadata pattern.","categories":["cake"],"name":"Existing Metadata Pattern"}} -->Existing metadata content<!-- /wp:paragraph -->',
158168
),
169+
// Custom metadata keys are preserved when resolving patterns.
170+
'custom metadata preserved' => array(
171+
'<!-- wp:pattern {"slug":"core/with-custom-metadata"} /-->',
172+
'<!-- wp:paragraph {"metadata":{"customKey":"customValue","anotherKey":123,"booleanKey":true,"patternName":"core/with-custom-metadata","name":"Pattern With Custom Metadata","description":"A pattern with custom metadata keys.","categories":["test"]}} -->Content with custom metadata<!-- /wp:paragraph -->',
173+
),
159174
);
160175
}
161176
}

0 commit comments

Comments
 (0)