From 57b7e5f99e8bb73a169142184a9f3b2be834c372 Mon Sep 17 00:00:00 2001 From: costdev Date: Sat, 27 Aug 2022 11:44:19 +0100 Subject: [PATCH 01/31] Add tests for `WP_List_Table::get_views_links()`. --- tests/phpunit/tests/admin/wpListTable.php | 240 ++++++++++++++++++++++ 1 file changed, 240 insertions(+) diff --git a/tests/phpunit/tests/admin/wpListTable.php b/tests/phpunit/tests/admin/wpListTable.php index c07d7579c8c45..294f2a5ca7d4b 100644 --- a/tests/phpunit/tests/admin/wpListTable.php +++ b/tests/phpunit/tests/admin/wpListTable.php @@ -7,6 +7,24 @@ */ class Tests_Admin_WpListTable extends WP_UnitTestCase { + /** + * List table. + * + * @var WP_List_Table $list_table + */ + protected static $list_table; + + public static function set_up_before_class() { + global $hook_suffix; + + parent::set_up_before_class(); + + require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; + + $hook_suffix = '_wp_tests'; + self::$list_table = new WP_List_Table(); + } + /** * Tests that `WP_List_Table::get_column_info()` only adds the primary * column header when necessary. @@ -104,4 +122,226 @@ public function data_should_only_add_primary_column_when_needed() { return $datasets; } + + /** + * Tests the "get_views_links()" method. + * + * @ticket 42066 + * + * @covers WP_List_Table::get_views_links + * + * @dataProvider data_get_views_links + * + * @param array $link_data { + * An array of link data. + * + * @type string $url The link URL. + * @type string $label The link label. + * @type bool $current Optional. Whether this is the currently selected view. + * } + * @param array $expected + */ + public function test_get_views_links( $link_data, $expected ) { + $get_views_links = new ReflectionMethod( self::$list_table, 'get_views_links' ); + $get_views_links->setAccessible( true ); + + $actual = $get_views_links->invokeArgs( self::$list_table, array( $link_data ) ); + + $this->assertSameSetsWithIndex( $expected, $actual ); + } + + /** + * Data provider. + * + * @return array + */ + public function data_get_views_links() { + return array( + 'one "current" link' => array( + 'link_data' => array( + 'all' => array( + 'url' => 'https://example.org/', + 'label' => 'All', + 'current' => true, + ), + 'activated' => array( + 'url' => add_query_arg( 'status', 'activated', 'https://example.org/' ), + 'label' => 'Activated', + 'current' => false, + ), + ), + 'expected' => array( + 'all' => 'All', + 'activated' => 'Activated', + ), + ), + 'two "current" links' => array( + 'link_data' => array( + 'all' => array( + 'url' => 'https://example.org/', + 'label' => 'All', + 'current' => true, + ), + 'activated' => array( + 'url' => add_query_arg( 'status', 'activated', 'https://example.org/' ), + 'label' => 'Activated', + 'current' => true, + ), + ), + 'expected' => array( + 'all' => 'All', + 'activated' => 'Activated', + ), + ), + 'one "current" link and one without "current" key' => array( + 'link_data' => array( + 'all' => array( + 'url' => 'https://example.org/', + 'label' => 'All', + 'current' => true, + ), + 'activated' => array( + 'url' => add_query_arg( 'status', 'activated', 'https://example.org/' ), + 'label' => 'Activated', + ), + ), + 'expected' => array( + 'all' => 'All', + 'activated' => 'Activated', + ), + ), + 'one "current" link with escapable characters' => array( + 'link_data' => array( + 'all' => array( + 'url' => 'https://example.org/', + 'label' => 'All', + 'current' => true, + ), + 'activated' => array( + 'url' => add_query_arg( + array( + 'status' => 'activated', + 'sort' => 'desc', + ), + 'https://example.org/' + ), + 'label' => 'Activated', + 'current' => false, + ), + ), + 'expected' => array( + 'all' => 'All', + 'activated' => 'Activated', + ), + ), + ); + } + + /** + * Tests that "get_views_links()" throws a _doing_it_wrong(). + * + * @ticket 42066 + * + * @covers WP_List_Table::get_views_links + * + * @expectedIncorrectUsage WP_List_Table::get_views_links + * + * @dataProvider data_get_views_links_doing_it_wrong + * + * @param array $link_data { + * An array of link data. + * + * @type string $url The link URL. + * @type string $label The link label. + * @type bool $current Optional. Whether this is the currently selected view. + * } + */ + public function test_get_views_links_doing_it_wrong( $link_data ) { + $get_views_links = new ReflectionMethod( self::$list_table, 'get_views_links' ); + $get_views_links->setAccessible( true ); + $get_views_links->invokeArgs( self::$list_table, array( $link_data ) ); + } + + /** + * Data provider. + * + * @return array + */ + public function data_get_views_links_doing_it_wrong() { + return array( + 'non-array $link_data' => array( + 'link_data' => 'https://example.org, All, class="current" aria-current="page"', + ), + 'a link with no URL' => array( + 'link_data' => array( + 'all' => array( + 'label' => 'All', + 'current' => true, + ), + ), + ), + 'a link with an empty URL' => array( + 'link_data' => array( + 'all' => array( + 'url' => '', + 'label' => 'All', + 'current' => true, + ), + ), + ), + 'a link with a URL of only spaces' => array( + 'link_data' => array( + 'all' => array( + 'url' => ' ', + 'label' => 'All', + 'current' => true, + ), + ), + ), + 'a link with a non-string URL' => array( + 'link_data' => array( + 'all' => array( + 'url' => array(), + 'label' => 'All', + 'current' => true, + ), + ), + ), + 'a link with no label' => array( + 'link_data' => array( + 'all' => array( + 'url' => 'https://example.org/', + 'current' => true, + ), + ), + ), + 'a link with an empty label' => array( + 'link_data' => array( + 'all' => array( + 'url' => 'https://example.org/', + 'label' => '', + 'current' => true, + ), + ), + ), + 'a link with a label of only spaces' => array( + 'link_data' => array( + 'all' => array( + 'url' => 'https://example.org/', + 'label' => ' ', + 'current' => true, + ), + ), + ), + 'a link with a non-string label' => array( + 'link_data' => array( + 'all' => array( + 'url' => 'https://example.org/', + 'label' => array(), + 'current' => true, + ), + ), + ), + ); + } } From 809ab761488d385e703ed17bd53f9d7a03700bd8 Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 19 Jun 2022 07:43:59 +0100 Subject: [PATCH 02/31] Add `WP_List_Table::get_views_links()`. --- src/wp-admin/includes/class-wp-list-table.php | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/src/wp-admin/includes/class-wp-list-table.php b/src/wp-admin/includes/class-wp-list-table.php index 8df48e6a0cda8..f86afe9d19847 100644 --- a/src/wp-admin/includes/class-wp-list-table.php +++ b/src/wp-admin/includes/class-wp-list-table.php @@ -1512,6 +1512,78 @@ public function ajax_response() { die( wp_json_encode( $response ) ); } + /** + * Generates views links. + * + * @since 6.1.0 + * + * @param array $link_data { + * An array of link data. + * + * @type string $url The link URL. + * @type string $label The link label. + * @type bool $current Optional. Whether this is the currently selected view. + * } + * @return array An array of link markup. Keys match the $link_data input array. + */ + protected function get_views_links( $link_data = array() ) { + if ( ! $link_data || ! is_array( $link_data ) ) { + _doing_it_wrong( + __METHOD__, + sprintf( + /* translators: %s: The $link_data argument. */ + __( 'The %s argument must be a non-empty array.' ), + '$link_data' + ), + '6.1.0' + ); + + return array( '' ); + } + + $views_links = array(); + foreach ( $link_data as $view => $link ) { + if ( ! isset( $link['url'] ) || ! is_string( $link['url'] ) || '' === trim( $link['url'] ) ) { + _doing_it_wrong( + __METHOD__, + sprintf( + /* translators: %1$s: The argument name. %2$s: The view name. */ + __( 'The %1$s argument must be a non-empty string for %2$s.' ), + 'url', + $view + ), + '6.1.0' + ); + + continue; + } + + if ( ! isset( $link['label'] ) || ! is_string( $link['label'] ) || '' === trim( $link['label'] ) ) { + _doing_it_wrong( + __METHOD__, + sprintf( + /* translators: %1$s: The argument name. %2$s: The view name. */ + __( 'The %1$s argument must be a non-empty string for %2$s.' ), + 'label', + $view + ), + '6.1.0' + ); + + continue; + } + + $views_links[ $view ] = sprintf( + '%s', + $link['url'], + isset( $link['current'] ) && true === $link['current'] ? ' class="current" aria-current="page"' : '', + $link['label'] + ); + } + + return $views_links; + } + /** * Sends required variables to JavaScript land. * From 3a7181f7aa21709e297dd79e47262e9a98a3cdda Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 28 Aug 2022 05:51:22 +0100 Subject: [PATCH 03/31] Posts: Use `::get_views_links()` in list table. `WP_Posts_List_Table::get_edit_link()` is still used by: - `::column_author()` - `::column_default()` These can be replaced to use `get_views_links()`, but this would lose context. This is another use case for a general function like the proposed `wp_create_links()`. --- .../includes/class-wp-posts-list-table.php | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) 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 4e7dad18c738b..764b60f65a443 100644 --- a/src/wp-admin/includes/class-wp-posts-list-table.php +++ b/src/wp-admin/includes/class-wp-posts-list-table.php @@ -331,16 +331,16 @@ protected function get_views() { number_format_i18n( $this->user_posts_count ) ); - $mine = $this->get_edit_link( $mine_args, $mine_inner_html, $class ); + $mine = array( + 'url' => esc_url( add_query_arg( $mine_args, 'edit.php' ) ), + 'label' => $mine_inner_html, + 'current' => isset( $_GET['author'] ) && ( $current_user_id === (int) $_GET['author'] ), + ); $all_args['all_posts'] = 1; $class = ''; } - if ( empty( $class ) && ( $this->is_base_request() || isset( $_REQUEST['all_posts'] ) ) ) { - $class = 'current'; - } - $all_inner_html = sprintf( /* translators: %s: Number of posts. */ _nx( @@ -352,7 +352,11 @@ protected function get_views() { number_format_i18n( $total_posts ) ); - $status_links['all'] = $this->get_edit_link( $all_args, $all_inner_html, $class ); + $status_links['all'] = array( + 'url' => esc_url( add_query_arg( $all_args, 'edit.php' ) ), + 'label' => $all_inner_html, + 'current' => empty( $class ) && ( $this->is_base_request() || isset( $_REQUEST['all_posts'] ) ), + ); if ( $mine ) { $status_links['mine'] = $mine; @@ -381,7 +385,11 @@ protected function get_views() { number_format_i18n( $num_posts->$status_name ) ); - $status_links[ $status_name ] = $this->get_edit_link( $status_args, $status_label, $class ); + $status_links[ $status_name ] = array( + 'url' => esc_url( add_query_arg( $status_args, 'edit.php' ) ), + 'label' => $status_label, + 'current' => isset( $_REQUEST['post_status'] ) && $status_name === $_REQUEST['post_status'], + ); } if ( ! empty( $this->sticky_posts_count ) ) { @@ -404,7 +412,11 @@ protected function get_views() { ); $sticky_link = array( - 'sticky' => $this->get_edit_link( $sticky_args, $sticky_inner_html, $class ), + 'sticky' => array( + 'url' => esc_url( add_query_arg( $sticky_args, 'edit.php' ) ), + 'label' => $sticky_inner_html, + 'current' => ! empty( $_REQUEST['show_sticky'] ), + ), ); // Sticky comes after Publish, or if not listed, after All. @@ -412,7 +424,7 @@ protected function get_views() { $status_links = array_merge( array_slice( $status_links, 0, $split ), $sticky_link, array_slice( $status_links, $split ) ); } - return $status_links; + return $this->get_views_links( $status_links ); } /** From 588c02b6c7c77414a7d8acae48b187eccb5703c6 Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 28 Aug 2022 05:11:27 +0100 Subject: [PATCH 04/31] Comments: Use `::get_views_links()` in list table. --- .../includes/class-wp-comments-list-table.php | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/wp-admin/includes/class-wp-comments-list-table.php b/src/wp-admin/includes/class-wp-comments-list-table.php index ae462dd0dbe8b..258b23906d1ea 100644 --- a/src/wp-admin/includes/class-wp-comments-list-table.php +++ b/src/wp-admin/includes/class-wp-comments-list-table.php @@ -293,12 +293,6 @@ protected function get_views() { } foreach ( $stati as $status => $label ) { - $current_link_attributes = ''; - - if ( $status === $comment_status ) { - $current_link_attributes = ' class="current" aria-current="page"'; - } - if ( 'mine' === $status ) { $current_user_id = get_current_user_id(); $num_comments->mine = get_comments( @@ -329,14 +323,18 @@ protected function get_views() { $link = add_query_arg( 's', esc_attr( wp_unslash( $_REQUEST['s'] ) ), $link ); */ - $status_links[ $status ] = "" . sprintf( - translate_nooped_plural( $label, $num_comments->$status ), - sprintf( - '%s', - ( 'moderated' === $status ) ? 'pending' : $status, - number_format_i18n( $num_comments->$status ) - ) - ) . ''; + $status_links[ $status ] = array( + 'url' => esc_url( $link ), + 'label' => sprintf( + translate_nooped_plural( $label, $num_comments->$status ), + sprintf( + '%s', + ( 'moderated' === $status ) ? 'pending' : $status, + number_format_i18n( $num_comments->$status ) + ) + ), + 'current' => $status === $comment_status, + ); } /** @@ -348,7 +346,7 @@ protected function get_views() { * @param string[] $status_links An associative array of fully-formed comment status links. Includes 'All', 'Mine', * 'Pending', 'Approved', 'Spam', and 'Trash'. */ - return apply_filters( 'comment_status_links', $status_links ); + return apply_filters( 'comment_status_links', $this->get_views_links( $status_links ) ); } /** From 7d4de21afca67a83f79ae0b0ea926889d81eb156 Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 19 Jun 2022 07:44:46 +0100 Subject: [PATCH 05/31] Users: Use `::get_views_links()` in list table. --- .../includes/class-wp-users-list-table.php | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/src/wp-admin/includes/class-wp-users-list-table.php b/src/wp-admin/includes/class-wp-users-list-table.php index 19921ae5bcac2..381354b36a4b8 100644 --- a/src/wp-admin/includes/class-wp-users-list-table.php +++ b/src/wp-admin/includes/class-wp-users-list-table.php @@ -185,10 +185,9 @@ protected function get_views() { $url = 'users.php'; } - $role_links = array(); - $avail_roles = array(); - $all_text = __( 'All' ); - $current_link_attributes = empty( $role ) ? ' class="current" aria-current="page"' : ''; + $role_links = array(); + $avail_roles = array(); + $all_text = __( 'All' ); if ( $count_users ) { if ( $this->is_site_users ) { @@ -215,19 +214,17 @@ protected function get_views() { ); } - $role_links['all'] = sprintf( '%s', $url, $current_link_attributes, $all_text ); + $role_links['all'] = array( + 'url' => $url, + 'label' => $all_text, + 'current' => empty( $role ), + ); foreach ( $wp_roles->get_names() as $this_role => $name ) { if ( $count_users && ! isset( $avail_roles[ $this_role ] ) ) { continue; } - $current_link_attributes = ''; - - if ( $this_role === $role ) { - $current_link_attributes = ' class="current" aria-current="page"'; - } - $name = translate_user_role( $name ); if ( $count_users ) { $name = sprintf( @@ -238,17 +235,15 @@ protected function get_views() { ); } - $role_links[ $this_role ] = "$name"; + $role_links[ $this_role ] = array( + 'url' => esc_url( add_query_arg( 'role', $this_role, $url ) ), + 'label' => $name, + 'current' => $this_role === $role, + ); } if ( ! empty( $avail_roles['none'] ) ) { - $current_link_attributes = ''; - - if ( 'none' === $role ) { - $current_link_attributes = ' class="current" aria-current="page"'; - } - $name = __( 'No role' ); $name = sprintf( /* translators: 1: User role name, 2: Number of users. */ @@ -257,10 +252,14 @@ protected function get_views() { number_format_i18n( $avail_roles['none'] ) ); - $role_links['none'] = "$name"; + $role_links['none'] = array( + 'url' => esc_url( add_query_arg( 'role', 'none', $url ) ), + 'label' => $name, + 'current' => 'none' === $role, + ); } - return $role_links; + return $this->get_views_links( $role_links ); } /** From 5a358f26fff2cea5a650d4ddb8b1e0fe5fe27729 Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 19 Jun 2022 07:45:09 +0100 Subject: [PATCH 06/31] Plugins: Use `::get_views_links()` in list table. --- src/wp-admin/includes/class-wp-plugins-list-table.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/wp-admin/includes/class-wp-plugins-list-table.php b/src/wp-admin/includes/class-wp-plugins-list-table.php index d5a4a93e3fd98..930c89f1ecfbe 100644 --- a/src/wp-admin/includes/class-wp-plugins-list-table.php +++ b/src/wp-admin/includes/class-wp-plugins-list-table.php @@ -576,16 +576,15 @@ protected function get_views() { } if ( 'search' !== $type ) { - $status_links[ $type ] = sprintf( - "%s", - add_query_arg( 'plugin_status', $type, 'plugins.php' ), - ( $type === $status ) ? ' class="current" aria-current="page"' : '', - sprintf( $text, number_format_i18n( $count ) ) + $status_links[ $type ] = array( + 'url' => add_query_arg( 'plugin_status', $type, 'plugins.php' ), + 'label' => sprintf( $text, number_format_i18n( $count ) ), + 'current' => $type === $status, ); } } - return $status_links; + return $this->get_views_links( $status_links ); } /** From d1fbe288de973b94d33c69517536eb1712269c0b Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 19 Jun 2022 07:45:20 +0100 Subject: [PATCH 07/31] Plugin Install: Use `::get_views_links()` in list table. --- .../includes/class-wp-plugin-install-list-table.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/wp-admin/includes/class-wp-plugin-install-list-table.php b/src/wp-admin/includes/class-wp-plugin-install-list-table.php index 3c8dc1d2bbbe1..c482c7fa998cd 100644 --- a/src/wp-admin/includes/class-wp-plugin-install-list-table.php +++ b/src/wp-admin/includes/class-wp-plugin-install-list-table.php @@ -310,14 +310,16 @@ protected function get_views() { $display_tabs = array(); foreach ( (array) $tabs as $action => $text ) { - $current_link_attributes = ( $action === $tab ) ? ' class="current" aria-current="page"' : ''; - $href = self_admin_url( 'plugin-install.php?tab=' . $action ); - $display_tabs[ 'plugin-install-' . $action ] = "$text"; + $display_tabs[ 'plugin-install-' . $action ] = array( + 'url' => self_admin_url( 'plugin-install.php?tab=' . $action ), + 'label' => $text, + 'current' => $action === $tab, + ); } // No longer a real tab. unset( $display_tabs['plugin-install-upload'] ); - return $display_tabs; + return $this->get_views_links( $display_tabs ); } /** From fea9e02711e564629db71318c0ee084f7a42a145 Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 19 Jun 2022 07:45:29 +0100 Subject: [PATCH 08/31] Theme Install: Use `::get_views_links()` in list table. --- .../includes/class-wp-theme-install-list-table.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/wp-admin/includes/class-wp-theme-install-list-table.php b/src/wp-admin/includes/class-wp-theme-install-list-table.php index 17f8f8598caea..a02767f2775db 100644 --- a/src/wp-admin/includes/class-wp-theme-install-list-table.php +++ b/src/wp-admin/includes/class-wp-theme-install-list-table.php @@ -186,12 +186,14 @@ protected function get_views() { $display_tabs = array(); foreach ( (array) $tabs as $action => $text ) { - $current_link_attributes = ( $action === $tab ) ? ' class="current" aria-current="page"' : ''; - $href = self_admin_url( 'theme-install.php?tab=' . $action ); - $display_tabs[ 'theme-install-' . $action ] = "$text"; + $display_tabs[ 'theme-install-' . $action ] = array( + 'url' => self_admin_url( 'theme-install.php?tab=' . $action ), + 'label' => $text, + 'current' => $action === $tab, + ); } - return $display_tabs; + return $this->get_views_links( $display_tabs ); } /** From 4361d930eab4f665b3c356243fc663347323a4e4 Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 28 Aug 2022 05:58:22 +0100 Subject: [PATCH 09/31] Privacy Requests: Use `::get_views_links()` in list table. --- .../class-wp-privacy-requests-table.php | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/wp-admin/includes/class-wp-privacy-requests-table.php b/src/wp-admin/includes/class-wp-privacy-requests-table.php index 05dbcbc03128f..3061b73375d88 100644 --- a/src/wp-admin/includes/class-wp-privacy-requests-table.php +++ b/src/wp-admin/includes/class-wp-privacy-requests-table.php @@ -153,8 +153,7 @@ protected function get_views() { // Normalized admin URL. $admin_url = $this->get_admin_url(); - $current_link_attributes = empty( $current_status ) ? ' class="current" aria-current="page"' : ''; - $status_label = sprintf( + $status_label = sprintf( /* translators: %s: Number of requests. */ _nx( 'All (%s)', @@ -165,11 +164,10 @@ protected function get_views() { number_format_i18n( $total_requests ) ); - $views['all'] = sprintf( - '%s', - esc_url( $admin_url ), - $current_link_attributes, - $status_label + $views['all'] = array( + 'url' => esc_url( $admin_url ), + 'label' => $status_label, + 'current' => empty( $current_status ), ); foreach ( $statuses as $status => $label ) { @@ -178,8 +176,7 @@ protected function get_views() { continue; } - $current_link_attributes = $status === $current_status ? ' class="current" aria-current="page"' : ''; - $total_status_requests = absint( $counts->{$status} ); + $total_status_requests = absint( $counts->{$status} ); if ( ! $total_status_requests ) { continue; @@ -192,15 +189,14 @@ protected function get_views() { $status_link = add_query_arg( 'filter-status', $status, $admin_url ); - $views[ $status ] = sprintf( - '%s', - esc_url( $status_link ), - $current_link_attributes, - $status_label + $views[ $status ] = array( + 'url' => esc_url( $status_link ), + 'label' => $status_label, + 'current' => $status === $current_status, ); } - return $views; + return $this->get_views_links( $views ); } /** From 3de35a5e575d00c0bb6d73ac34d5255f905f86d8 Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 19 Jun 2022 07:45:46 +0100 Subject: [PATCH 10/31] MS Sites: Use `::get_views_links()` in list table. --- .../includes/class-wp-ms-sites-list-table.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/wp-admin/includes/class-wp-ms-sites-list-table.php b/src/wp-admin/includes/class-wp-ms-sites-list-table.php index 2d014700bb1c8..d50b7f84b493a 100644 --- a/src/wp-admin/includes/class-wp-ms-sites-list-table.php +++ b/src/wp-admin/includes/class-wp-ms-sites-list-table.php @@ -262,23 +262,19 @@ protected function get_views() { $url = 'sites.php'; foreach ( $statuses as $status => $label_count ) { - $current_link_attributes = $requested_status === $status || ( '' === $requested_status && 'all' === $status ) - ? ' class="current" aria-current="page"' - : ''; if ( (int) $counts[ $status ] > 0 ) { $label = sprintf( translate_nooped_plural( $label_count, $counts[ $status ] ), number_format_i18n( $counts[ $status ] ) ); $full_url = 'all' === $status ? $url : add_query_arg( 'status', $status, $url ); - $view_links[ $status ] = sprintf( - '%3$s', - esc_url( $full_url ), - $current_link_attributes, - $label + $view_links[ $status ] = array( + 'url' => esc_url( $full_url ), + 'label' => $label, + 'current' => $requested_status === $status || ( '' === $requested_status && 'all' === $status ), ); } } - return $view_links; + return $this->get_views_links( $view_links ); } /** From 47f5f9d998ebb109d617a8e1d0add6db2a1ceeb2 Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 19 Jun 2022 07:44:58 +0100 Subject: [PATCH 11/31] MS Users: Use `::get_views_links()` in list table. --- .../includes/class-wp-ms-users-list-table.php | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) 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 d2ba7c72b5123..857a4f05a776d 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 @@ -137,13 +137,10 @@ protected function get_views() { $super_admins = get_super_admins(); $total_admins = count( $super_admins ); - $current_link_attributes = 'super' !== $role ? ' class="current" aria-current="page"' : ''; - $role_links = array(); - $role_links['all'] = sprintf( - '%s', - network_admin_url( 'users.php' ), - $current_link_attributes, - sprintf( + $role_links = array(); + $role_links['all'] = array( + 'url' => network_admin_url( 'users.php' ), + 'label' => sprintf( /* translators: Number of users. */ _nx( 'All (%s)', @@ -152,14 +149,13 @@ protected function get_views() { 'users' ), number_format_i18n( $total_users ) - ) + ), + 'current' => 'super' !== $role, ); - $current_link_attributes = 'super' === $role ? ' class="current" aria-current="page"' : ''; - $role_links['super'] = sprintf( - '%s', - network_admin_url( 'users.php?role=super' ), - $current_link_attributes, - sprintf( + + $role_links['super'] = array( + 'url' => network_admin_url( 'users.php?role=super' ), + 'label' => sprintf( /* translators: Number of users. */ _n( 'Super Admin (%s)', @@ -167,10 +163,11 @@ protected function get_views() { $total_admins ), number_format_i18n( $total_admins ) - ) + ), + 'current' => 'super' === $role, ); - return $role_links; + return $this->get_views_links( $role_links ); } /** From 0425791f265dde0f49a3cee3096f6166734141bb Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 19 Jun 2022 07:45:35 +0100 Subject: [PATCH 12/31] MS Themes: Use `::get_views_links()` in list table. --- .../includes/class-wp-ms-themes-list-table.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/wp-admin/includes/class-wp-ms-themes-list-table.php b/src/wp-admin/includes/class-wp-ms-themes-list-table.php index e87da5ca7a80b..70073e81303f7 100644 --- a/src/wp-admin/includes/class-wp-ms-themes-list-table.php +++ b/src/wp-admin/includes/class-wp-ms-themes-list-table.php @@ -444,16 +444,15 @@ protected function get_views() { } if ( 'search' !== $type ) { - $status_links[ $type ] = sprintf( - "%s", - esc_url( add_query_arg( 'theme_status', $type, $url ) ), - ( $type === $status ) ? ' class="current" aria-current="page"' : '', - sprintf( $text, number_format_i18n( $count ) ) + $status_links[ $type ] = array( + 'url' => esc_url( add_query_arg( 'theme_status', $type, $url ) ), + 'label' => sprintf( $text, number_format_i18n( $count ) ), + 'current' => $type === $status, ); } } - return $status_links; + return $this->get_views_links( $status_links ); } /** From 9f34460b93b202fc5a500ca413adbf5d2255a1c8 Mon Sep 17 00:00:00 2001 From: costdev Date: Tue, 26 Jul 2022 22:59:05 +0100 Subject: [PATCH 13/31] WP_List_Table: Allow empty `$link_data` array. --- src/wp-admin/includes/class-wp-list-table.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-admin/includes/class-wp-list-table.php b/src/wp-admin/includes/class-wp-list-table.php index f86afe9d19847..38937f6912e51 100644 --- a/src/wp-admin/includes/class-wp-list-table.php +++ b/src/wp-admin/includes/class-wp-list-table.php @@ -1527,12 +1527,12 @@ public function ajax_response() { * @return array An array of link markup. Keys match the $link_data input array. */ protected function get_views_links( $link_data = array() ) { - if ( ! $link_data || ! is_array( $link_data ) ) { + if ( ! is_array( $link_data ) ) { _doing_it_wrong( __METHOD__, sprintf( /* translators: %s: The $link_data argument. */ - __( 'The %s argument must be a non-empty array.' ), + __( 'The %s argument must be an array.' ), '$link_data' ), '6.1.0' From bcb9adce3fc9a4af0b123fa8ffb3e29330c6dd8b Mon Sep 17 00:00:00 2001 From: costdev Date: Tue, 26 Jul 2022 22:59:44 +0100 Subject: [PATCH 14/31] WP_List_Table: Use `empty()` for URL and label. --- src/wp-admin/includes/class-wp-list-table.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-admin/includes/class-wp-list-table.php b/src/wp-admin/includes/class-wp-list-table.php index 38937f6912e51..4cafacbad8c98 100644 --- a/src/wp-admin/includes/class-wp-list-table.php +++ b/src/wp-admin/includes/class-wp-list-table.php @@ -1543,7 +1543,7 @@ protected function get_views_links( $link_data = array() ) { $views_links = array(); foreach ( $link_data as $view => $link ) { - if ( ! isset( $link['url'] ) || ! is_string( $link['url'] ) || '' === trim( $link['url'] ) ) { + if ( empty( $link['url'] ) || ! is_string( $link['url'] ) || '' === trim( $link['url'] ) ) { _doing_it_wrong( __METHOD__, sprintf( @@ -1558,7 +1558,7 @@ protected function get_views_links( $link_data = array() ) { continue; } - if ( ! isset( $link['label'] ) || ! is_string( $link['label'] ) || '' === trim( $link['label'] ) ) { + if ( empty( $link['label'] ) || ! is_string( $link['label'] ) || '' === trim( $link['label'] ) ) { _doing_it_wrong( __METHOD__, sprintf( From 8b4c3cba502b0328752533339875c5b55a9396e7 Mon Sep 17 00:00:00 2001 From: costdev Date: Tue, 26 Jul 2022 23:00:26 +0100 Subject: [PATCH 15/31] WP_List_Table: Improve escaping. --- src/wp-admin/includes/class-wp-list-table.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wp-admin/includes/class-wp-list-table.php b/src/wp-admin/includes/class-wp-list-table.php index 4cafacbad8c98..43f2413390f9f 100644 --- a/src/wp-admin/includes/class-wp-list-table.php +++ b/src/wp-admin/includes/class-wp-list-table.php @@ -1550,7 +1550,7 @@ protected function get_views_links( $link_data = array() ) { /* translators: %1$s: The argument name. %2$s: The view name. */ __( 'The %1$s argument must be a non-empty string for %2$s.' ), 'url', - $view + esc_html( $view ) ), '6.1.0' ); @@ -1565,7 +1565,7 @@ protected function get_views_links( $link_data = array() ) { /* translators: %1$s: The argument name. %2$s: The view name. */ __( 'The %1$s argument must be a non-empty string for %2$s.' ), 'label', - $view + esc_html( $view ) ), '6.1.0' ); @@ -1575,7 +1575,7 @@ protected function get_views_links( $link_data = array() ) { $views_links[ $view ] = sprintf( '%s', - $link['url'], + esc_url( $link['url'] ), isset( $link['current'] ) && true === $link['current'] ? ' class="current" aria-current="page"' : '', $link['label'] ); From bcdadf3fb08498cc2d3b2b981610790ded89b5bf Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 28 Aug 2022 05:48:20 +0100 Subject: [PATCH 16/31] Add tests for `WP_Posts_List_Table::get_views()`. --- .../phpunit/tests/admin/wpPostsListTable.php | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/phpunit/tests/admin/wpPostsListTable.php b/tests/phpunit/tests/admin/wpPostsListTable.php index 306fddb65d9fa..c209179870944 100644 --- a/tests/phpunit/tests/admin/wpPostsListTable.php +++ b/tests/phpunit/tests/admin/wpPostsListTable.php @@ -319,4 +319,26 @@ public function test_empty_trash_button_should_not_be_shown_if_there_are_no_post $this->assertStringNotContainsString( 'id="delete_all"', $output ); } + /** + * @ticket 42066 + * + * @covers WP_Posts_List_Table::get_views + */ + public function test_get_views_should_return_views_by_default() { + global $avail_post_stati; + + $avail_post_stati_backup = $avail_post_stati; + $avail_post_stati = get_available_post_statuses(); + + $actual = $this->table->get_views(); + $avail_post_stati = $avail_post_stati_backup; + + $expected = array( + 'all' => 'All (38)', + 'publish' => 'Published (38)', + ); + + $this->assertSame( $expected, $actual ); + } + } From 815daf514ab75f15ba63704467ebef5fc6d264ab Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 28 Aug 2022 05:10:43 +0100 Subject: [PATCH 17/31] Add tests for `WP_Comments_List_Table::get_views()`. --- .../tests/admin/wpCommentsListTable.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/phpunit/tests/admin/wpCommentsListTable.php b/tests/phpunit/tests/admin/wpCommentsListTable.php index b05c5fa5f1970..a22d1d8097567 100644 --- a/tests/phpunit/tests/admin/wpCommentsListTable.php +++ b/tests/phpunit/tests/admin/wpCommentsListTable.php @@ -195,4 +195,23 @@ public function test_sortable_columns_with_current_ordering() { $this->assertStringContainsString( 'column-date sorted desc', $output, 'Mismatch of CSS classes for the comment date column.' ); } + /** + * @ticket 42066 + * + * @covers WP_Comments_List_Table::get_views + */ + public function test_get_views_should_return_views_by_default() { + $this->table->prepare_items(); + + $expected = array( + 'all' => 'All (0)', + 'mine' => 'Mine (0)', + 'moderated' => 'Pending (0)', + 'approved' => 'Approved (0)', + 'spam' => 'Spam (0)', + 'trash' => 'Trash (0)', + ); + $this->assertSame( $expected, $this->table->get_views() ); + } + } From ea3e1cd22086ad32172f3f157ab0aff5da61f31f Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 28 Aug 2022 05:22:28 +0100 Subject: [PATCH 18/31] Add tests for `WP_Post_Comments_List_Table::get_views()`. --- .../tests/admin/wpPostCommentsListTable.php | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tests/phpunit/tests/admin/wpPostCommentsListTable.php diff --git a/tests/phpunit/tests/admin/wpPostCommentsListTable.php b/tests/phpunit/tests/admin/wpPostCommentsListTable.php new file mode 100644 index 0000000000000..092d003314d67 --- /dev/null +++ b/tests/phpunit/tests/admin/wpPostCommentsListTable.php @@ -0,0 +1,39 @@ +table = _get_list_table( 'WP_Post_Comments_List_Table', array( 'screen' => 'edit-post-comments' ) ); + } + + /** + * @ticket 42066 + * + * @covers WP_Post_Comments_List_Table::get_views + */ + public function test_get_views_should_return_views_by_default() { + $this->table->prepare_items(); + + $expected = array( + 'all' => 'All (0)', + 'mine' => 'Mine (0)', + 'moderated' => 'Pending (0)', + 'approved' => 'Approved (0)', + 'spam' => 'Spam (0)', + 'trash' => 'Trash (0)', + ); + $this->assertSame( $expected, $this->table->get_views() ); + } + +} From ac36df8e53349e9e2907eca3bfb2057b16e84288 Mon Sep 17 00:00:00 2001 From: costdev Date: Sat, 27 Aug 2022 12:22:33 +0100 Subject: [PATCH 19/31] Add tests for `WP_Users_List_Table::get_views()`. --- .../phpunit/tests/admin/wpUsersListTable.php | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tests/phpunit/tests/admin/wpUsersListTable.php diff --git a/tests/phpunit/tests/admin/wpUsersListTable.php b/tests/phpunit/tests/admin/wpUsersListTable.php new file mode 100644 index 0000000000000..0ff91ba5aa428 --- /dev/null +++ b/tests/phpunit/tests/admin/wpUsersListTable.php @@ -0,0 +1,32 @@ +table = _get_list_table( 'WP_Users_List_Table', array( 'screen' => 'users' ) ); + } + + /** + * @ticket 42066 + * + * @covers WP_Users_List_Table::get_views + */ + public function test_get_views_should_return_views_by_default() { + $expected = array( + 'all' => 'All (1)', + 'administrator' => 'Administrator (1)', + ); + + $this->assertSame( $expected, $this->table->get_views() ); + } +} From e54bf1228e44f7a71f8b99961b44010c1930a7b6 Mon Sep 17 00:00:00 2001 From: costdev Date: Sat, 27 Aug 2022 12:46:17 +0100 Subject: [PATCH 20/31] Add tests for `WP_Plugins_List_Table::get_views()`. --- .../tests/admin/wpPluginsListTable.php | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 tests/phpunit/tests/admin/wpPluginsListTable.php diff --git a/tests/phpunit/tests/admin/wpPluginsListTable.php b/tests/phpunit/tests/admin/wpPluginsListTable.php new file mode 100644 index 0000000000000..072539d5c2b41 --- /dev/null +++ b/tests/phpunit/tests/admin/wpPluginsListTable.php @@ -0,0 +1,59 @@ +table = _get_list_table( 'WP_Plugins_List_Table', array( 'screen' => 'plugins' ) ); + } + + /** + * @ticket 42066 + * + * @covers WP_Plugins_List_Table::get_views + */ + public function test_get_views_should_return_views_by_default() { + global $totals; + + $totals_backup = $totals; + $totals = array( + 'all' => 45, + 'active' => 1, + 'recently_activated' => 2, + 'inactive' => 3, + 'mustuse' => 4, + 'dropins' => 5, + 'paused' => 6, + 'upgrade' => 7, + 'auto-update-enabled' => 8, + 'auto-update-disabled' => 9, + ); + + $expected = array( + 'all' => 'All (45)', + 'active' => 'Active (1)', + 'recently_activated' => 'Recently Active (2)', + 'inactive' => 'Inactive (3)', + 'mustuse' => 'Must-Use (4)', + 'dropins' => 'Drop-ins (5)', + 'paused' => 'Paused (6)', + 'upgrade' => 'Update Available (7)', + 'auto-update-enabled' => 'Auto-updates Enabled (8)', + 'auto-update-disabled' => 'Auto-updates Disabled (9)', + ); + + $actual = $this->table->get_views(); + $totals = $totals_backup; + + $this->assertSame( $expected, $actual ); + } +} From f400ab7d78504636b3c18e3a57d359f77fb937f1 Mon Sep 17 00:00:00 2001 From: costdev Date: Sat, 27 Aug 2022 12:52:02 +0100 Subject: [PATCH 21/31] Add tests for `WP_Plugin_Install_List_Table::get_views()`. --- .../tests/admin/wpPluginInstallListTable.php | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tests/phpunit/tests/admin/wpPluginInstallListTable.php diff --git a/tests/phpunit/tests/admin/wpPluginInstallListTable.php b/tests/phpunit/tests/admin/wpPluginInstallListTable.php new file mode 100644 index 0000000000000..406c740a443f3 --- /dev/null +++ b/tests/phpunit/tests/admin/wpPluginInstallListTable.php @@ -0,0 +1,27 @@ +table = _get_list_table( 'WP_Plugin_Install_List_Table', array( 'screen' => 'plugin-install' ) ); + } + + /** + * @ticket 42066 + * + * @covers WP_Plugin_Install_List_Table::get_views + */ + public function test_get_views_should_return_no_views_by_default() { + $this->assertSame( array(), $this->table->get_views() ); + } +} From 9e30826b07c3946fcb8257125d46166d934554c2 Mon Sep 17 00:00:00 2001 From: costdev Date: Sat, 27 Aug 2022 13:01:55 +0100 Subject: [PATCH 22/31] Add tests for `WP_Theme_Install_List_Table::get_views()`. --- .../tests/admin/wpThemeInstallListTable.php | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tests/phpunit/tests/admin/wpThemeInstallListTable.php diff --git a/tests/phpunit/tests/admin/wpThemeInstallListTable.php b/tests/phpunit/tests/admin/wpThemeInstallListTable.php new file mode 100644 index 0000000000000..2c1c157c0f00b --- /dev/null +++ b/tests/phpunit/tests/admin/wpThemeInstallListTable.php @@ -0,0 +1,27 @@ +table = _get_list_table( 'WP_Theme_Install_List_Table', array( 'screen' => 'theme-install' ) ); + } + + /** + * @ticket 42066 + * + * @covers WP_Theme_Install_List_Table::get_views + */ + public function test_get_views_should_return_no_views_by_default() { + $this->assertSame( array(), $this->table->get_views() ); + } +} From 79639ea62cccc12e36e15096f2dbf5bac4ee73bc Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 28 Aug 2022 05:58:19 +0100 Subject: [PATCH 23/31] Add tests for `WP_Privacy_Requests_List_Table::get_views()`. --- .../phpunit/tests/admin/wpPrivacyRequestsTable.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/phpunit/tests/admin/wpPrivacyRequestsTable.php b/tests/phpunit/tests/admin/wpPrivacyRequestsTable.php index 34b0b251f29b7..7f555c4d250f4 100644 --- a/tests/phpunit/tests/admin/wpPrivacyRequestsTable.php +++ b/tests/phpunit/tests/admin/wpPrivacyRequestsTable.php @@ -198,4 +198,17 @@ public function data_test_columns_should_be_sortable() { ), ); } + + /** + * @ticket 42066 + * + * @covers WP_Privacy_Requests_List_Table::get_views + */ + public function test_get_views_should_return_views_by_default() { + $expected = array( + 'all' => 'All (0)', + ); + + $this->assertSame( $expected, $this->get_mocked_class_instance()->get_views() ); + } } From 0d11699e5cd5fe9991a633e9b10548e5b7d1d17a Mon Sep 17 00:00:00 2001 From: costdev Date: Sat, 27 Aug 2022 12:14:31 +0100 Subject: [PATCH 24/31] Add tests for `WP_MS_Sites_List_Table::get_views()`. --- tests/phpunit/tests/multisite/wpMsSitesListTable.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/phpunit/tests/multisite/wpMsSitesListTable.php b/tests/phpunit/tests/multisite/wpMsSitesListTable.php index 8bccd34f07fe2..559f7412f4334 100644 --- a/tests/phpunit/tests/multisite/wpMsSitesListTable.php +++ b/tests/phpunit/tests/multisite/wpMsSitesListTable.php @@ -230,5 +230,17 @@ public function test_ms_sites_list_table_subdirectory_path_search_items_with_tra $this->assertSameSets( $expected, $items ); } + + /** + * @ticket 42066 + */ + public function test_get_views_should_return_views_by_default() { + $expected = array( + 'all' => 'All (14)', + 'public' => 'Public (14)', + ); + + $this->assertSame( $expected, $this->table->get_views() ); + } } endif; From ae2ebd75a33f7daca8134bd65d7f407c7d378e48 Mon Sep 17 00:00:00 2001 From: costdev Date: Sat, 27 Aug 2022 12:30:04 +0100 Subject: [PATCH 25/31] Add tests for `WP_MS_Users_List_Table::get_views()`. --- .../tests/multisite/wpMsUsersListTable.php | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 tests/phpunit/tests/multisite/wpMsUsersListTable.php diff --git a/tests/phpunit/tests/multisite/wpMsUsersListTable.php b/tests/phpunit/tests/multisite/wpMsUsersListTable.php new file mode 100644 index 0000000000000..450cd3e8a40e9 --- /dev/null +++ b/tests/phpunit/tests/multisite/wpMsUsersListTable.php @@ -0,0 +1,106 @@ +table = _get_list_table( 'WP_MS_Users_List_Table', array( 'screen' => 'ms-users' ) ); + } + + public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { + self::$site_ids = array( + 'wordpress.org/' => array( + 'domain' => 'wordpress.org', + 'path' => '/', + ), + 'wordpress.org/foo/' => array( + 'domain' => 'wordpress.org', + 'path' => '/foo/', + ), + 'wordpress.org/foo/bar/' => array( + 'domain' => 'wordpress.org', + 'path' => '/foo/bar/', + ), + 'wordpress.org/afoo/' => array( + 'domain' => 'wordpress.org', + 'path' => '/afoo/', + ), + 'make.wordpress.org/' => array( + 'domain' => 'make.wordpress.org', + 'path' => '/', + ), + 'make.wordpress.org/foo/' => array( + 'domain' => 'make.wordpress.org', + 'path' => '/foo/', + ), + 'www.w.org/' => array( + 'domain' => 'www.w.org', + 'path' => '/', + ), + 'www.w.org/foo/' => array( + 'domain' => 'www.w.org', + 'path' => '/foo/', + ), + 'www.w.org/foo/bar/' => array( + 'domain' => 'www.w.org', + 'path' => '/foo/bar/', + ), + 'test.example.org/' => array( + 'domain' => 'test.example.org', + 'path' => '/', + ), + 'test2.example.org/' => array( + 'domain' => 'test2.example.org', + 'path' => '/', + ), + 'test3.example.org/zig/' => array( + 'domain' => 'test3.example.org', + 'path' => '/zig/', + ), + 'atest.example.org/' => array( + 'domain' => 'atest.example.org', + 'path' => '/', + ), + ); + + foreach ( self::$site_ids as &$id ) { + $id = $factory->blog->create( $id ); + } + unset( $id ); + } + + public static function wpTearDownAfterClass() { + foreach ( self::$site_ids as $site_id ) { + wp_delete_site( $site_id ); + } + } + + /** + * @ticket 42066 + * + * @covers WP_MS_Users_List_Table::get_views + */ + public function test_get_views_should_return_views_by_default() { + $expected = array( + 'all' => 'All (1)', + 'super' => 'Super Admin (1)', + ); + + $this->assertSame( $expected, $this->table->get_views() ); + } + } +endif; From 45333b447d2e2ea0e45f2ea03a330a932a18b6af Mon Sep 17 00:00:00 2001 From: costdev Date: Sat, 27 Aug 2022 13:11:20 +0100 Subject: [PATCH 26/31] Add tests for `WP_MS_Themes_List_Table::get_views()`. --- .../tests/multisite/wpMsThemesListTable.php | 127 ++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 tests/phpunit/tests/multisite/wpMsThemesListTable.php diff --git a/tests/phpunit/tests/multisite/wpMsThemesListTable.php b/tests/phpunit/tests/multisite/wpMsThemesListTable.php new file mode 100644 index 0000000000000..36d25839341a0 --- /dev/null +++ b/tests/phpunit/tests/multisite/wpMsThemesListTable.php @@ -0,0 +1,127 @@ +table = _get_list_table( 'WP_MS_Themes_List_Table', array( 'screen' => 'ms-themes' ) ); + } + + public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { + self::$site_ids = array( + 'wordpress.org/' => array( + 'domain' => 'wordpress.org', + 'path' => '/', + ), + 'wordpress.org/foo/' => array( + 'domain' => 'wordpress.org', + 'path' => '/foo/', + ), + 'wordpress.org/foo/bar/' => array( + 'domain' => 'wordpress.org', + 'path' => '/foo/bar/', + ), + 'wordpress.org/afoo/' => array( + 'domain' => 'wordpress.org', + 'path' => '/afoo/', + ), + 'make.wordpress.org/' => array( + 'domain' => 'make.wordpress.org', + 'path' => '/', + ), + 'make.wordpress.org/foo/' => array( + 'domain' => 'make.wordpress.org', + 'path' => '/foo/', + ), + 'www.w.org/' => array( + 'domain' => 'www.w.org', + 'path' => '/', + ), + 'www.w.org/foo/' => array( + 'domain' => 'www.w.org', + 'path' => '/foo/', + ), + 'www.w.org/foo/bar/' => array( + 'domain' => 'www.w.org', + 'path' => '/foo/bar/', + ), + 'test.example.org/' => array( + 'domain' => 'test.example.org', + 'path' => '/', + ), + 'test2.example.org/' => array( + 'domain' => 'test2.example.org', + 'path' => '/', + ), + 'test3.example.org/zig/' => array( + 'domain' => 'test3.example.org', + 'path' => '/zig/', + ), + 'atest.example.org/' => array( + 'domain' => 'atest.example.org', + 'path' => '/', + ), + ); + + foreach ( self::$site_ids as &$id ) { + $id = $factory->blog->create( $id ); + } + unset( $id ); + } + + public static function wpTearDownAfterClass() { + foreach ( self::$site_ids as $site_id ) { + wp_delete_site( $site_id ); + } + } + + /** + * @ticket 42066 + * + * @covers WP_MS_Themes_List_Table::get_views + */ + public function test_get_views_should_return_views_by_default() { + global $totals; + + $totals_backup = $totals; + $totals = array( + 'all' => 21, + 'enabled' => 1, + 'disabled' => 2, + 'upgrade' => 3, + 'broken' => 4, + 'auto-update-enabled' => 5, + 'auto-update-disabled' => 6, + ); + + $expected = array( + 'all' => 'All (21)', + 'enabled' => 'Enabled (1)', + 'disabled' => 'Disabled (2)', + 'upgrade' => 'Update Available (3)', + 'broken' => 'Broken (4)', + 'auto-update-enabled' => 'Auto-updates Enabled (5)', + 'auto-update-disabled' => 'Auto-updates Disabled (6)', + ); + + $actual = $this->table->get_views(); + $totals = $totals_backup; + + $this->assertSame( $expected, $actual ); + } + } +endif; From e4a63bb0a18ce9d78ede76c08a7b9ff39e7386cf Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 19 Jun 2022 07:45:35 +0100 Subject: [PATCH 27/31] Tests: Replace `\'` with `"` to fix failures. --- .../tests/admin/wpCommentsListTable.php | 12 +++++------ .../tests/admin/wpPluginsListTable.php | 20 +++++++++---------- .../tests/admin/wpPostCommentsListTable.php | 12 +++++------ .../phpunit/tests/admin/wpUsersListTable.php | 2 +- .../tests/multisite/wpMsThemesListTable.php | 14 ++++++------- 5 files changed, 30 insertions(+), 30 deletions(-) diff --git a/tests/phpunit/tests/admin/wpCommentsListTable.php b/tests/phpunit/tests/admin/wpCommentsListTable.php index a22d1d8097567..2902f22c49979 100644 --- a/tests/phpunit/tests/admin/wpCommentsListTable.php +++ b/tests/phpunit/tests/admin/wpCommentsListTable.php @@ -204,12 +204,12 @@ public function test_get_views_should_return_views_by_default() { $this->table->prepare_items(); $expected = array( - 'all' => 'All (0)', - 'mine' => 'Mine (0)', - 'moderated' => 'Pending (0)', - 'approved' => 'Approved (0)', - 'spam' => 'Spam (0)', - 'trash' => 'Trash (0)', + 'all' => 'All (0)', + 'mine' => 'Mine (0)', + 'moderated' => 'Pending (0)', + 'approved' => 'Approved (0)', + 'spam' => 'Spam (0)', + 'trash' => 'Trash (0)', ); $this->assertSame( $expected, $this->table->get_views() ); } diff --git a/tests/phpunit/tests/admin/wpPluginsListTable.php b/tests/phpunit/tests/admin/wpPluginsListTable.php index 072539d5c2b41..f97059d4754d8 100644 --- a/tests/phpunit/tests/admin/wpPluginsListTable.php +++ b/tests/phpunit/tests/admin/wpPluginsListTable.php @@ -39,16 +39,16 @@ public function test_get_views_should_return_views_by_default() { ); $expected = array( - 'all' => 'All (45)', - 'active' => 'Active (1)', - 'recently_activated' => 'Recently Active (2)', - 'inactive' => 'Inactive (3)', - 'mustuse' => 'Must-Use (4)', - 'dropins' => 'Drop-ins (5)', - 'paused' => 'Paused (6)', - 'upgrade' => 'Update Available (7)', - 'auto-update-enabled' => 'Auto-updates Enabled (8)', - 'auto-update-disabled' => 'Auto-updates Disabled (9)', + 'all' => 'All (45)', + 'active' => 'Active (1)', + 'recently_activated' => 'Recently Active (2)', + 'inactive' => 'Inactive (3)', + 'mustuse' => 'Must-Use (4)', + 'dropins' => 'Drop-ins (5)', + 'paused' => 'Paused (6)', + 'upgrade' => 'Update Available (7)', + 'auto-update-enabled' => 'Auto-updates Enabled (8)', + 'auto-update-disabled' => 'Auto-updates Disabled (9)', ); $actual = $this->table->get_views(); diff --git a/tests/phpunit/tests/admin/wpPostCommentsListTable.php b/tests/phpunit/tests/admin/wpPostCommentsListTable.php index 092d003314d67..7e8dc4cfabb72 100644 --- a/tests/phpunit/tests/admin/wpPostCommentsListTable.php +++ b/tests/phpunit/tests/admin/wpPostCommentsListTable.php @@ -26,12 +26,12 @@ public function test_get_views_should_return_views_by_default() { $this->table->prepare_items(); $expected = array( - 'all' => 'All (0)', - 'mine' => 'Mine (0)', - 'moderated' => 'Pending (0)', - 'approved' => 'Approved (0)', - 'spam' => 'Spam (0)', - 'trash' => 'Trash (0)', + 'all' => 'All (0)', + 'mine' => 'Mine (0)', + 'moderated' => 'Pending (0)', + 'approved' => 'Approved (0)', + 'spam' => 'Spam (0)', + 'trash' => 'Trash (0)', ); $this->assertSame( $expected, $this->table->get_views() ); } diff --git a/tests/phpunit/tests/admin/wpUsersListTable.php b/tests/phpunit/tests/admin/wpUsersListTable.php index 0ff91ba5aa428..bdf765fbfe0fc 100644 --- a/tests/phpunit/tests/admin/wpUsersListTable.php +++ b/tests/phpunit/tests/admin/wpUsersListTable.php @@ -24,7 +24,7 @@ public function set_up() { public function test_get_views_should_return_views_by_default() { $expected = array( 'all' => 'All (1)', - 'administrator' => 'Administrator (1)', + 'administrator' => 'Administrator (1)', ); $this->assertSame( $expected, $this->table->get_views() ); diff --git a/tests/phpunit/tests/multisite/wpMsThemesListTable.php b/tests/phpunit/tests/multisite/wpMsThemesListTable.php index 36d25839341a0..926162cac1467 100644 --- a/tests/phpunit/tests/multisite/wpMsThemesListTable.php +++ b/tests/phpunit/tests/multisite/wpMsThemesListTable.php @@ -109,13 +109,13 @@ public function test_get_views_should_return_views_by_default() { ); $expected = array( - 'all' => 'All (21)', - 'enabled' => 'Enabled (1)', - 'disabled' => 'Disabled (2)', - 'upgrade' => 'Update Available (3)', - 'broken' => 'Broken (4)', - 'auto-update-enabled' => 'Auto-updates Enabled (5)', - 'auto-update-disabled' => 'Auto-updates Disabled (6)', + 'all' => 'All (21)', + 'enabled' => 'Enabled (1)', + 'disabled' => 'Disabled (2)', + 'upgrade' => 'Update Available (3)', + 'broken' => 'Broken (4)', + 'auto-update-enabled' => 'Auto-updates Enabled (5)', + 'auto-update-disabled' => 'Auto-updates Disabled (6)', ); $actual = $this->table->get_views(); From 5945f30c86593d0e1147d76826b3b6325c772370 Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 28 Aug 2022 06:40:08 +0100 Subject: [PATCH 28/31] Tests: Replace `&` with `&` to fix failures. --- tests/phpunit/tests/admin/wpCommentsListTable.php | 2 +- tests/phpunit/tests/admin/wpPostCommentsListTable.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/admin/wpCommentsListTable.php b/tests/phpunit/tests/admin/wpCommentsListTable.php index 2902f22c49979..20fcd836e2cac 100644 --- a/tests/phpunit/tests/admin/wpCommentsListTable.php +++ b/tests/phpunit/tests/admin/wpCommentsListTable.php @@ -205,7 +205,7 @@ public function test_get_views_should_return_views_by_default() { $expected = array( 'all' => 'All (0)', - 'mine' => 'Mine (0)', + 'mine' => 'Mine (0)', 'moderated' => 'Pending (0)', 'approved' => 'Approved (0)', 'spam' => 'Spam (0)', diff --git a/tests/phpunit/tests/admin/wpPostCommentsListTable.php b/tests/phpunit/tests/admin/wpPostCommentsListTable.php index 7e8dc4cfabb72..98cb834bff2d7 100644 --- a/tests/phpunit/tests/admin/wpPostCommentsListTable.php +++ b/tests/phpunit/tests/admin/wpPostCommentsListTable.php @@ -27,7 +27,7 @@ public function test_get_views_should_return_views_by_default() { $expected = array( 'all' => 'All (0)', - 'mine' => 'Mine (0)', + 'mine' => 'Mine (0)', 'moderated' => 'Pending (0)', 'approved' => 'Approved (0)', 'spam' => 'Spam (0)', From be0780b54a7325231e8baea27de462fac6ecb213 Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 28 Aug 2022 07:59:46 +0100 Subject: [PATCH 29/31] Tests: Get actual user counts in test data. This test was previously faulty and used the counts from a local install. This has now been resolved using: - `get_user_count()` for 'all' - `count( get_super_admins() )` for 'super' --- tests/phpunit/tests/multisite/wpMsUsersListTable.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/multisite/wpMsUsersListTable.php b/tests/phpunit/tests/multisite/wpMsUsersListTable.php index 450cd3e8a40e9..f381e67559090 100644 --- a/tests/phpunit/tests/multisite/wpMsUsersListTable.php +++ b/tests/phpunit/tests/multisite/wpMsUsersListTable.php @@ -95,9 +95,12 @@ public static function wpTearDownAfterClass() { * @covers WP_MS_Users_List_Table::get_views */ public function test_get_views_should_return_views_by_default() { + $all = get_user_count(); + $super = count( get_super_admins() ); + $expected = array( - 'all' => 'All (1)', - 'super' => 'Super Admin (1)', + 'all' => 'All (' . $all . ')', + 'super' => 'Super Admin (' . $super . ')', ); $this->assertSame( $expected, $this->table->get_views() ); From 92a05b4a83aeb81644e7b2e0b6eb29a709e76561 Mon Sep 17 00:00:00 2001 From: costdev Date: Sun, 28 Aug 2022 07:33:22 +0100 Subject: [PATCH 30/31] Tests: Fix docblock alignment. --- tests/phpunit/tests/admin/wpListTable.php | 34 +++++++++++------------ 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/tests/phpunit/tests/admin/wpListTable.php b/tests/phpunit/tests/admin/wpListTable.php index 294f2a5ca7d4b..c28113d99f133 100644 --- a/tests/phpunit/tests/admin/wpListTable.php +++ b/tests/phpunit/tests/admin/wpListTable.php @@ -124,23 +124,23 @@ public function data_should_only_add_primary_column_when_needed() { } /** - * Tests the "get_views_links()" method. - * - * @ticket 42066 - * - * @covers WP_List_Table::get_views_links - * - * @dataProvider data_get_views_links - * - * @param array $link_data { - * An array of link data. - * - * @type string $url The link URL. - * @type string $label The link label. - * @type bool $current Optional. Whether this is the currently selected view. - * } - * @param array $expected - */ + * Tests the "get_views_links()" method. + * + * @ticket 42066 + * + * @covers WP_List_Table::get_views_links + * + * @dataProvider data_get_views_links + * + * @param array $link_data { + * An array of link data. + * + * @type string $url The link URL. + * @type string $label The link label. + * @type bool $current Optional. Whether this is the currently selected view. + * } + * @param array $expected + */ public function test_get_views_links( $link_data, $expected ) { $get_views_links = new ReflectionMethod( self::$list_table, 'get_views_links' ); $get_views_links->setAccessible( true ); From d26fdc07e5bcb0311b69b463269f73cb56bb58e8 Mon Sep 17 00:00:00 2001 From: costdev Date: Fri, 9 Sep 2022 09:43:57 +0100 Subject: [PATCH 31/31] Tests: Replace `is_multisite()` with `ms-required` group. --- .../tests/multisite/wpMsThemesListTable.php | 218 +++++++++--------- .../tests/multisite/wpMsUsersListTable.php | 186 ++++++++------- 2 files changed, 200 insertions(+), 204 deletions(-) diff --git a/tests/phpunit/tests/multisite/wpMsThemesListTable.php b/tests/phpunit/tests/multisite/wpMsThemesListTable.php index 926162cac1467..b02df1a740ffc 100644 --- a/tests/phpunit/tests/multisite/wpMsThemesListTable.php +++ b/tests/phpunit/tests/multisite/wpMsThemesListTable.php @@ -1,127 +1,125 @@ table = _get_list_table( 'WP_MS_Themes_List_Table', array( 'screen' => 'ms-themes' ) ); - } + public function set_up() { + parent::set_up(); + $this->table = _get_list_table( 'WP_MS_Themes_List_Table', array( 'screen' => 'ms-themes' ) ); + } - public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { - self::$site_ids = array( - 'wordpress.org/' => array( - 'domain' => 'wordpress.org', - 'path' => '/', - ), - 'wordpress.org/foo/' => array( - 'domain' => 'wordpress.org', - 'path' => '/foo/', - ), - 'wordpress.org/foo/bar/' => array( - 'domain' => 'wordpress.org', - 'path' => '/foo/bar/', - ), - 'wordpress.org/afoo/' => array( - 'domain' => 'wordpress.org', - 'path' => '/afoo/', - ), - 'make.wordpress.org/' => array( - 'domain' => 'make.wordpress.org', - 'path' => '/', - ), - 'make.wordpress.org/foo/' => array( - 'domain' => 'make.wordpress.org', - 'path' => '/foo/', - ), - 'www.w.org/' => array( - 'domain' => 'www.w.org', - 'path' => '/', - ), - 'www.w.org/foo/' => array( - 'domain' => 'www.w.org', - 'path' => '/foo/', - ), - 'www.w.org/foo/bar/' => array( - 'domain' => 'www.w.org', - 'path' => '/foo/bar/', - ), - 'test.example.org/' => array( - 'domain' => 'test.example.org', - 'path' => '/', - ), - 'test2.example.org/' => array( - 'domain' => 'test2.example.org', - 'path' => '/', - ), - 'test3.example.org/zig/' => array( - 'domain' => 'test3.example.org', - 'path' => '/zig/', - ), - 'atest.example.org/' => array( - 'domain' => 'atest.example.org', - 'path' => '/', - ), - ); + public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { + self::$site_ids = array( + 'wordpress.org/' => array( + 'domain' => 'wordpress.org', + 'path' => '/', + ), + 'wordpress.org/foo/' => array( + 'domain' => 'wordpress.org', + 'path' => '/foo/', + ), + 'wordpress.org/foo/bar/' => array( + 'domain' => 'wordpress.org', + 'path' => '/foo/bar/', + ), + 'wordpress.org/afoo/' => array( + 'domain' => 'wordpress.org', + 'path' => '/afoo/', + ), + 'make.wordpress.org/' => array( + 'domain' => 'make.wordpress.org', + 'path' => '/', + ), + 'make.wordpress.org/foo/' => array( + 'domain' => 'make.wordpress.org', + 'path' => '/foo/', + ), + 'www.w.org/' => array( + 'domain' => 'www.w.org', + 'path' => '/', + ), + 'www.w.org/foo/' => array( + 'domain' => 'www.w.org', + 'path' => '/foo/', + ), + 'www.w.org/foo/bar/' => array( + 'domain' => 'www.w.org', + 'path' => '/foo/bar/', + ), + 'test.example.org/' => array( + 'domain' => 'test.example.org', + 'path' => '/', + ), + 'test2.example.org/' => array( + 'domain' => 'test2.example.org', + 'path' => '/', + ), + 'test3.example.org/zig/' => array( + 'domain' => 'test3.example.org', + 'path' => '/zig/', + ), + 'atest.example.org/' => array( + 'domain' => 'atest.example.org', + 'path' => '/', + ), + ); - foreach ( self::$site_ids as &$id ) { - $id = $factory->blog->create( $id ); - } - unset( $id ); + foreach ( self::$site_ids as &$id ) { + $id = $factory->blog->create( $id ); } + unset( $id ); + } - public static function wpTearDownAfterClass() { - foreach ( self::$site_ids as $site_id ) { - wp_delete_site( $site_id ); - } + public static function wpTearDownAfterClass() { + foreach ( self::$site_ids as $site_id ) { + wp_delete_site( $site_id ); } + } - /** - * @ticket 42066 - * - * @covers WP_MS_Themes_List_Table::get_views - */ - public function test_get_views_should_return_views_by_default() { - global $totals; + /** + * @ticket 42066 + * + * @covers WP_MS_Themes_List_Table::get_views + */ + public function test_get_views_should_return_views_by_default() { + global $totals; - $totals_backup = $totals; - $totals = array( - 'all' => 21, - 'enabled' => 1, - 'disabled' => 2, - 'upgrade' => 3, - 'broken' => 4, - 'auto-update-enabled' => 5, - 'auto-update-disabled' => 6, - ); + $totals_backup = $totals; + $totals = array( + 'all' => 21, + 'enabled' => 1, + 'disabled' => 2, + 'upgrade' => 3, + 'broken' => 4, + 'auto-update-enabled' => 5, + 'auto-update-disabled' => 6, + ); - $expected = array( - 'all' => 'All (21)', - 'enabled' => 'Enabled (1)', - 'disabled' => 'Disabled (2)', - 'upgrade' => 'Update Available (3)', - 'broken' => 'Broken (4)', - 'auto-update-enabled' => 'Auto-updates Enabled (5)', - 'auto-update-disabled' => 'Auto-updates Disabled (6)', - ); + $expected = array( + 'all' => 'All (21)', + 'enabled' => 'Enabled (1)', + 'disabled' => 'Disabled (2)', + 'upgrade' => 'Update Available (3)', + 'broken' => 'Broken (4)', + 'auto-update-enabled' => 'Auto-updates Enabled (5)', + 'auto-update-disabled' => 'Auto-updates Disabled (6)', + ); - $actual = $this->table->get_views(); - $totals = $totals_backup; + $actual = $this->table->get_views(); + $totals = $totals_backup; - $this->assertSame( $expected, $actual ); - } + $this->assertSame( $expected, $actual ); } -endif; +} diff --git a/tests/phpunit/tests/multisite/wpMsUsersListTable.php b/tests/phpunit/tests/multisite/wpMsUsersListTable.php index f381e67559090..be17e7ae36470 100644 --- a/tests/phpunit/tests/multisite/wpMsUsersListTable.php +++ b/tests/phpunit/tests/multisite/wpMsUsersListTable.php @@ -1,109 +1,107 @@ table = _get_list_table( 'WP_MS_Users_List_Table', array( 'screen' => 'ms-users' ) ); - } + public function set_up() { + parent::set_up(); + $this->table = _get_list_table( 'WP_MS_Users_List_Table', array( 'screen' => 'ms-users' ) ); + } - public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { - self::$site_ids = array( - 'wordpress.org/' => array( - 'domain' => 'wordpress.org', - 'path' => '/', - ), - 'wordpress.org/foo/' => array( - 'domain' => 'wordpress.org', - 'path' => '/foo/', - ), - 'wordpress.org/foo/bar/' => array( - 'domain' => 'wordpress.org', - 'path' => '/foo/bar/', - ), - 'wordpress.org/afoo/' => array( - 'domain' => 'wordpress.org', - 'path' => '/afoo/', - ), - 'make.wordpress.org/' => array( - 'domain' => 'make.wordpress.org', - 'path' => '/', - ), - 'make.wordpress.org/foo/' => array( - 'domain' => 'make.wordpress.org', - 'path' => '/foo/', - ), - 'www.w.org/' => array( - 'domain' => 'www.w.org', - 'path' => '/', - ), - 'www.w.org/foo/' => array( - 'domain' => 'www.w.org', - 'path' => '/foo/', - ), - 'www.w.org/foo/bar/' => array( - 'domain' => 'www.w.org', - 'path' => '/foo/bar/', - ), - 'test.example.org/' => array( - 'domain' => 'test.example.org', - 'path' => '/', - ), - 'test2.example.org/' => array( - 'domain' => 'test2.example.org', - 'path' => '/', - ), - 'test3.example.org/zig/' => array( - 'domain' => 'test3.example.org', - 'path' => '/zig/', - ), - 'atest.example.org/' => array( - 'domain' => 'atest.example.org', - 'path' => '/', - ), - ); + public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { + self::$site_ids = array( + 'wordpress.org/' => array( + 'domain' => 'wordpress.org', + 'path' => '/', + ), + 'wordpress.org/foo/' => array( + 'domain' => 'wordpress.org', + 'path' => '/foo/', + ), + 'wordpress.org/foo/bar/' => array( + 'domain' => 'wordpress.org', + 'path' => '/foo/bar/', + ), + 'wordpress.org/afoo/' => array( + 'domain' => 'wordpress.org', + 'path' => '/afoo/', + ), + 'make.wordpress.org/' => array( + 'domain' => 'make.wordpress.org', + 'path' => '/', + ), + 'make.wordpress.org/foo/' => array( + 'domain' => 'make.wordpress.org', + 'path' => '/foo/', + ), + 'www.w.org/' => array( + 'domain' => 'www.w.org', + 'path' => '/', + ), + 'www.w.org/foo/' => array( + 'domain' => 'www.w.org', + 'path' => '/foo/', + ), + 'www.w.org/foo/bar/' => array( + 'domain' => 'www.w.org', + 'path' => '/foo/bar/', + ), + 'test.example.org/' => array( + 'domain' => 'test.example.org', + 'path' => '/', + ), + 'test2.example.org/' => array( + 'domain' => 'test2.example.org', + 'path' => '/', + ), + 'test3.example.org/zig/' => array( + 'domain' => 'test3.example.org', + 'path' => '/zig/', + ), + 'atest.example.org/' => array( + 'domain' => 'atest.example.org', + 'path' => '/', + ), + ); - foreach ( self::$site_ids as &$id ) { - $id = $factory->blog->create( $id ); - } - unset( $id ); + foreach ( self::$site_ids as &$id ) { + $id = $factory->blog->create( $id ); } + unset( $id ); + } - public static function wpTearDownAfterClass() { - foreach ( self::$site_ids as $site_id ) { - wp_delete_site( $site_id ); - } + public static function wpTearDownAfterClass() { + foreach ( self::$site_ids as $site_id ) { + wp_delete_site( $site_id ); } + } - /** - * @ticket 42066 - * - * @covers WP_MS_Users_List_Table::get_views - */ - public function test_get_views_should_return_views_by_default() { - $all = get_user_count(); - $super = count( get_super_admins() ); + /** + * @ticket 42066 + * + * @covers WP_MS_Users_List_Table::get_views + */ + public function test_get_views_should_return_views_by_default() { + $all = get_user_count(); + $super = count( get_super_admins() ); - $expected = array( - 'all' => 'All (' . $all . ')', - 'super' => 'Super Admin (' . $super . ')', - ); + $expected = array( + 'all' => 'All (' . $all . ')', + 'super' => 'Super Admin (' . $super . ')', + ); - $this->assertSame( $expected, $this->table->get_views() ); - } + $this->assertSame( $expected, $this->table->get_views() ); } -endif; +}