From 0ded98ff2c3588374d8189cf22e264c84531e8f7 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 14 Jul 2020 00:32:36 +0000 Subject: [PATCH] Tests: Copy themes from `tests/phpunit/data` to `wp-content/themes`, instead of creating a symlink. This allows the theme file tests in `phpunit/tests/link/themeFile.php` to run on Windows without requiring administrative privileges. Follow-up to [42812], [42819]. Props danielhuesken, christophherr, davidbaumwald, SergeyBiryukov. See #40856, #39975. git-svn-id: https://develop.svn.wordpress.org/trunk@48463 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/link/themeFile.php | 42 ++++++++++++++++++-------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/tests/phpunit/tests/link/themeFile.php b/tests/phpunit/tests/link/themeFile.php index 9497b71e14..3e00780a64 100644 --- a/tests/phpunit/tests/link/themeFile.php +++ b/tests/phpunit/tests/link/themeFile.php @@ -5,22 +5,40 @@ class Test_Theme_File extends WP_UnitTestCase { public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { - if ( ! function_exists( 'symlink' ) ) { - self::markTestSkipped( 'symlink() is not available.' ); - } - // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged - if ( ! @symlink( DIR_TESTDATA . '/theme-file-parent', WP_CONTENT_DIR . '/themes/theme-file-parent' ) ) { - self::markTestSkipped( 'Could not create parent symlink.' ); - } - // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged - if ( ! @symlink( DIR_TESTDATA . '/theme-file-child', WP_CONTENT_DIR . '/themes/theme-file-child' ) ) { - self::markTestSkipped( 'Could not create child symlink.' ); + $themes = array( + 'theme-file-parent', + 'theme-file-child', + ); + + // Copy themes from tests/phpunit/data to wp-content/themes. + foreach ( $themes as $theme ) { + $source_dir = DIR_TESTDATA . '/' . $theme; + $dest_dir = WP_CONTENT_DIR . '/themes/' . $theme; + + mkdir( $dest_dir ); + + foreach ( glob( $source_dir . '/*.*' ) as $theme_file ) { + copy( $theme_file, $dest_dir . '/' . basename( $theme_file ) ); + } } } public static function wpTearDownAfterClass() { - unlink( WP_CONTENT_DIR . '/themes/theme-file-parent' ); - unlink( WP_CONTENT_DIR . '/themes/theme-file-child' ); + $themes = array( + 'theme-file-parent', + 'theme-file-child', + ); + + // Remove previously copied themes from wp-content/themes. + foreach ( $themes as $theme ) { + $dest_dir = WP_CONTENT_DIR . '/themes/' . $theme; + + foreach ( glob( $dest_dir . '/*.*' ) as $theme_file ) { + unlink( $theme_file ); + } + + rmdir( $dest_dir ); + } } /**