@@ -30,12 +30,37 @@ public function set_up() {
3030 'description ' => 'Recursive pattern. ' ,
3131 )
3232 );
33+ register_block_pattern (
34+ 'core/single-root ' ,
35+ array (
36+ 'title ' => 'Single Root Pattern ' ,
37+ 'content ' => '<!-- wp:paragraph -->Single root content<!-- /wp:paragraph --> ' ,
38+ 'description ' => 'A single root pattern. ' ,
39+ )
40+ );
41+ register_block_pattern (
42+ 'core/with-attrs ' ,
43+ array (
44+ 'title ' => 'Pattern With Attrs ' ,
45+ 'content ' => '<!-- wp:paragraph {"className":"custom-class"} -->Content<!-- /wp:paragraph --> ' ,
46+ 'description ' => 'A pattern with existing attributes. ' ,
47+ )
48+ );
49+ register_block_pattern (
50+ 'core/nested-single ' ,
51+ array (
52+ 'title ' => 'Nested Pattern ' ,
53+ 'content ' => '<!-- wp:group --><!-- wp:paragraph -->Nested content<!-- /wp:paragraph --><!-- wp:pattern {"slug":"core/single-root"} /--><!-- /wp:group --> ' ,
54+ 'description ' => 'A nested single root pattern. ' ,
55+ )
56+ );
3357 }
3458
3559 public function tear_down () {
3660 unregister_block_pattern ( 'core/test ' );
3761 unregister_block_pattern ( 'core/recursive ' );
38-
62+ unregister_block_pattern ( 'core/single-root ' );
63+ unregister_block_pattern ( 'core/with-attrs ' );
3964 parent ::tear_down ();
4065 }
4166
@@ -67,6 +92,12 @@ public function data_should_resolve_pattern_blocks_as_expected() {
6792 'recursive pattern ' => array ( '<!-- wp:pattern {"slug":"core/recursive"} /--> ' , '<!-- wp:paragraph -->Recursive<!-- /wp:paragraph --> ' ),
6893 // Resolves the pattern within a block.
6994 'pattern within a block ' => array ( '<!-- wp:group --><!-- wp:paragraph -->Before<!-- /wp:paragraph --><!-- wp:pattern {"slug":"core/test"} /--><!-- wp:paragraph -->After<!-- /wp:paragraph --><!-- /wp:group --> ' , '<!-- wp:group --><!-- wp:paragraph -->Before<!-- /wp:paragraph --><!-- wp:paragraph -->Hello<!-- /wp:paragraph --><!-- wp:paragraph -->World<!-- /wp:paragraph --><!-- wp:paragraph -->After<!-- /wp:paragraph --><!-- /wp:group --> ' ),
95+ // Resolves the single-root pattern and adds metadata.
96+ 'single-root pattern ' => array ( '<!-- wp:pattern {"slug":"core/single-root"} /--> ' , '<!-- wp:paragraph {"metadata":{"patternName":"core/single-root","name":"Single Root Pattern"}} -->Single root content<!-- /wp:paragraph --> ' ),
97+ // Existing attributes are preserved when adding metadata.
98+ 'existing attributes preserved ' => array ( '<!-- wp:pattern {"slug":"core/with-attrs"} /--> ' , '<!-- wp:paragraph {"className":"custom-class","metadata":{"patternName":"core/with-attrs","name":"Pattern With Attrs"}} -->Content<!-- /wp:paragraph --> ' ),
99+ // Resolves the nested single-root pattern and adds metadata.
100+ 'nested single-root pattern ' => array ( '<!-- wp:pattern {"slug":"core/nested-single"} /--> ' , '<!-- wp:group {"metadata":{"patternName":"core/nested-single","name":"Nested Pattern"}} --><!-- wp:paragraph -->Nested content<!-- /wp:paragraph --><!-- wp:paragraph {"metadata":{"patternName":"core/single-root","name":"Single Root Pattern"}} -->Single root content<!-- /wp:paragraph --><!-- /wp:group --> ' ),
70101 );
71102 }
72103}
0 commit comments