@@ -290,4 +290,55 @@ private function populate_args_post_authors( array &$args, $expected_ids ) {
290290 $ post_ids_key = $ expected_ids [0 ];
291291 $ args ['author ' ] = self ::$ post_ids [ $ post_ids_key ]['post_author ' ];
292292 }
293+
294+ /**
295+ * @ticket 61244
296+ * @covers ::export_wp
297+ */
298+ public function test_export_wp_should_not_include_empty_comments_when_filtered () {
299+ $ post_id = self ::factory ()->post ->create ( array ( 'post_title ' => 'Test Post ' ) );
300+ self ::factory ()->comment ->create_post_comments ( $ post_id , 3 );
301+
302+ // Add filter to make get_comment return false.
303+ add_action (
304+ 'export_wp ' ,
305+ function () {
306+ add_filter ( 'get_comment ' , '__return_false ' );
307+ }
308+ );
309+
310+ ob_start ();
311+ export_wp ();
312+ $ xml = ob_get_clean ();
313+
314+ $ xml_obj = simplexml_load_string ( $ xml );
315+
316+ // Convert all <wp:comment> tags to string for easier checking.
317+ $ comment_tags = $ xml_obj ->xpath ( '//wp:comment ' );
318+
319+ // Verify there are no comment tags in the export.
320+ $ this ->assertEmpty ( $ comment_tags , 'No <wp:comment> tags should be present when comments are filtered out. ' );
321+ }
322+
323+ /**
324+ * @ticket 61244
325+ * @covers ::export_wp
326+ */
327+ public function test_export_wp_includes_comments_when_not_filtered () {
328+ $ post_id = self ::factory ()->post ->create ( array ( 'post_title ' => 'Test Post ' ) );
329+ $ comment_count = 3 ;
330+ self ::factory ()->comment ->create_post_comments ( $ post_id , $ comment_count );
331+
332+ ob_start ();
333+ export_wp ();
334+ $ xml = ob_get_clean ();
335+
336+ $ xml_obj = simplexml_load_string ( $ xml );
337+
338+ // Count <wp:comment> tags.
339+ $ comment_tags = $ xml_obj ->xpath ( '//wp:comment ' );
340+
341+ // Verify the correct number of comment tags are present.
342+ $ this ->assertCount ( $ comment_count , $ comment_tags , 'Export should include all comments when not filtered. ' );
343+ }
293344}
0 commit comments