- Timestamp:
- 03/26/2021 08:02:01 PM (4 years ago)
- Location:
- branches/5.2
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/5.2
-
branches/5.2/tests/phpunit/tests/admin/includesPlugin.php
r42343 r50606 5 5 */ 6 6 class Tests_Admin_includesPlugin extends WP_UnitTestCase { 7 public static function wpSetUpBeforeClass( $factory ) { 8 self::_back_up_mu_plugins(); 9 } 10 11 public static function wpTearDownAfterClass() { 12 self::_restore_mu_plugins(); 13 } 14 7 15 function test_get_plugin_data() { 8 16 $data = get_plugin_data( DIR_TESTDATA . '/plugins/hello.php' ); … … 111 119 'list_files_test_plugin/subdir/subfile.php', 112 120 ); 113 $this->assertEquals( $expected, $plugin_files );114 121 115 122 unlink( $sub_dir . '/subfile.php' ); … … 117 124 rmdir( $sub_dir ); 118 125 rmdir( $plugin_dir ); 126 127 $this->assertSame( $expected, $plugin_files ); 119 128 } 120 129 … … 123 132 */ 124 133 public function test_get_mu_plugins_when_mu_plugins_exists_but_is_empty() { 125 if ( is_dir( WPMU_PLUGIN_DIR ) ) { 126 $exists = true; 127 $this->_back_up_mu_plugins(); 128 } else { 129 $exists = false; 130 mkdir( WPMU_PLUGIN_DIR ); 131 } 132 133 $this->assertEquals( array(), get_mu_plugins() ); 134 135 // Clean up. 136 if ( $exists ) { 137 $this->_restore_mu_plugins(); 138 } else { 139 rmdir( WPMU_PLUGIN_DIR ); 140 } 134 mkdir( WPMU_PLUGIN_DIR ); 135 136 $mu_plugins = get_mu_plugins(); 137 138 rmdir( WPMU_PLUGIN_DIR ); 139 140 $this->assertSame( array(), $mu_plugins ); 141 141 } 142 142 … … 145 145 */ 146 146 public function test_get_mu_plugins_when_mu_plugins_directory_does_not_exist() { 147 $exists = false; 148 if ( is_dir( WPMU_PLUGIN_DIR ) ) { 149 $exists = true; 150 $this->_back_up_mu_plugins(); 151 rmdir( WPMU_PLUGIN_DIR ); 152 } 153 154 $this->assertEquals( array(), get_mu_plugins() ); 155 156 // Clean up. 157 if ( $exists ) { 158 mkdir( WPMU_PLUGIN_DIR ); 159 $this->_restore_mu_plugins(); 160 } 147 $this->assertFileNotExists( WPMU_PLUGIN_DIR ); 148 $this->assertSame( array(), get_mu_plugins() ); 161 149 } 162 150 … … 165 153 */ 166 154 public function test_get_mu_plugins_should_ignore_index_php_containing_silence_is_golden() { 167 if ( is_dir( WPMU_PLUGIN_DIR ) ) { 168 $exists = true; 169 $this->_back_up_mu_plugins(); 170 } else { 171 $exists = false; 172 mkdir( WPMU_PLUGIN_DIR ); 173 } 155 mkdir( WPMU_PLUGIN_DIR ); 174 156 175 157 $this->_create_plugin( '<?php\n//Silence is golden.', 'index.php', WPMU_PLUGIN_DIR ); 176 $this->assertEquals( array(), get_mu_plugins() ); 158 159 $mu_plugins = get_mu_plugins(); 160 161 unlink( WPMU_PLUGIN_DIR . '/index.php' ); 162 rmdir( WPMU_PLUGIN_DIR ); 163 164 $this->assertSame( array(), $mu_plugins ); 165 } 166 167 /** 168 * @covers ::get_mu_plugins 169 */ 170 public function test_get_mu_plugins_should_not_ignore_index_php_containing_something_other_than_silence_is_golden() { 171 mkdir( WPMU_PLUGIN_DIR ); 172 173 $this->_create_plugin( '<?php\n//Silence is not golden.', 'index.php', WPMU_PLUGIN_DIR ); 174 $found = get_mu_plugins(); 177 175 178 176 // Clean up. 179 177 unlink( WPMU_PLUGIN_DIR . '/index.php' ); 180 if ( $exists ) { 181 $this->_restore_mu_plugins(); 182 } else { 183 rmdir( WPMU_PLUGIN_DIR ); 184 } 178 rmdir( WPMU_PLUGIN_DIR ); 179 180 $this->assertSame( array( 'index.php' ), array_keys( $found ) ); 185 181 } 186 182 … … 188 184 * @covers ::get_mu_plugins 189 185 */ 190 public function test_get_mu_plugins_should_not_ignore_index_php_containing_something_other_than_silence_is_golden() {191 if ( is_dir( WPMU_PLUGIN_DIR ) ) {192 $exists = true;193 $this->_back_up_mu_plugins();194 } else {195 $exists = false;196 mkdir( WPMU_PLUGIN_DIR );197 }198 199 $this->_create_plugin( '<?php\n//Silence is not golden.', 'index.php', WPMU_PLUGIN_DIR );200 $found = get_mu_plugins();201 $this->assertEquals( array( 'index.php' ), array_keys( $found ) );202 203 // Clean up.204 unlink( WPMU_PLUGIN_DIR . '/index.php' );205 if ( $exists ) {206 $this->_restore_mu_plugins();207 } else {208 rmdir( WPMU_PLUGIN_DIR );209 }210 }211 212 /**213 * @covers ::get_mu_plugins214 */215 186 public function test_get_mu_plugins_should_ignore_files_without_php_extensions() { 216 if ( is_dir( WPMU_PLUGIN_DIR ) ) { 217 $exists = true; 218 $this->_back_up_mu_plugins(); 219 } else { 220 $exists = false; 221 mkdir( WPMU_PLUGIN_DIR ); 222 } 187 mkdir( WPMU_PLUGIN_DIR ); 223 188 224 189 $this->_create_plugin( '<?php\n//Test', 'foo.php', WPMU_PLUGIN_DIR ); 225 190 $this->_create_plugin( '<?php\n//Test 2', 'bar.txt', WPMU_PLUGIN_DIR ); 226 191 $found = get_mu_plugins(); 227 $this->assertEquals( array( 'foo.php' ), array_keys( $found ) );228 192 229 193 // Clean up. 230 194 unlink( WPMU_PLUGIN_DIR . '/foo.php' ); 231 195 unlink( WPMU_PLUGIN_DIR . '/bar.txt' ); 232 if ( $exists ) { 233 $this->_restore_mu_plugins(); 234 } else { 235 rmdir( WPMU_PLUGIN_DIR ); 236 } 196 197 $this->assertSame( array( 'foo.php' ), array_keys( $found ) ); 237 198 } 238 199 … … 393 354 394 355 /** 395 * Move existing mu-plugins to wp-content/mu-plugin /backup.356 * Move existing mu-plugins to wp-content/mu-plugin-backup. 396 357 * 397 358 * @since 4.2.0 … … 399 360 * @access private 400 361 */ 401 private function _back_up_mu_plugins() {362 private static function _back_up_mu_plugins() { 402 363 if ( is_dir( WPMU_PLUGIN_DIR ) ) { 403 364 $mu_bu_dir = WP_CONTENT_DIR . '/mu-plugin-backup'; 404 if ( ! is_dir( $mu_bu_dir ) ) { 405 mkdir( $mu_bu_dir ); 406 } 407 408 $files_to_move = array(); 409 if ( $mu_plugins = opendir( WPMU_PLUGIN_DIR ) ) { 410 while ( false !== $plugin = readdir( $mu_plugins ) ) { 411 if ( 0 !== strpos( $plugin, '.' ) ) { 412 $files_to_move[] = $plugin; 413 } 414 } 415 } 416 417 @closedir( $mu_plugins ); 418 419 foreach ( $files_to_move as $file_to_move ) { 420 $f = rename( WPMU_PLUGIN_DIR . '/' . $file_to_move, $mu_bu_dir . '/' . $file_to_move ); 421 } 365 rename( WPMU_PLUGIN_DIR, $mu_bu_dir ); 422 366 } 423 367 } … … 430 374 * @access private 431 375 */ 432 private function _restore_mu_plugins() { 433 $mu_bu_dir = WP_CONTENT_DIR . '/mu-plugin-backup'; 434 $files_to_move = array(); 435 if ( is_dir( $mu_bu_dir ) && $mu_plugins = opendir( $mu_bu_dir ) ) { 436 while ( false !== $plugin = readdir( $mu_plugins ) ) { 437 if ( 0 !== strpos( $plugin, '.' ) ) { 438 $files_to_move[] = $plugin; 439 } 440 } 441 } 442 443 @closedir( $mu_plugins ); 444 445 foreach ( $files_to_move as $file_to_move ) { 446 rename( $mu_bu_dir . '/' . $file_to_move, WPMU_PLUGIN_DIR . '/' . $file_to_move ); 376 private static function _restore_mu_plugins() { 377 $mu_bu_dir = WP_CONTENT_DIR . '/mu-plugin-backup'; 378 379 if ( is_dir( WPMU_PLUGIN_DIR ) ) { 380 rmdir( WPMU_PLUGIN_DIR ); 447 381 } 448 382 449 383 if ( is_dir( $mu_bu_dir ) ) { 450 r mdir( $mu_bu_dir);384 rename( $mu_bu_dir, WPMU_PLUGIN_DIR ); 451 385 } 452 386 }
Note: See TracChangeset
for help on using the changeset viewer.