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
13 changes: 13 additions & 0 deletions tests/phpunit/tests/blocks/editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function set_up() {
global $post;

parent::set_up();
$this->original_stylesheet = get_stylesheet();

remove_action( 'wp_print_styles', 'print_emoji_styles' );

Expand Down Expand Up @@ -51,6 +52,11 @@ public function tear_down() {
$wp_rest_server = null;
global $post_ID;
$post_ID = null;

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

parent::tear_down();
}

Expand All @@ -64,6 +70,13 @@ public function tear_down() {
*/
protected $original_wp_styles;

/**
* Original stylesheet.
*
* @var string
*/
private $original_stylesheet;

public function filter_set_block_categories_post( $block_categories, $post ) {
if ( empty( $post ) ) {
return $block_categories;
Expand Down
12 changes: 12 additions & 0 deletions tests/phpunit/tests/blocks/getBlockAssetUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@ class Tests_Get_Block_Asset_Url extends WP_UnitTestCase {
*/
private $orig_theme_dir;

/**
* Original stylesheet.
*
* @var string
*/
private $original_stylesheet;

public function set_up() {
global $wp_theme_directories;

parent::set_up();
$this->original_stylesheet = get_stylesheet();

// Sets up the `wp-content/themes/` directory to ensure consistency when running tests.
$this->orig_theme_dir = $wp_theme_directories;
Expand All @@ -34,6 +42,10 @@ public function set_up() {
public function tear_down() {
global $wp_theme_directories;

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

$wp_theme_directories = $this->orig_theme_dir;

wp_clean_themes_cache();
Expand Down
16 changes: 16 additions & 0 deletions tests/phpunit/tests/blocks/getBlockTemplates.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ class Tests_Blocks_GetBlockTemplates extends WP_UnitTestCase {

const TEST_THEME = 'block-theme';

/**
* Original stylesheet.
*
* @var string
*/
private $original_stylesheet;

/**
* @var WP_Post
*/
Expand Down Expand Up @@ -91,9 +98,18 @@ public static function wpTearDownAfterClass() {

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

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

parent::tear_down();
}

/**
* Gets the template IDs from the given array.
*
Expand Down
16 changes: 16 additions & 0 deletions tests/phpunit/tests/blocks/getHookedBlocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ class Tests_Blocks_GetHookedBlocks extends WP_UnitTestCase {

const TEST_THEME_NAME = 'block-theme-with-hooked-blocks';

/**
* Original stylesheet.
*
* @var string
*/
private $original_stylesheet;

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

/**
* Tear down after each test.
*
Expand Down Expand Up @@ -43,6 +55,10 @@ public function tear_down() {
}
}

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

parent::tear_down();
}

Expand Down
12 changes: 12 additions & 0 deletions tests/phpunit/tests/blocks/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ class Tests_Blocks_Register extends WP_UnitTestCase {
*/
protected $original_wp_styles;

/**
* Original stylesheet.
*
* @var string
*/
private $original_stylesheet;

/**
* ID for a test post.
*
Expand Down Expand Up @@ -61,6 +68,7 @@ public function render_stub() {}
*/
public function set_up() {
parent::set_up();
$this->original_stylesheet = get_stylesheet();

global $wp_scripts, $wp_styles;
$this->original_wp_scripts = $wp_scripts;
Expand Down Expand Up @@ -96,6 +104,10 @@ public function tear_down() {
$wp_scripts = $this->original_wp_scripts;
$wp_styles = $this->original_wp_styles;

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/blocks/wpBlockPatternsRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
*/
private $original_registered_patterns = null;

/**
* Original stylesheet.
*
* @var string
*/
private $original_stylesheet;

/**
* Set up each test method.
*
Expand All @@ -37,6 +44,7 @@

$this->registry = new WP_Block_Patterns_Registry();
$this->original_registered_patterns = $this->get_registered_patterns_variable_value();
$this->original_stylesheet = get_stylesheet();

Check warning on line 47 in tests/phpunit/tests/blocks/wpBlockPatternsRegistry.php

View workflow job for this annotation

GitHub Actions / Coding standards / PHP checks

Equals sign not aligned with surrounding assignments; expected 10 spaces but found 11 spaces
}

/**
Expand All @@ -54,6 +62,11 @@
}

$this->set_registered_patterns_variable_value( $this->original_registered_patterns );

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/theme/wpThemeGetBlockPatterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,27 @@ class Tests_Theme_WPThemeGetBlockPatterns extends WP_UnitTestCase {
*/
private $initial_cache_object;

/**
* Original stylesheet.
*
* @var string
*/
private $original_stylesheet;

public function set_up() {
parent::set_up();

$this->initial_cache_object = wp_using_ext_object_cache();
$this->original_stylesheet = get_stylesheet();
}

public function tear_down() {
wp_using_ext_object_cache( $this->initial_cache_object );

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

parent::tear_down();
}

Expand Down
Loading