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