Skip to content

Commit a45fc65

Browse files
committed
Reintroduce test removed in #45993.
1 parent 35814d5 commit a45fc65

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

phpunit/get-global-styles-and-settings-test.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,21 @@
77

88
class WP_Get_Global_Styles_And_Settings_Test extends WP_UnitTestCase {
99

10+
/**
11+
* Administrator ID.
12+
*
13+
* @var int
14+
*/
15+
private static $administrator_id;
16+
17+
public static function wpSetUpBeforeClass( $factory ) {
18+
self::$administrator_id = $factory->user->create( array( 'role' => 'administrator' ) );
19+
}
20+
21+
public static function wpTearDownAfterClass() {
22+
self::delete_user( self::$administrator_id );
23+
}
24+
1025
public function test_wp_theme_use_persistent_cache() {
1126
$expected_default = ! in_array( wp_get_environment_type(), array( 'local', 'development' ), true );
1227

@@ -18,4 +33,33 @@ public function test_wp_theme_use_persistent_cache() {
1833
add_filter( 'wp_theme_use_persistent_cache', '__return_false' );
1934
$this->assertFalse( wp_theme_use_persistent_cache() );
2035
}
36+
37+
public function test_global_styles_user_cpt_change_invalidates_cached_stylesheet() {
38+
$this->override_theme_root( realpath( DIR_TESTDATA . '/themedir1' ) );
39+
add_filter( 'wp_theme_use_persistent_cache', '__return_true' );
40+
switch_theme( 'block-theme' );
41+
wp_set_current_user( self::$administrator_id );
42+
43+
$styles = gutenberg_get_global_stylesheet();
44+
$this->assertStringNotContainsString( 'background-color: hotpink;', $styles );
45+
46+
$user_cpt = WP_Theme_JSON_Resolver_Gutenberg::get_user_data_from_wp_global_styles( wp_get_theme(), true );
47+
$config = json_decode( $user_cpt['post_content'], true );
48+
$config['styles']['color']['background'] = 'hotpink';
49+
$user_cpt['post_content'] = wp_json_encode( $config );
50+
51+
wp_update_post( $user_cpt, true, false );
52+
53+
$styles = gutenberg_get_global_stylesheet();
54+
$this->assertStringContainsString( 'background-color: hotpink;', $styles );
55+
}
56+
57+
public function override_theme_root( $theme_root ) {
58+
$override = function() use ( $theme_root ) {
59+
return $theme_root;
60+
};
61+
add_filter( 'theme_root', $override );
62+
add_filter( 'stylesheet_root', $override );
63+
add_filter( 'template_root', $override );
64+
}
2165
}

0 commit comments

Comments
 (0)