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