- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/multisite/wpMSSitesListTable.php
r39481 r42343 3 3 if ( is_multisite() ) : 4 4 5 /**6 * @group admin7 * @group network-admin8 */9 class Tests_WP_MS_Sites_List_Table extends WP_UnitTestCase {10 protected static $site_ids;11 12 5 /** 13 * @var WP_MS_Sites_List_Table 6 * @group admin 7 * @group network-admin 14 8 */ 15 var $table = false; 16 17 function setUp() { 18 parent::setUp(); 19 $this->table = _get_list_table( 'WP_MS_Sites_List_Table', array( 'screen' => 'ms-sites' ) ); 9 class Tests_WP_MS_Sites_List_Table extends WP_UnitTestCase { 10 protected static $site_ids; 11 12 /** 13 * @var WP_MS_Sites_List_Table 14 */ 15 var $table = false; 16 17 function setUp() { 18 parent::setUp(); 19 $this->table = _get_list_table( 'WP_MS_Sites_List_Table', array( 'screen' => 'ms-sites' ) ); 20 } 21 22 public static function wpSetUpBeforeClass( $factory ) { 23 self::$site_ids = array( 24 'wordpress.org/' => array( 25 'domain' => 'wordpress.org', 26 'path' => '/', 27 ), 28 'wordpress.org/foo/' => array( 29 'domain' => 'wordpress.org', 30 'path' => '/foo/', 31 ), 32 'wordpress.org/foo/bar/' => array( 33 'domain' => 'wordpress.org', 34 'path' => '/foo/bar/', 35 ), 36 'wordpress.org/afoo/' => array( 37 'domain' => 'wordpress.org', 38 'path' => '/afoo/', 39 ), 40 'make.wordpress.org/' => array( 41 'domain' => 'make.wordpress.org', 42 'path' => '/', 43 ), 44 'make.wordpress.org/foo/' => array( 45 'domain' => 'make.wordpress.org', 46 'path' => '/foo/', 47 ), 48 'www.w.org/' => array( 49 'domain' => 'www.w.org', 50 'path' => '/', 51 ), 52 'www.w.org/foo/' => array( 53 'domain' => 'www.w.org', 54 'path' => '/foo/', 55 ), 56 'www.w.org/foo/bar/' => array( 57 'domain' => 'www.w.org', 58 'path' => '/foo/bar/', 59 ), 60 'test.example.org/' => array( 61 'domain' => 'test.example.org', 62 'path' => '/', 63 ), 64 'test2.example.org/' => array( 65 'domain' => 'test2.example.org', 66 'path' => '/', 67 ), 68 'test3.example.org/zig/' => array( 69 'domain' => 'test3.example.org', 70 'path' => '/zig/', 71 ), 72 'atest.example.org/' => array( 73 'domain' => 'atest.example.org', 74 'path' => '/', 75 ), 76 ); 77 78 foreach ( self::$site_ids as &$id ) { 79 $id = $factory->blog->create( $id ); 80 } 81 unset( $id ); 82 } 83 84 public static function wpTearDownAfterClass() { 85 foreach ( self::$site_ids as $site_id ) { 86 wpmu_delete_blog( $site_id, true ); 87 } 88 } 89 90 public function test_ms_sites_list_table_default_items() { 91 $this->table->prepare_items(); 92 93 $items = wp_list_pluck( $this->table->items, 'blog_id' ); 94 $items = array_map( 'intval', $items ); 95 96 $this->assertEqualSets( array( 1 ) + self::$site_ids, $items ); 97 } 98 99 public function test_ms_sites_list_table_subdirectory_path_search_items() { 100 if ( is_subdomain_install() ) { 101 $this->markTestSkipped( 'Path search is not available for subdomain configurations.' ); 102 } 103 104 $_REQUEST['s'] = 'foo'; 105 106 $this->table->prepare_items(); 107 108 $items = wp_list_pluck( $this->table->items, 'blog_id' ); 109 $items = array_map( 'intval', $items ); 110 111 unset( $_REQUEST['s'] ); 112 113 $expected = array( 114 self::$site_ids['wordpress.org/foo/'], 115 self::$site_ids['wordpress.org/foo/bar/'], 116 self::$site_ids['wordpress.org/afoo/'], 117 self::$site_ids['make.wordpress.org/foo/'], 118 self::$site_ids['www.w.org/foo/'], 119 self::$site_ids['www.w.org/foo/bar/'], 120 ); 121 122 $this->assertEqualSets( $expected, $items ); 123 } 124 125 public function test_ms_sites_list_table_subdirectory_multiple_path_search_items() { 126 if ( is_subdomain_install() ) { 127 $this->markTestSkipped( 'Path search is not available for subdomain configurations.' ); 128 } 129 130 $_REQUEST['s'] = 'foo/bar'; 131 132 $this->table->prepare_items(); 133 134 $items = wp_list_pluck( $this->table->items, 'blog_id' ); 135 $items = array_map( 'intval', $items ); 136 137 unset( $_REQUEST['s'] ); 138 139 $expected = array( 140 self::$site_ids['wordpress.org/foo/bar/'], 141 self::$site_ids['www.w.org/foo/bar/'], 142 ); 143 144 $this->assertEqualSets( $expected, $items ); 145 } 146 147 public function test_ms_sites_list_table_invalid_path_search_items() { 148 $_REQUEST['s'] = 'foobar'; 149 150 $this->table->prepare_items(); 151 152 $items = wp_list_pluck( $this->table->items, 'blog_id' ); 153 $items = array_map( 'intval', $items ); 154 155 unset( $_REQUEST['s'] ); 156 157 $this->assertEmpty( $items ); 158 } 159 160 public function test_ms_sites_list_table_subdomain_domain_search_items() { 161 if ( ! is_subdomain_install() ) { 162 $this->markTestSkipped( 'Domain search is not available for subdirectory configurations.' ); 163 } 164 165 $_REQUEST['s'] = 'test'; 166 167 $this->table->prepare_items(); 168 169 $items = wp_list_pluck( $this->table->items, 'blog_id' ); 170 $items = array_map( 'intval', $items ); 171 172 unset( $_REQUEST['s'] ); 173 174 $expected = array( 175 self::$site_ids['test.example.org/'], 176 self::$site_ids['test2.example.org/'], 177 self::$site_ids['test3.example.org/zig/'], 178 self::$site_ids['atest.example.org/'], 179 ); 180 181 $this->assertEqualSets( $expected, $items ); 182 } 183 184 public function test_ms_sites_list_table_subdomain_domain_search_items_with_trailing_wildcard() { 185 if ( ! is_subdomain_install() ) { 186 $this->markTestSkipped( 'Domain search is not available for subdirectory configurations.' ); 187 } 188 189 $_REQUEST['s'] = 'test*'; 190 191 $this->table->prepare_items(); 192 193 $items = wp_list_pluck( $this->table->items, 'blog_id' ); 194 $items = array_map( 'intval', $items ); 195 196 unset( $_REQUEST['s'] ); 197 198 $expected = array( 199 self::$site_ids['test.example.org/'], 200 self::$site_ids['test2.example.org/'], 201 self::$site_ids['test3.example.org/zig/'], 202 self::$site_ids['atest.example.org/'], 203 ); 204 205 $this->assertEqualSets( $expected, $items ); 206 } 207 208 public function test_ms_sites_list_table_subdirectory_path_search_items_with_trailing_wildcard() { 209 if ( is_subdomain_install() ) { 210 $this->markTestSkipped( 'Path search is not available for subdomain configurations.' ); 211 } 212 213 $_REQUEST['s'] = 'fo*'; 214 215 $this->table->prepare_items(); 216 217 $items = wp_list_pluck( $this->table->items, 'blog_id' ); 218 $items = array_map( 'intval', $items ); 219 220 unset( $_REQUEST['s'] ); 221 222 $expected = array( 223 self::$site_ids['wordpress.org/foo/'], 224 self::$site_ids['wordpress.org/foo/bar/'], 225 self::$site_ids['wordpress.org/afoo/'], 226 self::$site_ids['make.wordpress.org/foo/'], 227 self::$site_ids['www.w.org/foo/'], 228 self::$site_ids['www.w.org/foo/bar/'], 229 ); 230 231 $this->assertEqualSets( $expected, $items ); 232 } 20 233 } 21 22 public static function wpSetUpBeforeClass( $factory ) {23 self::$site_ids = array(24 'wordpress.org/' => array( 'domain' => 'wordpress.org', 'path' => '/' ),25 'wordpress.org/foo/' => array( 'domain' => 'wordpress.org', 'path' => '/foo/' ),26 'wordpress.org/foo/bar/' => array( 'domain' => 'wordpress.org', 'path' => '/foo/bar/' ),27 'wordpress.org/afoo/' => array( 'domain' => 'wordpress.org', 'path' => '/afoo/' ),28 'make.wordpress.org/' => array( 'domain' => 'make.wordpress.org', 'path' => '/' ),29 'make.wordpress.org/foo/' => array( 'domain' => 'make.wordpress.org', 'path' => '/foo/' ),30 'www.w.org/' => array( 'domain' => 'www.w.org', 'path' => '/' ),31 'www.w.org/foo/' => array( 'domain' => 'www.w.org', 'path' => '/foo/' ),32 'www.w.org/foo/bar/' => array( 'domain' => 'www.w.org', 'path' => '/foo/bar/' ),33 'test.example.org/' => array( 'domain' => 'test.example.org', 'path' => '/' ),34 'test2.example.org/' => array( 'domain' => 'test2.example.org', 'path' => '/' ),35 'test3.example.org/zig/' => array( 'domain' => 'test3.example.org', 'path' => '/zig/' ),36 'atest.example.org/' => array( 'domain' => 'atest.example.org', 'path' => '/' ),37 );38 39 foreach ( self::$site_ids as &$id ) {40 $id = $factory->blog->create( $id );41 }42 unset( $id );43 }44 45 public static function wpTearDownAfterClass() {46 foreach ( self::$site_ids as $site_id ) {47 wpmu_delete_blog( $site_id, true );48 }49 }50 51 public function test_ms_sites_list_table_default_items() {52 $this->table->prepare_items();53 54 $items = wp_list_pluck( $this->table->items, 'blog_id' );55 $items = array_map( 'intval', $items );56 57 $this->assertEqualSets( array( 1 ) + self::$site_ids, $items );58 }59 60 public function test_ms_sites_list_table_subdirectory_path_search_items() {61 if ( is_subdomain_install() ) {62 $this->markTestSkipped( 'Path search is not available for subdomain configurations.' );63 }64 65 $_REQUEST['s'] = 'foo';66 67 $this->table->prepare_items();68 69 $items = wp_list_pluck( $this->table->items, 'blog_id' );70 $items = array_map( 'intval', $items );71 72 unset( $_REQUEST['s'] );73 74 $expected = array(75 self::$site_ids['wordpress.org/foo/'],76 self::$site_ids['wordpress.org/foo/bar/'],77 self::$site_ids['wordpress.org/afoo/'],78 self::$site_ids['make.wordpress.org/foo/'],79 self::$site_ids['www.w.org/foo/'],80 self::$site_ids['www.w.org/foo/bar/'],81 );82 83 $this->assertEqualSets( $expected, $items );84 }85 86 public function test_ms_sites_list_table_subdirectory_multiple_path_search_items() {87 if ( is_subdomain_install() ) {88 $this->markTestSkipped( 'Path search is not available for subdomain configurations.' );89 }90 91 $_REQUEST['s'] = 'foo/bar';92 93 $this->table->prepare_items();94 95 $items = wp_list_pluck( $this->table->items, 'blog_id' );96 $items = array_map( 'intval', $items );97 98 unset( $_REQUEST['s'] );99 100 $expected = array(101 self::$site_ids['wordpress.org/foo/bar/'],102 self::$site_ids['www.w.org/foo/bar/'],103 );104 105 $this->assertEqualSets( $expected, $items );106 }107 108 public function test_ms_sites_list_table_invalid_path_search_items() {109 $_REQUEST['s'] = 'foobar';110 111 $this->table->prepare_items();112 113 $items = wp_list_pluck( $this->table->items, 'blog_id' );114 $items = array_map( 'intval', $items );115 116 unset( $_REQUEST['s'] );117 118 $this->assertEmpty( $items );119 }120 121 public function test_ms_sites_list_table_subdomain_domain_search_items() {122 if ( ! is_subdomain_install() ) {123 $this->markTestSkipped( 'Domain search is not available for subdirectory configurations.' );124 }125 126 $_REQUEST['s'] = 'test';127 128 $this->table->prepare_items();129 130 $items = wp_list_pluck( $this->table->items, 'blog_id' );131 $items = array_map( 'intval', $items );132 133 unset( $_REQUEST['s'] );134 135 $expected = array(136 self::$site_ids['test.example.org/'],137 self::$site_ids['test2.example.org/'],138 self::$site_ids['test3.example.org/zig/'],139 self::$site_ids['atest.example.org/'],140 );141 142 $this->assertEqualSets( $expected, $items );143 }144 145 public function test_ms_sites_list_table_subdomain_domain_search_items_with_trailing_wildcard() {146 if ( ! is_subdomain_install() ) {147 $this->markTestSkipped( 'Domain search is not available for subdirectory configurations.' );148 }149 150 $_REQUEST['s'] = 'test*';151 152 $this->table->prepare_items();153 154 $items = wp_list_pluck( $this->table->items, 'blog_id' );155 $items = array_map( 'intval', $items );156 157 unset( $_REQUEST['s'] );158 159 $expected = array(160 self::$site_ids['test.example.org/'],161 self::$site_ids['test2.example.org/'],162 self::$site_ids['test3.example.org/zig/'],163 self::$site_ids['atest.example.org/'],164 );165 166 $this->assertEqualSets( $expected, $items );167 }168 169 public function test_ms_sites_list_table_subdirectory_path_search_items_with_trailing_wildcard() {170 if ( is_subdomain_install() ) {171 $this->markTestSkipped( 'Path search is not available for subdomain configurations.' );172 }173 174 $_REQUEST['s'] = 'fo*';175 176 $this->table->prepare_items();177 178 $items = wp_list_pluck( $this->table->items, 'blog_id' );179 $items = array_map( 'intval', $items );180 181 unset( $_REQUEST['s'] );182 183 $expected = array(184 self::$site_ids['wordpress.org/foo/'],185 self::$site_ids['wordpress.org/foo/bar/'],186 self::$site_ids['wordpress.org/afoo/'],187 self::$site_ids['make.wordpress.org/foo/'],188 self::$site_ids['www.w.org/foo/'],189 self::$site_ids['www.w.org/foo/bar/'],190 );191 192 $this->assertEqualSets( $expected, $items );193 }194 }195 234 endif;
Note: See TracChangeset
for help on using the changeset viewer.