From 92db7ba7fe63b2e1562e4ce6e492ff5edb662e87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Fri, 28 Oct 2022 10:47:21 +0200 Subject: [PATCH] Properly set up theme directory --- phpunit/wp-theme-json-test.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/phpunit/wp-theme-json-test.php b/phpunit/wp-theme-json-test.php index dbbe8a1884145..0d92d33faf88d 100644 --- a/phpunit/wp-theme-json-test.php +++ b/phpunit/wp-theme-json-test.php @@ -7,6 +7,35 @@ class WP_Theme_Json_Test extends WP_UnitTestCase { + public function set_up() { + parent::set_up(); + $this->theme_root = realpath( __DIR__ . '/data/themedir1' ); + + $this->orig_theme_dir = $GLOBALS['wp_theme_directories']; + + // /themes is necessary as theme.php functions assume /themes is the root if there is only one root. + $GLOBALS['wp_theme_directories'] = array( WP_CONTENT_DIR . '/themes', $this->theme_root ); + + add_filter( 'theme_root', array( $this, 'filter_set_theme_root' ) ); + add_filter( 'stylesheet_root', array( $this, 'filter_set_theme_root' ) ); + add_filter( 'template_root', array( $this, 'filter_set_theme_root' ) ); + $this->queries = array(); + // Clear caches. + wp_clean_themes_cache(); + unset( $GLOBALS['wp_themes'] ); + } + + public function tear_down() { + $GLOBALS['wp_theme_directories'] = $this->orig_theme_dir; + wp_clean_themes_cache(); + unset( $GLOBALS['wp_themes'] ); + parent::tear_down(); + } + + public function filter_set_theme_root() { + return $this->theme_root; + } + /** * Test that it reports correctly themes that have a theme.json. *