@@ -349,4 +349,68 @@ protected function assertEqualBlocks( $expected, $actual, $message = '' ) {
349349 $ this ->assertEqualBlocks ( $ expected_inner_block , $ actual_inner_blocks [ $ index ], $ message );
350350 }
351351 }
352+
353+ /**
354+ * Tests that pattern inner blocks are resolved correctly.
355+ */
356+ public function test_resolve_content_blocks_resolves_pattern_inner_blocks () {
357+ // Skip if pattern resolution functionality is not supported.
358+ if ( ! function_exists ( 'resolve_pattern_blocks ' ) ) {
359+ $ this ->markTestSkipped ( 'Pattern block resolution not supported in this WordPress version. ' );
360+ }
361+
362+ // Create a pattern
363+ $ pattern_name = 'test/pattern-blocks ' ;
364+ $ pattern_content = '
365+ <!-- wp:paragraph -->
366+ <p>Pattern Paragraph</p>
367+ <!-- /wp:paragraph -->
368+ <!-- wp:heading -->
369+ <h2>Pattern Heading</h2>
370+ <!-- /wp:heading -->
371+ ' ;
372+
373+ // Register the pattern.
374+ register_block_pattern (
375+ $ pattern_name ,
376+ [
377+ 'title ' => 'Test Pattern ' ,
378+ 'content ' => $ pattern_content ,
379+ ]
380+ );
381+
382+ // Update post content to include pattern block.
383+ $ post_content = '
384+ <!-- wp:pattern {"slug":"test/pattern-blocks"} /-->
385+ ' ;
386+
387+ wp_update_post (
388+ [
389+ 'ID ' => $ this ->post_id ,
390+ 'post_content ' => $ post_content ,
391+ ]
392+ );
393+
394+ $ post_model = new Post ( get_post ( $ this ->post_id ) );
395+
396+ // Resolve blocks as nested.
397+ $ resolved_blocks = $ this ->instance ->resolve_content_blocks ( $ post_model , [ 'flat ' => false ] );
398+
399+ $ this ->assertCount ( 1 , $ resolved_blocks , 'There should be only one top-level block (pattern). ' );
400+ $ this ->assertEquals ( 'core/pattern ' , $ resolved_blocks [0 ]['blockName ' ] );
401+ $ this ->assertCount ( 2 , $ resolved_blocks [0 ]['innerBlocks ' ], 'There should be two inner blocks in the pattern. ' );
402+ $ this ->assertEquals ( 'core/paragraph ' , $ resolved_blocks [0 ]['innerBlocks ' ][0 ]['blockName ' ] );
403+ $ this ->assertEquals ( 'core/heading ' , $ resolved_blocks [0 ]['innerBlocks ' ][1 ]['blockName ' ] );
404+
405+ // Resolve blocks as flat.
406+ $ resolved_flat_blocks = $ this ->instance ->resolve_content_blocks ( $ post_model , [ 'flat ' => true ] );
407+
408+ $ this ->assertCount ( 3 , $ resolved_flat_blocks , 'There should be three blocks when flattened. ' );
409+ $ this ->assertEquals ( 'core/pattern ' , $ resolved_flat_blocks [0 ]['blockName ' ] );
410+ $ this ->assertEquals ( 'core/paragraph ' , $ resolved_flat_blocks [1 ]['blockName ' ] );
411+ $ this ->assertEquals ( 'core/heading ' , $ resolved_flat_blocks [2 ]['blockName ' ] );
412+
413+ // Cleanup: Unregistering the pattern.
414+ unregister_block_pattern ( $ pattern_name );
415+ }
352416}
0 commit comments