@@ -278,6 +278,29 @@ public function test_insert_after_nth_block() {
278278 $ this ->assertLessThan ( $ third_pos , $ insert_pos , 'Inserted content should come before third paragraph. ' );
279279 }
280280
281+ /**
282+ * Test insert_after_nth_block preserves inner blocks (e.g., list items).
283+ *
284+ * Regression: a `core/list` block stores its `<li>` items as `core/list-item`
285+ * inner blocks, not in `innerHTML`. The same applies to columns, groups,
286+ * buttons, etc. Reassembling parsed blocks must use `render_block()` so
287+ * inner-block content (and dynamic blocks) are emitted.
288+ *
289+ * @covers \Newspack\Collections\Content_Inserter::insert_after_nth_block
290+ */
291+ public function test_insert_after_nth_block_preserves_inner_blocks () {
292+ $ insert_html = '<div>Inserted content</div> ' ;
293+
294+ $ block_content = "<!-- wp:paragraph --> \n<p>First paragraph.</p> \n<!-- /wp:paragraph --> \n\n"
295+ . "<!-- wp:paragraph --> \n<p>Second paragraph.</p> \n<!-- /wp:paragraph --> \n\n"
296+ . "<!-- wp:list --> \n<ul class= \"wp-block-list \"><!-- wp:list-item --> \n<li>Item one</li> \n<!-- /wp:list-item --> \n\n<!-- wp:list-item --> \n<li>Item two</li> \n<!-- /wp:list-item --></ul> \n<!-- /wp:list --> " ;
297+
298+ $ result = Content_Inserter::insert_after_nth_block ( $ block_content , $ insert_html , 2 );
299+
300+ $ this ->assertStringContainsString ( '<li>Item one</li> ' , $ result , 'First list item should be preserved. ' );
301+ $ this ->assertStringContainsString ( '<li>Item two</li> ' , $ result , 'Second list item should be preserved. ' );
302+ }
303+
281304 /**
282305 * Test check_if_post_is_in_collection excludes draft collections.
283306 *
0 commit comments