Skip to content

Commit 648d1bb

Browse files
committed
Tests: Restore themes after block template tests.
Save and restore the incoming stylesheet in `Tests_Block_Template` and `Tests_Block_Template_Utils`. Switching back clears cached `theme.json` data before parent teardown, preventing later tests from using resolver data from a temporary test theme. Developed in: #14817 Props shailu25. See #65893. git-svn-id: https://develop.svn.wordpress.org/trunk@64776 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 3d8defe commit 648d1bb

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

‎tests/phpunit/tests/block-template-utils.php‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,16 @@ public static function wpTearDownAfterClass() {
8181
wp_delete_post( self::$template_post->ID );
8282
}
8383

84+
/**
85+
* Original stylesheet before the test switches themes.
86+
*
87+
* @var string
88+
*/
89+
private $original_stylesheet;
90+
8491
public function set_up() {
8592
parent::set_up();
93+
$this->original_stylesheet = get_stylesheet();
8694
switch_theme( self::TEST_THEME );
8795
}
8896

@@ -96,6 +104,10 @@ public function tear_down() {
96104
unregister_block_type( 'tests/hooked-block' );
97105
}
98106

107+
if ( get_stylesheet() !== $this->original_stylesheet ) {
108+
switch_theme( $this->original_stylesheet );
109+
}
110+
99111
parent::tear_down();
100112
}
101113

‎tests/phpunit/tests/block-template.php‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,16 @@ class Tests_Block_Template extends WP_UnitTestCase {
1111

1212
private static $template_canvas_path = ABSPATH . WPINC . '/template-canvas.php';
1313

14+
/**
15+
* Original stylesheet before the test switches themes.
16+
*
17+
* @var string
18+
*/
19+
private $original_stylesheet;
20+
1421
public function set_up() {
1522
parent::set_up();
23+
$this->original_stylesheet = get_stylesheet();
1624
switch_theme( 'block-theme' );
1725
do_action( 'setup_theme' );
1826
do_action( 'after_setup_theme' );
@@ -21,6 +29,11 @@ public function set_up() {
2129
public function tear_down() {
2230
global $_wp_current_template_id, $_wp_current_template_content;
2331
unset( $_wp_current_template_id, $_wp_current_template_content );
32+
33+
if ( get_stylesheet() !== $this->original_stylesheet ) {
34+
switch_theme( $this->original_stylesheet );
35+
}
36+
2437
parent::tear_down();
2538
}
2639

0 commit comments

Comments
 (0)