Skip to content

Commit 92db7ba

Browse files
committed
Properly set up theme directory
1 parent 2b570aa commit 92db7ba

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

phpunit/wp-theme-json-test.php

+29
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,35 @@
77

88
class WP_Theme_Json_Test extends WP_UnitTestCase {
99

10+
public function set_up() {
11+
parent::set_up();
12+
$this->theme_root = realpath( __DIR__ . '/data/themedir1' );
13+
14+
$this->orig_theme_dir = $GLOBALS['wp_theme_directories'];
15+
16+
// /themes is necessary as theme.php functions assume /themes is the root if there is only one root.
17+
$GLOBALS['wp_theme_directories'] = array( WP_CONTENT_DIR . '/themes', $this->theme_root );
18+
19+
add_filter( 'theme_root', array( $this, 'filter_set_theme_root' ) );
20+
add_filter( 'stylesheet_root', array( $this, 'filter_set_theme_root' ) );
21+
add_filter( 'template_root', array( $this, 'filter_set_theme_root' ) );
22+
$this->queries = array();
23+
// Clear caches.
24+
wp_clean_themes_cache();
25+
unset( $GLOBALS['wp_themes'] );
26+
}
27+
28+
public function tear_down() {
29+
$GLOBALS['wp_theme_directories'] = $this->orig_theme_dir;
30+
wp_clean_themes_cache();
31+
unset( $GLOBALS['wp_themes'] );
32+
parent::tear_down();
33+
}
34+
35+
public function filter_set_theme_root() {
36+
return $this->theme_root;
37+
}
38+
1039
/**
1140
* Test that it reports correctly themes that have a theme.json.
1241
*

0 commit comments

Comments
 (0)