Skip to content
Closed
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
5 changes: 5 additions & 0 deletions tests/phpunit/data/themedir1/block-theme/theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@
}
}
}
},
"my/unregistered-third-party-block": {
"color": {
"background": "hotpink"
}
}
},
"elements": {
Expand Down
5 changes: 5 additions & 0 deletions tests/phpunit/tests/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ public function tear_down() {
$registry->unregister( 'third-party/test' );
}

if ( isset( $GLOBALS['_wp_tests_development_mode'] ) ) {
remove_all_filters( 'theme_file_path' );
wp_theme_has_theme_json();
}

unset( $GLOBALS['_wp_tests_development_mode'] );
parent::tear_down();
}
Expand Down
19 changes: 16 additions & 3 deletions tests/phpunit/tests/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,22 @@
*/
private $orig_theme_dir;

/**
* Theme features registered before the test ran.
*
* @var array
*/
private $orig_theme_features;

public function set_up() {
global $wp_theme_directories;

parent::set_up();

// Sets up the `wp-content/themes/` directory to ensure consistency when running tests.
$this->orig_theme_dir = $wp_theme_directories;
$wp_theme_directories = array( WP_CONTENT_DIR . '/themes', realpath( DIR_TESTDATA . '/themedir1' ) );
$this->orig_theme_dir = $wp_theme_directories;
$wp_theme_directories = array( WP_CONTENT_DIR . '/themes', realpath( DIR_TESTDATA . '/themedir1' ) );
$this->orig_theme_features = $GLOBALS['_wp_theme_features'];

add_filter( 'extra_theme_headers', array( $this, 'theme_data_extra_headers' ) );
wp_clean_themes_cache();
Expand All @@ -56,7 +64,12 @@
wp_clean_themes_cache();
unset( $GLOBALS['wp_themes'] );

parent::tear_down();
try {
parent::tear_down();
} finally {
// Restore after the parent removes HTML5 theme support.
$GLOBALS['_wp_theme_features'] = $this->orig_theme_features;
}
}

public function test_wp_get_themes_default() {
Expand Down Expand Up @@ -428,7 +441,7 @@
* @expectedDeprecated get_themes
* @expectedDeprecated get_current_theme
*/
public function test_switch_theme() {

Check warning on line 444 in tests/phpunit/tests/theme.php

View workflow job for this annotation

GitHub Actions / PHP 8.5 / MySQL 8.4 (test reporting enabled)

Slow PHPUnit test

Tests_Theme::test_switch_theme took 1.365968s
$themes = get_themes();

$this->assertNotEmpty( $themes );
Expand Down
34 changes: 34 additions & 0 deletions tests/phpunit/tests/theme/support.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,40 @@
*/
class Tests_Theme_Support extends WP_UnitTestCase {

/**
* Theme features registered before the test ran.
*
* @var array
*/
private $orig_theme_features;

/**
* Nav menu locations registered before the test ran.
*
* @var array
*/
private $orig_registered_nav_menus;

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

$this->orig_theme_features = $GLOBALS['_wp_theme_features'];
$this->orig_registered_nav_menus = $GLOBALS['_wp_registered_nav_menus'] ?? array();

// Start without support from the bootstrapped theme.
$GLOBALS['_wp_theme_features'] = array();
}

public function tear_down() {
try {
parent::tear_down();
} finally {
// Restore after the parent removes HTML5 theme support.
$GLOBALS['_wp_theme_features'] = $this->orig_theme_features;
$GLOBALS['_wp_registered_nav_menus'] = $this->orig_registered_nav_menus;
}
}

public function test_the_basics() {
add_theme_support( 'automatic-feed-links' );
$this->assertTrue( current_theme_supports( 'automatic-feed-links' ) );
Expand Down
14 changes: 13 additions & 1 deletion tests/phpunit/tests/theme/wpAddGlobalStylesForBlocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ class Tests_Theme_WpAddGlobalStylesForBlocks extends WP_Theme_UnitTestCase {
*/
private $test_blocks = array();

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

/**
* Administrator ID.
*
Expand All @@ -37,6 +44,7 @@ public static function set_up_before_class() {

public function set_up() {
parent::set_up();
$this->original_stylesheet = get_stylesheet();
remove_action( 'wp_print_styles', 'print_emoji_styles' );
}

Expand All @@ -49,6 +57,10 @@ public function tear_down() {
$this->test_blocks = array();
}

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

parent::tear_down();
}

Expand All @@ -63,7 +75,7 @@ public function test_third_party_blocks_inline_styles_not_register_to_global_sty
wp_add_global_styles_for_blocks();

$this->assertNotContains(
':root :where(.wp-block-my-third-party-block){background-color: hotpink;}',
':root :where(.wp-block-my-unregistered-third-party-block){background-color: hotpink;}',
$this->get_global_styles()
);
}
Expand Down
Loading