Skip to content

Commit 9f4a5ce

Browse files
committed
improve tests for wp_always_load_block_styles_on_demand_init and wp_use_placeholder_for_delayed_css
1 parent 5e7b5b0 commit 9f4a5ce

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

tests/phpunit/tests/template.php

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -830,10 +830,27 @@ public function test_wp_start_template_enhancement_output_buffer_for_json(): voi
830830
$this->assertSame( $json, $output, 'Expected output to not be processed.' );
831831
}
832832

833-
// public function test_wp_always_load_block_styles_on_demand_init_in_block_theme(): void {
834-
// // If we're in a block theme, expect no filters to be added.
833+
/**
834+
* Tests that wp_always_load_block_styles_on_demand does not add filters for block themes.
835+
*
836+
* @ticket 64099
837+
* @covers ::wp_always_load_block_styles_on_demand_init
838+
*/
839+
public function test_wp_always_load_block_styles_on_demand_init_in_block_theme(): void {
840+
// Clean up any filters that may have been added by previous tests
841+
remove_filter( 'wp_should_output_buffer_template_for_enhancement', '__return_true', 0 );
842+
remove_filter( 'should_load_separate_core_block_assets', '__return_true' );
843+
remove_filter( 'should_load_block_assets_on_demand', '__return_true' );
844+
remove_action( 'wp_template_enhancement_output_buffer_started', 'wp_use_placeholder_for_delayed_css' );
845+
846+
switch_theme( 'block-theme' );
835847

836-
// }
848+
wp_always_load_block_styles_on_demand_init();
849+
850+
$this->assertFalse( has_filter( 'should_load_separate_core_block_assets' ), 'Expect should_load_separate_core_block_assets filter NOT to be added for block themes.' );
851+
$this->assertFalse( has_filter( 'should_load_block_assets_on_demand', '__return_true' ), 'Expect should_load_block_assets_on_demand filter NOT to be added for block themes.' );
852+
$this->assertFalse( has_action( 'wp_template_enhancement_output_buffer_started', 'wp_use_placeholder_for_delayed_css' ), 'Expect wp_template_enhancement_output_buffer_started action NOT to be added for block themes.' );
853+
}
837854

838855
/**
839856
* Tests that wp_always_load_block_styles_on_demand adds the expected filters for classic themes.
@@ -842,7 +859,16 @@ public function test_wp_start_template_enhancement_output_buffer_for_json(): voi
842859
* @covers ::wp_always_load_block_styles_on_demand_init
843860
*/
844861
public function test_wp_always_load_block_styles_on_demand_init_in_classic_theme(): void {
845-
// If we're in a classic theme, expect filters to be added.
862+
// Clean up any filters that may have been added by previous tests
863+
remove_filter( 'wp_should_output_buffer_template_for_enhancement', '__return_true', 0 );
864+
remove_filter( 'should_load_separate_core_block_assets', '__return_true' );
865+
remove_filter( 'should_load_block_assets_on_demand', '__return_true' );
866+
remove_action( 'wp_template_enhancement_output_buffer_started', 'wp_use_placeholder_for_delayed_css' );
867+
868+
switch_theme( 'default' );
869+
870+
wp_always_load_block_styles_on_demand_init();
871+
846872
$default = null;
847873
$this->assertTrue( has_filter( 'should_load_separate_core_block_assets' ), 'Expect should_load_separate_core_block_assets filter to be added for classic themes.' );
848874
$this->assertTrue( apply_filters( 'should_load_separate_core_block_assets', $default ), 'Expect should_load_separate_core_block_assets filters to return true' );
@@ -858,6 +884,13 @@ public function test_wp_always_load_block_styles_on_demand_init_in_classic_theme
858884
* @covers ::wp_use_placeholder_for_delayed_css
859885
*/
860886
public function test_wp_use_placeholder_for_delayed_css(): void {
887+
// Clean up any filters that may have been added by previous tests
888+
remove_filter( 'wp_should_output_buffer_template_for_enhancement', '__return_true', 0 );
889+
remove_filter( 'should_load_separate_core_block_assets', '__return_true' );
890+
remove_filter( 'should_load_block_assets_on_demand', '__return_true' );
891+
remove_action( 'wp_template_enhancement_output_buffer_started', 'wp_use_placeholder_for_delayed_css' );
892+
893+
switch_theme( 'default' );
861894

862895
// Enqueue a style
863896
wp_enqueue_style( 'test-style', 'http://example.com/style.css' );

0 commit comments

Comments
 (0)