Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions tests/phpunit/tests/block-template-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,16 @@ public static function wpTearDownAfterClass() {
wp_delete_post( self::$template_post->ID );
}

/**
* Original stylesheet before the test switches themes.
*
* @var string
*/
private $original_stylesheet;

public function set_up() {
parent::set_up();
$this->original_stylesheet = get_stylesheet();
switch_theme( self::TEST_THEME );
}

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

if ( get_stylesheet() !== $this->original_stylesheet ) {
switch_theme( $this->original_stylesheet );
}

parent::tear_down();
}

Expand Down
13 changes: 13 additions & 0 deletions tests/phpunit/tests/block-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@ class Tests_Block_Template extends WP_UnitTestCase {

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

/**
* Original stylesheet before the test switches themes.
*
* @var string
*/
private $original_stylesheet;

public function set_up() {
parent::set_up();
$this->original_stylesheet = get_stylesheet();
switch_theme( 'block-theme' );
do_action( 'setup_theme' );
do_action( 'after_setup_theme' );
Expand All @@ -21,6 +29,11 @@ public function set_up() {
public function tear_down() {
global $_wp_current_template_id, $_wp_current_template_content;
unset( $_wp_current_template_id, $_wp_current_template_content );

if ( get_stylesheet() !== $this->original_stylesheet ) {
switch_theme( $this->original_stylesheet );
}

parent::tear_down();
}

Expand Down
Loading