From c89248e77293299244c29cab276908042416ce98 Mon Sep 17 00:00:00 2001 From: Himanshu Pathak Date: Fri, 15 May 2026 23:07:38 +0530 Subject: [PATCH 1/6] Refactor: Add unit tests for bulk actions in WP_Comments_List_Table --- ...n_WpCommentsListTable_BulkActions_Test.php | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 tests/phpunit/tests/admin/Admin_WpCommentsListTable_BulkActions_Test.php diff --git a/tests/phpunit/tests/admin/Admin_WpCommentsListTable_BulkActions_Test.php b/tests/phpunit/tests/admin/Admin_WpCommentsListTable_BulkActions_Test.php new file mode 100644 index 0000000000000..54cab8068a1ca --- /dev/null +++ b/tests/phpunit/tests/admin/Admin_WpCommentsListTable_BulkActions_Test.php @@ -0,0 +1,52 @@ +table = _get_list_table( 'WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) ); + } + + /** + * @ticket 19278 + */ + public function test_bulk_action_menu_supports_options_and_optgroups() { + add_filter( + 'bulk_actions-edit-comments', + static function () { + return array( + 'delete' => 'Delete', + 'Change State' => array( + 'feature' => 'Featured', + 'sale' => 'On Sale', + ), + ); + } + ); + + ob_start(); + $this->table->bulk_actions(); + $output = ob_get_clean(); + + $expected = <<<'OPTIONS' + + + + + +OPTIONS; + $expected = str_replace( "\r\n", "\n", $expected ); + + $this->assertStringContainsString( $expected, $output ); + } +} From 2b867e522da551c37f6034c868d302782f78a33b Mon Sep 17 00:00:00 2001 From: Himanshu Pathak Date: Fri, 15 May 2026 23:07:55 +0530 Subject: [PATCH 2/6] Tests: Add unit tests for extra_tablenav in WP_Comments_List_Table --- ...WpCommentsListTable_ExtraTablenav_Test.php | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 tests/phpunit/tests/admin/Admin_WpCommentsListTable_ExtraTablenav_Test.php diff --git a/tests/phpunit/tests/admin/Admin_WpCommentsListTable_ExtraTablenav_Test.php b/tests/phpunit/tests/admin/Admin_WpCommentsListTable_ExtraTablenav_Test.php new file mode 100644 index 0000000000000..00265ed8f4fcc --- /dev/null +++ b/tests/phpunit/tests/admin/Admin_WpCommentsListTable_ExtraTablenav_Test.php @@ -0,0 +1,84 @@ +table = _get_list_table( 'WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) ); + } + + /** + * @ticket 40188 + */ + public function test_filter_button_should_not_be_shown_if_there_are_no_comments() { + ob_start(); + $this->table->extra_tablenav( 'top' ); + $output = ob_get_clean(); + + $this->assertStringNotContainsString( 'id="post-query-submit"', $output ); + } + + /** + * @ticket 40188 + */ + public function test_filter_button_should_be_shown_if_there_are_comments() { + $post_id = self::factory()->post->create(); + $comment_id = self::factory()->comment->create( + array( + 'comment_post_ID' => $post_id, + 'comment_approved' => '1', + ) + ); + + $this->table->prepare_items(); + + ob_start(); + $this->table->extra_tablenav( 'top' ); + $output = ob_get_clean(); + + $this->assertStringContainsString( 'id="post-query-submit"', $output ); + } + + /** + * @ticket 40188 + */ + public function test_filter_comment_type_dropdown_should_be_shown_if_there_are_comments() { + $post_id = self::factory()->post->create(); + $comment_id = self::factory()->comment->create( + array( + 'comment_post_ID' => $post_id, + 'comment_approved' => '1', + ) + ); + + $this->table->prepare_items(); + + ob_start(); + $this->table->extra_tablenav( 'top' ); + $output = ob_get_clean(); + + $this->assertStringContainsString( 'id="filter-by-comment-type"', $output ); + $this->assertStringContainsString( "