WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/23/2019 05:34:20 PM (8 weeks ago)
Author:
johnjamesjacoby
Message:

Multisite/Sites: Add links to filter websites by status.

This commit brings the Network-Admin Sites list page up-to-speed with other similar list-table powered pages, by adding links to filter the results by Site Status.

Includes a single unit test for the newly introduced wp_count_sites() multisite function, named to match the wp_count_ function pattern from other list tables.

Fixes #37392. Props mnelson4, spacedmonkey, pbiron.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/multisite.php

    r45607 r46251  
    3535            $this->assertEquals( $user->user_email, $reg_blog[ count( $reg_blog ) - 1 ] );
    3636        }
     37
     38        /**
     39         * @ticket 37392
     40         */
     41        function test_wp_count_sites() {
     42            // create a random number of sites with each status.
     43            $site_ids = array(
     44                'public'   => self::factory()->blog->create_many(
     45                    random_int( 0, 5 ),
     46                    array( 'meta' => array( 'public' => 1 ) )
     47                ),
     48                'archived' => self::factory()->blog->create_many(
     49                    random_int( 0, 5 ),
     50                    array( 'meta' => array( 'archived' => 1 ) )
     51                ),
     52                'mature'   => self::factory()->blog->create_many(
     53                    random_int( 0, 5 ),
     54                    array( 'meta' => array( 'mature' => 1 ) )
     55                ),
     56                'spam'     => self::factory()->blog->create_many(
     57                    random_int( 0, 5 ),
     58                    array( 'meta' => array( 'spam' => 1 ) )
     59                ),
     60                'deleted'  => self::factory()->blog->create_many(
     61                    random_int( 0, 5 ),
     62                    array( 'meta' => array( 'deleted' => 1 ) )
     63                ),
     64            );
     65
     66            $counts = wp_count_sites();
     67
     68            $counts_by_status = array_map( 'count', $site_ids );
     69            $expected        = array_merge(
     70                array( 'all' => array_sum( $counts_by_status ) ),
     71                $counts_by_status
     72            );
     73            // add 1 to all & public for the main site.
     74            $expected['all']    += 1;
     75            $expected['public'] += 1;
     76
     77            $this->assertEquals( $expected, $counts );
     78        }
    3779    }
    3880
Note: See TracChangeset for help on using the changeset viewer.