@@ -413,4 +413,58 @@ public function test_resolve_content_blocks_resolves_pattern_inner_blocks() {
413413 // Cleanup: Unregistering the pattern.
414414 unregister_block_pattern ( $ pattern_name );
415415 }
416+
417+ /**
418+ * Tests that template part inner blocks are resolved correctly.
419+ */
420+ public function test_resolve_content_blocks_resolves_template_part_inner_blocks () {
421+ // Skip if template part functionality is not supported
422+ if ( ! function_exists ( 'get_block_templates ' ) ) {
423+ $ this ->markTestSkipped ( 'Template part functionality not supported in this WordPress version. ' );
424+ }
425+
426+ // Mock the get_block_templates function to control the output.
427+ $ mock_template = (object ) [
428+ 'content ' => '<!-- wp:paragraph /--><!-- wp:heading /--> ' ,
429+ ];
430+
431+ add_filter (
432+ 'get_block_templates ' ,
433+ function () use ( $ mock_template ) {
434+ return [ $ mock_template ];
435+ }
436+ );
437+
438+ // Update post content to include template part block
439+ $ post_content = '
440+ <!-- wp:template-part {"slug":"test-template-part"} /-->
441+ ' ;
442+
443+ wp_update_post (
444+ [
445+ 'ID ' => $ this ->post_id ,
446+ 'post_content ' => $ post_content ,
447+ ]
448+ );
449+
450+ $ post_model = new Post ( get_post ( $ this ->post_id ) );
451+
452+ // Resolve blocks as nested
453+ $ resolved_blocks = $ this ->instance ->resolve_content_blocks ( $ post_model , [ 'flat ' => false ] );
454+
455+ // Assertions
456+ $ this ->assertCount ( 1 , $ resolved_blocks , 'There should be only one top-level block (template-part). ' );
457+ $ this ->assertEquals ( 'core/template-part ' , $ resolved_blocks [0 ]['blockName ' ] );
458+ $ this ->assertCount ( 2 , $ resolved_blocks [0 ]['innerBlocks ' ], 'There should be two inner blocks in the template part. ' );
459+ $ this ->assertEquals ( 'core/paragraph ' , $ resolved_blocks [0 ]['innerBlocks ' ][0 ]['blockName ' ] );
460+ $ this ->assertEquals ( 'core/heading ' , $ resolved_blocks [0 ]['innerBlocks ' ][1 ]['blockName ' ] );
461+
462+ // Resolve blocks as flat
463+ $ resolved_flat_blocks = $ this ->instance ->resolve_content_blocks ( $ post_model , [ 'flat ' => true ] );
464+
465+ $ this ->assertCount ( 3 , $ resolved_flat_blocks , 'There should be three blocks when flattened. ' );
466+ $ this ->assertEquals ( 'core/template-part ' , $ resolved_flat_blocks [0 ]['blockName ' ] );
467+ $ this ->assertEquals ( 'core/paragraph ' , $ resolved_flat_blocks [1 ]['blockName ' ] );
468+ $ this ->assertEquals ( 'core/heading ' , $ resolved_flat_blocks [2 ]['blockName ' ] );
469+ }
416470}
0 commit comments