diff --git a/tests/phpunit/includes/bootstrap.php b/tests/phpunit/includes/bootstrap.php index b4bff16698..089cc59ef1 100644 --- a/tests/phpunit/includes/bootstrap.php +++ b/tests/phpunit/includes/bootstrap.php @@ -16,7 +16,7 @@ $config_file_path .= '/wp-tests-config.php'; * Globalize some WordPress variables, because PHPUnit loads this file inside a function * See: https://github.com/sebastianbergmann/phpunit/issues/325 */ -global $wpdb, $current_site, $current_blog, $wp_rewrite, $shortcode_tags, $wp, $phpmailer; +global $wpdb, $current_site, $current_blog, $wp_rewrite, $shortcode_tags, $wp, $phpmailer, $wp_theme_directories; if ( !is_readable( $config_file_path ) ) { die( "ERROR: wp-tests-config.php is missing! Please use wp-tests-config-sample.php to create a config file.\n" ); @@ -53,8 +53,11 @@ $multisite = $multisite || ( defined( 'MULTISITE' ) && MULTISITE ); require_once( dirname( __FILE__ ) . '/mock-mailer.php' ); $phpmailer = new MockPHPMailer(); -// Add a symlink to the empty default theme to the themes directory, so it can be used for the tests. -_symlink_default_theme(); +// Set the theme to our special empty theme, to avoid interference from the current Twenty* theme. +if ( ! defined( 'WP_DEFAULT_THEME' ) ) { + define( 'WP_DEFAULT_THEME', 'default' ); +} +$wp_theme_directories = array( DIR_TESTDATA . '/themedir1' ); system( WP_PHP_BINARY . ' ' . escapeshellarg( dirname( __FILE__ ) . '/install.php' ) . ' ' . escapeshellarg( $config_file_path ) . ' ' . $multisite ); diff --git a/tests/phpunit/includes/functions.php b/tests/phpunit/includes/functions.php index dc8e472ccd..a8702767ef 100644 --- a/tests/phpunit/includes/functions.php +++ b/tests/phpunit/includes/functions.php @@ -161,21 +161,3 @@ function _upload_dir_https( $uploads ) { return $uploads; } - -/** - * Helper functions to link and unlink the empty default theme into the WordPress install - */ -function _symlink_default_theme() { - _unlink_default_theme(); - symlink( DIR_TESTDATA . '/themedir1/default', ABSPATH . '/wp-content/themes/default' ); -} - -function _unlink_default_theme() { - if ( file_exists( ABSPATH . '/wp-content/themes/default' ) ) { - unlink( ABSPATH . '/wp-content/themes/default' ); - } -} -// Only unlink when we're in the main process. -if ( 'phpunit' === substr( $GLOBALS['argv'][0], -7 ) ) { - register_shutdown_function( '_unlink_default_theme' ); -} diff --git a/tests/phpunit/includes/install.php b/tests/phpunit/includes/install.php index 5db0cc1c5a..50efd43bd7 100644 --- a/tests/phpunit/includes/install.php +++ b/tests/phpunit/includes/install.php @@ -9,6 +9,12 @@ error_reporting( E_ALL & ~E_DEPRECATED & ~E_STRICT ); $config_file_path = $argv[1]; $multisite = ! empty( $argv[2] ); +// Set the theme to our special empty theme, to avoid interference from the current Twenty* theme. +if ( ! defined( 'WP_DEFAULT_THEME' ) ) { + define( 'WP_DEFAULT_THEME', 'default' ); +} +$wp_theme_directories = array( dirname( __FILE__ ) . '/../data/themedir1' ); + define( 'WP_INSTALLING', true ); require_once $config_file_path; require_once dirname( __FILE__ ) . '/functions.php'; diff --git a/tests/phpunit/tests/theme.php b/tests/phpunit/tests/theme.php index 62a88b998f..4cfba15e45 100644 --- a/tests/phpunit/tests/theme.php +++ b/tests/phpunit/tests/theme.php @@ -14,16 +14,27 @@ class Tests_Theme extends WP_UnitTestCase { ); function setUp() { + global $wp_theme_directories; + parent::setUp(); + + $backup_wp_theme_directories = $wp_theme_directories; + $wp_theme_directories = array( WP_CONTENT_DIR . '/themes' ); + add_filter( 'extra_theme_headers', array( $this, '_theme_data_extra_headers' ) ); wp_clean_themes_cache(); unset( $GLOBALS['wp_themes'] ); } function tearDown() { + global $wp_theme_directories; + + $wp_theme_directories = $this->wp_theme_directories; + remove_filter( 'extra_theme_headers', array( $this, '_theme_data_extra_headers' ) ); wp_clean_themes_cache(); unset( $GLOBALS['wp_themes'] ); + parent::tearDown(); }