Skip to content

Commit 2e483e5

Browse files
committed
Tests: Restore the theme in the theme test base class.
Save the original stylesheet in `WP_Theme_UnitTestCase` and restore it during teardown after removing the test theme-root filters. Developed in: #14735 Props devmuhib, huzaifaalmesbah. See #65893. git-svn-id: https://develop.svn.wordpress.org/trunk@64836 602fd350-edb4-49c9-b593-d223f7449a82
1 parent bb44b14 commit 2e483e5

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

‎tests/phpunit/tests/theme/base.php‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,19 @@ abstract class WP_Theme_UnitTestCase extends WP_UnitTestCase {
1616
*/
1717
private $orig_theme_dir;
1818

19+
/**
20+
* Original stylesheet.
21+
*
22+
* @var string
23+
*/
24+
private $original_stylesheet;
25+
1926
public function set_up() {
2027
parent::set_up();
2128

22-
$this->orig_theme_dir = $GLOBALS['wp_theme_directories'];
23-
$this->theme_root = realpath( DIR_TESTDATA . '/themedir1' );
29+
$this->original_stylesheet = get_stylesheet();
30+
$this->orig_theme_dir = $GLOBALS['wp_theme_directories'];
31+
$this->theme_root = realpath( DIR_TESTDATA . '/themedir1' );
2432

2533
// /themes is necessary as theme.php functions assume /themes is the root if there is only one root.
2634
$GLOBALS['wp_theme_directories'] = array( WP_CONTENT_DIR . '/themes', $this->theme_root );
@@ -47,6 +55,10 @@ public function tear_down() {
4755
wp_clean_theme_json_cache();
4856
unset( $GLOBALS['wp_themes'] );
4957

58+
if ( get_stylesheet() !== $this->original_stylesheet ) {
59+
switch_theme( $this->original_stylesheet );
60+
}
61+
5062
parent::tear_down();
5163
}
5264

0 commit comments

Comments
 (0)