mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
Many `WP_List_Table` child classes in core use mostly the same code to create their "view" links markup. To DRY-up the code, a new `WP_List_Table->get_view_links` method is being introduced to consolidate the HTML link generation when provided an array of links. This change also implements this new method in the relevant `WP_List_Table_xxx` child classes `get_views` methods. Finally, unit tests are being added to validate view links markup and test for some "unhappy paths". Props afercia, costdev, garrett-eclipse, Dharm1025, juhise, peterwilsoncc. Fixes #42066. git-svn-id: https://develop.svn.wordpress.org/trunk@54215 602fd350-edb4-49c9-b593-d223f7449a82
108 lines
2.7 KiB
PHP
108 lines
2.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group admin
|
|
* @group network-admin
|
|
* @group ms-required
|
|
*
|
|
* @covers WP_MS_Users_List_Table
|
|
*/
|
|
class Tests_Multisite_wpMsUsersListTable extends WP_UnitTestCase {
|
|
protected static $site_ids;
|
|
|
|
/**
|
|
* @var WP_MS_Users_List_Table
|
|
*/
|
|
public $table = false;
|
|
|
|
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' => '/',
|
|
),
|
|
);
|
|
|
|
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() {
|
|
$all = get_user_count();
|
|
$super = count( get_super_admins() );
|
|
|
|
$expected = array(
|
|
'all' => '<a href="http://example.org/wp-admin/network/users.php" class="current" aria-current="page">All <span class="count">(' . $all . ')</span></a>',
|
|
'super' => '<a href="http://example.org/wp-admin/network/users.php?role=super">Super Admin <span class="count">(' . $super . ')</span></a>',
|
|
);
|
|
|
|
$this->assertSame( $expected, $this->table->get_views() );
|
|
}
|
|
}
|