From 8b9b13b503457335510f3d626b67d1b4a59f88ce Mon Sep 17 00:00:00 2001 From: Deepak Lalwani Date: Tue, 3 Mar 2026 21:39:24 +0530 Subject: [PATCH 1/2] Refresh 38238.5.diff patch --- .../includes/class-wp-links-list-table.php | 2 +- .../includes/class-wp-media-list-table.php | 2 +- .../includes/class-wp-ms-users-list-table.php | 2 +- .../includes/class-wp-posts-list-table.php | 4 +-- .../includes/class-wp-terms-list-table.php | 4 +-- .../phpunit/tests/admin/wpLinksListTable.php | 28 +++++++++++++++++++ .../phpunit/tests/admin/wpMediaListTable.php | 12 ++++++++ .../phpunit/tests/admin/wpPostsListTable.php | 12 ++++++++ .../phpunit/tests/admin/wpTermsListTable.php | 12 ++++++++ .../tests/multisite/wpMsUsersListTable.php | 12 ++++++++ 10 files changed, 83 insertions(+), 7 deletions(-) create mode 100644 tests/phpunit/tests/admin/wpLinksListTable.php diff --git a/src/wp-admin/includes/class-wp-links-list-table.php b/src/wp-admin/includes/class-wp-links-list-table.php index 309a00801adba..e40a1bd27938f 100644 --- a/src/wp-admin/includes/class-wp-links-list-table.php +++ b/src/wp-admin/includes/class-wp-links-list-table.php @@ -154,7 +154,7 @@ protected function get_sortable_columns() { 'name' => array( 'name', false, _x( 'Name', 'link name' ), __( 'Table ordered by Name.' ), 'asc' ), 'url' => array( 'url', false, __( 'URL' ), __( 'Table ordered by URL.' ) ), 'visible' => array( 'visible', false, __( 'Visible' ), __( 'Table ordered by Visibility.' ) ), - 'rating' => array( 'rating', false, __( 'Rating' ), __( 'Table ordered by Rating.' ) ), + 'rating' => array( 'rating', true, __( 'Rating' ), __( 'Table ordered by Rating.' ) ), ); } diff --git a/src/wp-admin/includes/class-wp-media-list-table.php b/src/wp-admin/includes/class-wp-media-list-table.php index 9476d23c4904d..1a28a44cdf128 100644 --- a/src/wp-admin/includes/class-wp-media-list-table.php +++ b/src/wp-admin/includes/class-wp-media-list-table.php @@ -431,7 +431,7 @@ protected function get_sortable_columns() { 'title' => array( 'title', false, _x( 'File', 'column name' ), __( 'Table ordered by File Name.' ) ), 'author' => array( 'author', false, __( 'Author' ), __( 'Table ordered by Author.' ) ), 'parent' => array( 'parent', false, _x( 'Uploaded to', 'column name' ), __( 'Table ordered by Uploaded To.' ) ), - 'comments' => array( 'comment_count', __( 'Comments' ), false, __( 'Table ordered by Comments.' ) ), + 'comments' => array( 'comment_count', true, __( 'Comments' ), __( 'Table ordered by Comments.' ) ), 'date' => array( 'date', true, __( 'Date' ), __( 'Table ordered by Date.' ), 'desc' ), ); } diff --git a/src/wp-admin/includes/class-wp-ms-users-list-table.php b/src/wp-admin/includes/class-wp-ms-users-list-table.php index b4cbf8457a0b4..d5496c86098fe 100644 --- a/src/wp-admin/includes/class-wp-ms-users-list-table.php +++ b/src/wp-admin/includes/class-wp-ms-users-list-table.php @@ -215,7 +215,7 @@ protected function get_sortable_columns() { 'username' => array( 'login', false, __( 'Username' ), __( 'Table ordered by Username.' ), 'asc' ), 'name' => array( 'name', false, __( 'Name' ), __( 'Table ordered by Name.' ) ), 'email' => array( 'email', false, __( 'E-mail' ), __( 'Table ordered by E-mail.' ) ), - 'registered' => array( 'id', false, _x( 'Registered', 'user' ), __( 'Table ordered by User Registered Date.' ) ), + 'registered' => array( 'id', true, _x( 'Registered', 'user' ), __( 'Table ordered by User Registered Date.' ) ), ); } diff --git a/src/wp-admin/includes/class-wp-posts-list-table.php b/src/wp-admin/includes/class-wp-posts-list-table.php index f9c08ad5c73ee..3677f0e47e305 100644 --- a/src/wp-admin/includes/class-wp-posts-list-table.php +++ b/src/wp-admin/includes/class-wp-posts-list-table.php @@ -772,14 +772,14 @@ protected function get_sortable_columns() { $sortables = array( 'title' => array( 'title', false, __( 'Title' ), $title_orderby_text, 'asc' ), 'parent' => array( 'parent', false ), - 'comments' => array( 'comment_count', false, __( 'Comments' ), __( 'Table ordered by Comments.' ) ), + 'comments' => array( 'comment_count', true, __( 'Comments' ), __( 'Table ordered by Comments.' ) ), 'date' => array( 'date', true, __( 'Date' ), __( 'Table ordered by Date.' ) ), ); } else { $sortables = array( 'title' => array( 'title', false, __( 'Title' ), __( 'Table ordered by Title.' ) ), 'parent' => array( 'parent', false ), - 'comments' => array( 'comment_count', false, __( 'Comments' ), __( 'Table ordered by Comments.' ) ), + 'comments' => array( 'comment_count', true, __( 'Comments' ), __( 'Table ordered by Comments.' ) ), 'date' => array( 'date', true, __( 'Date' ), __( 'Table ordered by Date.' ), 'desc' ), ); } diff --git a/src/wp-admin/includes/class-wp-terms-list-table.php b/src/wp-admin/includes/class-wp-terms-list-table.php index 75e37e45d5c4f..31b9086cdddfc 100644 --- a/src/wp-admin/includes/class-wp-terms-list-table.php +++ b/src/wp-admin/includes/class-wp-terms-list-table.php @@ -219,8 +219,8 @@ protected function get_sortable_columns() { 'name' => array( 'name', false, _x( 'Name', 'term name' ), $name_orderby_text, 'asc' ), 'description' => array( 'description', false, __( 'Description' ), __( 'Table ordered by Description.' ) ), 'slug' => array( 'slug', false, __( 'Slug' ), __( 'Table ordered by Slug.' ) ), - 'posts' => array( 'count', false, _x( 'Count', 'Number/count of items' ), __( 'Table ordered by Posts Count.' ) ), - 'links' => array( 'count', false, __( 'Links' ), __( 'Table ordered by Links.' ) ), + 'posts' => array( 'count', true, _x( 'Count', 'Number/count of items' ), __( 'Table ordered by Posts Count.' ) ), + 'links' => array( 'count', true, __( 'Links' ), __( 'Table ordered by Links.' ) ), ); } diff --git a/tests/phpunit/tests/admin/wpLinksListTable.php b/tests/phpunit/tests/admin/wpLinksListTable.php new file mode 100644 index 0000000000000..32d1d47475f3d --- /dev/null +++ b/tests/phpunit/tests/admin/wpLinksListTable.php @@ -0,0 +1,28 @@ +table = _get_list_table( 'WP_Links_List_Table', array( 'screen' => 'link-manager' ) ); + } + + /** + * @covers WP_Links_List_Table::print_column_headers + */ + public function test_sortable_columns_set_rating_descending_by_default() { + ob_start(); + $this->table->print_column_headers(); + $output = ob_get_clean(); + + $this->assertStringContainsString( '?orderby=rating&order=desc', $output, 'Mismatch of the default link ordering for rating column. Should be desc.' ); + $this->assertStringContainsString( 'column-rating sortable asc', $output, 'Mismatch of CSS classes for the rating column.' ); + } +} diff --git a/tests/phpunit/tests/admin/wpMediaListTable.php b/tests/phpunit/tests/admin/wpMediaListTable.php index 31d2bfa7cbb9d..ff6e453de5741 100644 --- a/tests/phpunit/tests/admin/wpMediaListTable.php +++ b/tests/phpunit/tests/admin/wpMediaListTable.php @@ -479,6 +479,18 @@ public function test_get_row_actions_should_not_include_download_without_an_atta $this->assertArrayNotHasKey( 'download', $actions, '"download" was included in the actions.' ); } + /** + * @covers WP_Media_List_Table::print_column_headers + */ + public function test_sortable_columns_set_comments_descending_by_default() { + ob_start(); + self::$list_table->print_column_headers(); + $output = ob_get_clean(); + + $this->assertStringContainsString( '?orderby=comment_count&order=desc', $output, 'Mismatch of the default link ordering for comments column. Should be desc.' ); + $this->assertMatchesRegularExpression( '/column-comments[^"\\n]*sortable asc/', $output, 'Mismatch of CSS classes for the comments column.' ); + } + /** * Sets the `$is_trash` property. * diff --git a/tests/phpunit/tests/admin/wpPostsListTable.php b/tests/phpunit/tests/admin/wpPostsListTable.php index 9d2482a034af7..49d3243e1d6c0 100644 --- a/tests/phpunit/tests/admin/wpPostsListTable.php +++ b/tests/phpunit/tests/admin/wpPostsListTable.php @@ -330,4 +330,16 @@ public function test_get_views_should_return_views_by_default() { $this->assertSame( $expected, $actual ); } + + /** + * @covers WP_Posts_List_Table::print_column_headers + */ + public function test_sortable_columns_set_comments_descending_by_default() { + ob_start(); + $this->table->print_column_headers(); + $output = ob_get_clean(); + + $this->assertStringContainsString( '?orderby=comment_count&order=desc', $output, 'Mismatch of the default link ordering for comments column. Should be desc.' ); + $this->assertMatchesRegularExpression( '/column-comments[^"\\n]*sortable asc/', $output, 'Mismatch of CSS classes for the comments column.' ); + } } diff --git a/tests/phpunit/tests/admin/wpTermsListTable.php b/tests/phpunit/tests/admin/wpTermsListTable.php index 9071dfd4055c5..990dbc6a25984 100644 --- a/tests/phpunit/tests/admin/wpTermsListTable.php +++ b/tests/phpunit/tests/admin/wpTermsListTable.php @@ -87,4 +87,16 @@ public function test_handle_row_actions_as_admin() { $this->assertStringContainsString( 'Delete', $actions, 'Delete action should be displayed to the admin.' ); $this->assertStringContainsString( admin_url( 'term.php' ), $actions, 'Edit term link should be displayed to the admin.' ); } + + /** + * @covers WP_Terms_List_Table::print_column_headers + */ + public function test_sortable_columns_set_count_columns_descending_by_default() { + ob_start(); + $this->terms_list_table->print_column_headers(); + $category_output = ob_get_clean(); + + $this->assertStringContainsString( '?orderby=count&order=desc', $category_output, 'Mismatch of the default link ordering for posts count column. Should be desc.' ); + $this->assertStringContainsString( 'column-posts sortable asc', $category_output, 'Mismatch of CSS classes for the posts count column.' ); + } } diff --git a/tests/phpunit/tests/multisite/wpMsUsersListTable.php b/tests/phpunit/tests/multisite/wpMsUsersListTable.php index b918edc4cfad1..b8328cfc030ec 100644 --- a/tests/phpunit/tests/multisite/wpMsUsersListTable.php +++ b/tests/phpunit/tests/multisite/wpMsUsersListTable.php @@ -104,4 +104,16 @@ public function test_get_views_should_return_views_by_default() { $this->assertSame( $expected, $this->table->get_views() ); } + + /** + * @covers WP_MS_Users_List_Table::print_column_headers + */ + public function test_sortable_columns_set_registered_descending_by_default() { + ob_start(); + $this->table->print_column_headers(); + $output = ob_get_clean(); + + $this->assertStringContainsString( '?orderby=id&order=desc', $output, 'Mismatch of the default link ordering for registered column. Should be desc.' ); + $this->assertStringContainsString( 'column-registered sortable asc', $output, 'Mismatch of CSS classes for the registered column.' ); + } } From 2c4099155a167cb9858581776c7b07267c72541f Mon Sep 17 00:00:00 2001 From: Deepak Lalwani Date: Tue, 3 Mar 2026 22:27:10 +0530 Subject: [PATCH 2/2] Update tests to use get_echo function --- tests/phpunit/tests/admin/wpLinksListTable.php | 4 +--- tests/phpunit/tests/admin/wpMediaListTable.php | 15 ++++++++++++--- tests/phpunit/tests/admin/wpPostsListTable.php | 4 +--- tests/phpunit/tests/admin/wpTermsListTable.php | 4 +--- .../tests/multisite/wpMsUsersListTable.php | 4 +--- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/tests/phpunit/tests/admin/wpLinksListTable.php b/tests/phpunit/tests/admin/wpLinksListTable.php index 32d1d47475f3d..5f2b3106a05bc 100644 --- a/tests/phpunit/tests/admin/wpLinksListTable.php +++ b/tests/phpunit/tests/admin/wpLinksListTable.php @@ -18,9 +18,7 @@ public function set_up() { * @covers WP_Links_List_Table::print_column_headers */ public function test_sortable_columns_set_rating_descending_by_default() { - ob_start(); - $this->table->print_column_headers(); - $output = ob_get_clean(); + $output = get_echo( array( $this->table, 'print_column_headers' ) ); $this->assertStringContainsString( '?orderby=rating&order=desc', $output, 'Mismatch of the default link ordering for rating column. Should be desc.' ); $this->assertStringContainsString( 'column-rating sortable asc', $output, 'Mismatch of CSS classes for the rating column.' ); diff --git a/tests/phpunit/tests/admin/wpMediaListTable.php b/tests/phpunit/tests/admin/wpMediaListTable.php index ff6e453de5741..f10003cbd4059 100644 --- a/tests/phpunit/tests/admin/wpMediaListTable.php +++ b/tests/phpunit/tests/admin/wpMediaListTable.php @@ -483,9 +483,18 @@ public function test_get_row_actions_should_not_include_download_without_an_atta * @covers WP_Media_List_Table::print_column_headers */ public function test_sortable_columns_set_comments_descending_by_default() { - ob_start(); - self::$list_table->print_column_headers(); - $output = ob_get_clean(); + $attachment_pages_enabled = get_option( 'wp_attachment_pages_enabled' ); + + add_post_type_support( 'attachment', 'comments' ); + update_option( 'wp_attachment_pages_enabled', 1 ); + + $output = get_echo( array( self::$list_table, 'print_column_headers' ) ); + + if ( false === $attachment_pages_enabled ) { + delete_option( 'wp_attachment_pages_enabled' ); + } else { + update_option( 'wp_attachment_pages_enabled', $attachment_pages_enabled ); + } $this->assertStringContainsString( '?orderby=comment_count&order=desc', $output, 'Mismatch of the default link ordering for comments column. Should be desc.' ); $this->assertMatchesRegularExpression( '/column-comments[^"\\n]*sortable asc/', $output, 'Mismatch of CSS classes for the comments column.' ); diff --git a/tests/phpunit/tests/admin/wpPostsListTable.php b/tests/phpunit/tests/admin/wpPostsListTable.php index 49d3243e1d6c0..5a6e1f03812b0 100644 --- a/tests/phpunit/tests/admin/wpPostsListTable.php +++ b/tests/phpunit/tests/admin/wpPostsListTable.php @@ -335,9 +335,7 @@ public function test_get_views_should_return_views_by_default() { * @covers WP_Posts_List_Table::print_column_headers */ public function test_sortable_columns_set_comments_descending_by_default() { - ob_start(); - $this->table->print_column_headers(); - $output = ob_get_clean(); + $output = get_echo( array( $this->table, 'print_column_headers' ) ); $this->assertStringContainsString( '?orderby=comment_count&order=desc', $output, 'Mismatch of the default link ordering for comments column. Should be desc.' ); $this->assertMatchesRegularExpression( '/column-comments[^"\\n]*sortable asc/', $output, 'Mismatch of CSS classes for the comments column.' ); diff --git a/tests/phpunit/tests/admin/wpTermsListTable.php b/tests/phpunit/tests/admin/wpTermsListTable.php index 990dbc6a25984..30857591a50a6 100644 --- a/tests/phpunit/tests/admin/wpTermsListTable.php +++ b/tests/phpunit/tests/admin/wpTermsListTable.php @@ -92,9 +92,7 @@ public function test_handle_row_actions_as_admin() { * @covers WP_Terms_List_Table::print_column_headers */ public function test_sortable_columns_set_count_columns_descending_by_default() { - ob_start(); - $this->terms_list_table->print_column_headers(); - $category_output = ob_get_clean(); + $category_output = get_echo( array( $this->terms_list_table, 'print_column_headers' ) ); $this->assertStringContainsString( '?orderby=count&order=desc', $category_output, 'Mismatch of the default link ordering for posts count column. Should be desc.' ); $this->assertStringContainsString( 'column-posts sortable asc', $category_output, 'Mismatch of CSS classes for the posts count column.' ); diff --git a/tests/phpunit/tests/multisite/wpMsUsersListTable.php b/tests/phpunit/tests/multisite/wpMsUsersListTable.php index b8328cfc030ec..01138cc72c159 100644 --- a/tests/phpunit/tests/multisite/wpMsUsersListTable.php +++ b/tests/phpunit/tests/multisite/wpMsUsersListTable.php @@ -109,9 +109,7 @@ public function test_get_views_should_return_views_by_default() { * @covers WP_MS_Users_List_Table::print_column_headers */ public function test_sortable_columns_set_registered_descending_by_default() { - ob_start(); - $this->table->print_column_headers(); - $output = ob_get_clean(); + $output = get_echo( array( $this->table, 'print_column_headers' ) ); $this->assertStringContainsString( '?orderby=id&order=desc', $output, 'Mismatch of the default link ordering for registered column. Should be desc.' ); $this->assertStringContainsString( 'column-registered sortable asc', $output, 'Mismatch of CSS classes for the registered column.' );