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..5f2b3106a05bc --- /dev/null +++ b/tests/phpunit/tests/admin/wpLinksListTable.php @@ -0,0 +1,26 @@ +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() { + $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 31d2bfa7cbb9d..f10003cbd4059 100644 --- a/tests/phpunit/tests/admin/wpMediaListTable.php +++ b/tests/phpunit/tests/admin/wpMediaListTable.php @@ -479,6 +479,27 @@ 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() { + $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.' ); + } + /** * Sets the `$is_trash` property. * diff --git a/tests/phpunit/tests/admin/wpPostsListTable.php b/tests/phpunit/tests/admin/wpPostsListTable.php index 9d2482a034af7..5a6e1f03812b0 100644 --- a/tests/phpunit/tests/admin/wpPostsListTable.php +++ b/tests/phpunit/tests/admin/wpPostsListTable.php @@ -330,4 +330,14 @@ 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() { + $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 9071dfd4055c5..30857591a50a6 100644 --- a/tests/phpunit/tests/admin/wpTermsListTable.php +++ b/tests/phpunit/tests/admin/wpTermsListTable.php @@ -87,4 +87,14 @@ 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() { + $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 b918edc4cfad1..01138cc72c159 100644 --- a/tests/phpunit/tests/multisite/wpMsUsersListTable.php +++ b/tests/phpunit/tests/multisite/wpMsUsersListTable.php @@ -104,4 +104,14 @@ 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() { + $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.' ); + } }