@@ -371,6 +371,31 @@ static function ( string $content, array $context ): string {
371371 $ failures [] = 'export CLI did not route --content-dir to the markdown content root ' ;
372372}
373373
374+ require_once dirname ( __DIR__ ) . '/inc/class-wp-markdown-content-layout-profiles.php ' ;
375+ markdown_db_register_content_layout_profile (
376+ 'nested-export-fixture ' ,
377+ array (
378+ 'enumerate ' => static fn (): array => array ( 'plugins/foo/docs/user/home.md ' ),
379+ 'map_source ' => static fn (): array => array ( 'post_type ' => 'page ' , 'post_name ' => 'home ' ),
380+ 'path_for_post ' => static fn (): string => 'plugins/foo/docs/user/home.md ' ,
381+ )
382+ );
383+ $ nested_options = array ( 'path ' => $ tmp_root . '/nested-export ' , 'post_types ' => 'page ' , 'layout_profile ' => 'nested-export-fixture ' );
384+ $ nested_export = WP_Markdown_CLI ::export ( $ nested_options );
385+ if ( true !== $ nested_export ['success ' ] || 1 !== $ nested_export ['written_count ' ] || 0 !== $ nested_export ['skipped_count ' ] || ! is_file ( $ nested_options ['path ' ] . '/plugins/foo/docs/user/home.md ' ) ) {
386+ $ failures [] = 'nested layout export did not write into a fresh root ' ;
387+ }
388+ // A conflicting route must be accounted for rather than silently disappearing.
389+ file_put_contents ( $ nested_options ['path ' ] . '/plugins/foo/docs/user/home.md ' , "--- \nid: 999 \n--- \n\nOther post \n" );
390+ $ failed_export = WP_Markdown_CLI ::export ( $ nested_options );
391+ if ( false !== $ failed_export ['success ' ] || 1 !== $ failed_export ['candidate_count ' ] || 0 !== $ failed_export ['written_count ' ] || 1 !== $ failed_export ['skipped_count ' ] || 17 !== ( $ failed_export ['skipped ' ][0 ]['id ' ] ?? null ) || 'plugins/foo/docs/user/home.md ' !== ( $ failed_export ['skipped ' ][0 ]['path ' ] ?? null ) || empty ( $ failed_export ['skipped ' ][0 ]['reason ' ] ) ) {
392+ $ failures [] = 'failed export write was not reported as a skip with unsuccessful status ' ;
393+ }
394+ $ dry_export = WP_Markdown_CLI ::export ( array_merge ( $ nested_options , array ( 'dry_run ' => true ) ) );
395+ if ( true !== $ dry_export ['success ' ] || 0 !== $ dry_export ['written_count ' ] || 0 !== $ dry_export ['skipped_count ' ] ) {
396+ $ failures [] = 'dry-run export was incorrectly reported as a failed write ' ;
397+ }
398+
374399mdi_mysql_import_export_rm_rf ( $ tmp_root );
375400
376401if ( ! empty ( $ failures ) ) {
0 commit comments