- Timestamp:
- 03/26/2021 07:22:10 PM (4 years ago)
- Location:
- branches/5.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/5.3
-
branches/5.3/tests/phpunit/tests/admin/includesPlugin.php
r46869 r50605 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' ); … … 374 382 'list_files_test_plugin/subdir/subfile.php', 375 383 ); 376 $this->assertEquals( $expected, $plugin_files );377 384 378 385 unlink( $sub_dir . '/subfile.php' ); … … 380 387 rmdir( $sub_dir ); 381 388 rmdir( $plugin_dir ); 389 390 $this->assertSame( $expected, $plugin_files ); 382 391 } 383 392 … … 386 395 */ 387 396 public function test_get_mu_plugins_when_mu_plugins_exists_but_is_empty() { 388 if ( is_dir( WPMU_PLUGIN_DIR ) ) { 389 $exists = true; 390 $this->_back_up_mu_plugins(); 391 } else { 392 $exists = false; 393 mkdir( WPMU_PLUGIN_DIR ); 394 } 395 396 $this->assertEquals( array(), get_mu_plugins() ); 397 398 // Clean up. 399 if ( $exists ) { 400 $this->_restore_mu_plugins(); 401 } else { 402 rmdir( WPMU_PLUGIN_DIR ); 403 } 397 mkdir( WPMU_PLUGIN_DIR ); 398 399 $mu_plugins = get_mu_plugins(); 400 401 rmdir( WPMU_PLUGIN_DIR ); 402 403 $this->assertSame( array(), $mu_plugins ); 404 404 } 405 405 … … 408 408 */ 409 409 public function test_get_mu_plugins_when_mu_plugins_directory_does_not_exist() { 410 $exists = false; 411 if ( is_dir( WPMU_PLUGIN_DIR ) ) { 412 $exists = true; 413 $this->_back_up_mu_plugins(); 414 rmdir( WPMU_PLUGIN_DIR ); 415 } 416 417 $this->assertEquals( array(), get_mu_plugins() ); 418 419 // Clean up. 420 if ( $exists ) { 421 mkdir( WPMU_PLUGIN_DIR ); 422 $this->_restore_mu_plugins(); 423 } 410 $this->assertFileNotExists( WPMU_PLUGIN_DIR ); 411 $this->assertSame( array(), get_mu_plugins() ); 424 412 } 425 413 … … 428 416 */ 429 417 public function test_get_mu_plugins_should_ignore_index_php_containing_silence_is_golden() { 430 if ( is_dir( WPMU_PLUGIN_DIR ) ) { 431 $exists = true; 432 $this->_back_up_mu_plugins(); 433 } else { 434 $exists = false; 435 mkdir( WPMU_PLUGIN_DIR ); 436 } 418 mkdir( WPMU_PLUGIN_DIR ); 437 419 438 420 $this->_create_plugin( '<?php\n//Silence is golden.', 'index.php', WPMU_PLUGIN_DIR ); 439 $this->assertEquals( array(), get_mu_plugins() ); 421 422 $mu_plugins = get_mu_plugins(); 423 424 unlink( WPMU_PLUGIN_DIR . '/index.php' ); 425 rmdir( WPMU_PLUGIN_DIR ); 426 427 $this->assertSame( array(), $mu_plugins ); 428 } 429 430 /** 431 * @covers ::get_mu_plugins 432 */ 433 public function test_get_mu_plugins_should_not_ignore_index_php_containing_something_other_than_silence_is_golden() { 434 mkdir( WPMU_PLUGIN_DIR ); 435 436 $this->_create_plugin( '<?php\n//Silence is not golden.', 'index.php', WPMU_PLUGIN_DIR ); 437 $found = get_mu_plugins(); 440 438 441 439 // Clean up. 442 440 unlink( WPMU_PLUGIN_DIR . '/index.php' ); 443 if ( $exists ) { 444 $this->_restore_mu_plugins(); 445 } else { 446 rmdir( WPMU_PLUGIN_DIR ); 447 } 441 rmdir( WPMU_PLUGIN_DIR ); 442 443 $this->assertSame( array( 'index.php' ), array_keys( $found ) ); 448 444 } 449 445 … … 451 447 * @covers ::get_mu_plugins 452 448 */ 453 public function test_get_mu_plugins_should_not_ignore_index_php_containing_something_other_than_silence_is_golden() {454 if ( is_dir( WPMU_PLUGIN_DIR ) ) {455 $exists = true;456 $this->_back_up_mu_plugins();457 } else {458 $exists = false;459 mkdir( WPMU_PLUGIN_DIR );460 }461 462 $this->_create_plugin( '<?php\n//Silence is not golden.', 'index.php', WPMU_PLUGIN_DIR );463 $found = get_mu_plugins();464 $this->assertEquals( array( 'index.php' ), array_keys( $found ) );465 466 // Clean up.467 unlink( WPMU_PLUGIN_DIR . '/index.php' );468 if ( $exists ) {469 $this->_restore_mu_plugins();470 } else {471 rmdir( WPMU_PLUGIN_DIR );472 }473 }474 475 /**476 * @covers ::get_mu_plugins477 */478 449 public function test_get_mu_plugins_should_ignore_files_without_php_extensions() { 479 if ( is_dir( WPMU_PLUGIN_DIR ) ) { 480 $exists = true; 481 $this->_back_up_mu_plugins(); 482 } else { 483 $exists = false; 484 mkdir( WPMU_PLUGIN_DIR ); 485 } 450 mkdir( WPMU_PLUGIN_DIR ); 486 451 487 452 $this->_create_plugin( '<?php\n//Test', 'foo.php', WPMU_PLUGIN_DIR ); 488 453 $this->_create_plugin( '<?php\n//Test 2', 'bar.txt', WPMU_PLUGIN_DIR ); 489 454 $found = get_mu_plugins(); 490 $this->assertEquals( array( 'foo.php' ), array_keys( $found ) );491 455 492 456 // Clean up. 493 457 unlink( WPMU_PLUGIN_DIR . '/foo.php' ); 494 458 unlink( WPMU_PLUGIN_DIR . '/bar.txt' ); 495 if ( $exists ) { 496 $this->_restore_mu_plugins(); 497 } else { 498 rmdir( WPMU_PLUGIN_DIR ); 499 } 459 460 $this->assertSame( array( 'foo.php' ), array_keys( $found ) ); 500 461 } 501 462 … … 656 617 657 618 /** 658 * Move existing mu-plugins to wp-content/mu-plugin /backup.619 * Move existing mu-plugins to wp-content/mu-plugin-backup. 659 620 * 660 621 * @since 4.2.0 … … 662 623 * @access private 663 624 */ 664 private function _back_up_mu_plugins() {625 private static function _back_up_mu_plugins() { 665 626 if ( is_dir( WPMU_PLUGIN_DIR ) ) { 666 627 $mu_bu_dir = WP_CONTENT_DIR . '/mu-plugin-backup'; 667 if ( ! is_dir( $mu_bu_dir ) ) { 668 mkdir( $mu_bu_dir ); 669 } 670 671 $files_to_move = array(); 672 $mu_plugins = opendir( WPMU_PLUGIN_DIR ); 673 if ( $mu_plugins ) { 674 while ( false !== $plugin = readdir( $mu_plugins ) ) { 675 if ( 0 !== strpos( $plugin, '.' ) ) { 676 $files_to_move[] = $plugin; 677 } 678 } 679 } 680 681 closedir( $mu_plugins ); 682 683 foreach ( $files_to_move as $file_to_move ) { 684 $f = rename( WPMU_PLUGIN_DIR . '/' . $file_to_move, $mu_bu_dir . '/' . $file_to_move ); 685 } 628 rename( WPMU_PLUGIN_DIR, $mu_bu_dir ); 686 629 } 687 630 } … … 694 637 * @access private 695 638 */ 696 private function _restore_mu_plugins() { 697 $mu_bu_dir = WP_CONTENT_DIR . '/mu-plugin-backup'; 698 $files_to_move = array(); 699 $mu_plugins = @opendir( $mu_bu_dir ); 700 if ( $mu_plugins ) { 701 while ( false !== $plugin = readdir( $mu_plugins ) ) { 702 if ( 0 !== strpos( $plugin, '.' ) ) { 703 $files_to_move[] = $plugin; 704 } 705 } 706 } 707 708 closedir( $mu_plugins ); 709 710 foreach ( $files_to_move as $file_to_move ) { 711 rename( $mu_bu_dir . '/' . $file_to_move, WPMU_PLUGIN_DIR . '/' . $file_to_move ); 639 private static function _restore_mu_plugins() { 640 $mu_bu_dir = WP_CONTENT_DIR . '/mu-plugin-backup'; 641 642 if ( is_dir( WPMU_PLUGIN_DIR ) ) { 643 rmdir( WPMU_PLUGIN_DIR ); 712 644 } 713 645 714 646 if ( is_dir( $mu_bu_dir ) ) { 715 r mdir( $mu_bu_dir);647 rename( $mu_bu_dir, WPMU_PLUGIN_DIR ); 716 648 } 717 649 }
Note: See TracChangeset
for help on using the changeset viewer.