Changeset 61076 for trunk/tests/phpunit/tests/template.php
- Timestamp:
- 10/28/2025 05:32:13 AM (8 months ago)
- File:
-
- 1 edited
-
trunk/tests/phpunit/tests/template.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/template.php
r61008 r61076 79 79 protected $original_wp_styles; 80 80 81 /** 82 * @var array|null 83 */ 84 protected $original_theme_features; 85 81 86 public function set_up() { 82 87 parent::set_up(); … … 111 116 wp_scripts(); 112 117 wp_styles(); 118 119 $this->original_theme_features = $GLOBALS['_wp_theme_features']; 113 120 } 114 121 … … 117 124 $wp_scripts = $this->original_wp_scripts; 118 125 $wp_styles = $this->original_wp_styles; 126 127 $GLOBALS['_wp_theme_features'] = $this->original_theme_features; 119 128 120 129 ini_set( 'default_mimetype', $this->original_default_mimetype ); … … 914 923 915 924 /** 916 * Tests that wp_load_classic_theme_block_styles_on_demand() does not add hooks for classic themes when output buffering is blocked. 925 * Data provider. 926 * 927 * @return array<string, array{theme: string, set_up: Closure|null, expected_on_demand: bool, expected_buffer_started: bool}> 928 */ 929 public function data_wp_load_classic_theme_block_styles_on_demand(): array { 930 return array( 931 'block_theme' => array( 932 'theme' => 'block-theme', 933 'set_up' => static function () {}, 934 'expected_on_demand' => false, 935 'expected_buffer_started' => false, 936 ), 937 'classic_theme_with_output_buffer_blocked' => array( 938 'theme' => 'default', 939 'set_up' => static function () { 940 add_filter( 'wp_should_output_buffer_template_for_enhancement', '__return_false' ); 941 }, 942 'expected_on_demand' => false, 943 'expected_buffer_started' => false, 944 ), 945 'classic_theme_with_block_styles_support' => array( 946 'theme' => 'default', 947 'set_up' => static function () { 948 add_theme_support( 'wp-block-styles' ); 949 }, 950 'expected_on_demand' => true, 951 'expected_buffer_started' => true, 952 ), 953 'classic_theme_without_block_styles_support' => array( 954 'theme' => 'default', 955 'set_up' => static function () { 956 remove_theme_support( 'wp-block-styles' ); 957 }, 958 'expected_on_demand' => false, 959 'expected_buffer_started' => true, 960 ), 961 ); 962 } 963 964 /** 965 * Tests that wp_load_classic_theme_block_styles_on_demand() adds the expected hooks (or not). 917 966 * 918 967 * @ticket 64099 968 * @ticket 64150 969 * 919 970 * @covers ::wp_load_classic_theme_block_styles_on_demand 920 */ 921 public function test_wp_load_classic_theme_block_styles_on_demand_in_classic_theme_but_output_buffering_blocked(): void { 922 add_filter( 'wp_should_output_buffer_template_for_enhancement', '__return_false' ); 923 switch_theme( 'default' ); 924 925 wp_load_classic_theme_block_styles_on_demand(); 926 927 $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.' ); 928 $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.' ); 929 $this->assertFalse( has_action( 'wp_template_enhancement_output_buffer_started', 'wp_hoist_late_printed_styles' ), 'Expect wp_template_enhancement_output_buffer_started action NOT to be added for block themes.' ); 930 } 931 932 /** 933 * Tests that wp_load_classic_theme_block_styles_on_demand() adds the expected hooks for classic themes. 934 * 935 * @ticket 64099 936 * @covers ::wp_load_classic_theme_block_styles_on_demand 937 */ 938 public function test_wp_load_classic_theme_block_styles_on_demand_in_classic_theme(): void { 939 switch_theme( 'default' ); 940 971 * 972 * @dataProvider data_wp_load_classic_theme_block_styles_on_demand 973 */ 974 public function test_wp_load_classic_theme_block_styles_on_demand( string $theme, ?Closure $set_up, bool $expected_on_demand, bool $expected_buffer_started ) { 941 975 $this->assertFalse( wp_should_load_separate_core_block_assets(), 'Expected wp_should_load_separate_core_block_assets() to return false initially.' ); 942 976 $this->assertFalse( wp_should_load_block_assets_on_demand(), 'Expected wp_should_load_block_assets_on_demand() to return true' ); 943 977 $this->assertFalse( has_action( 'wp_template_enhancement_output_buffer_started', 'wp_hoist_late_printed_styles' ), 'Expected wp_template_enhancement_output_buffer_started action to be added for classic themes.' ); 944 978 979 switch_theme( $theme ); 980 if ( $set_up ) { 981 $set_up(); 982 } 983 945 984 wp_load_classic_theme_block_styles_on_demand(); 946 985 947 $this->assert True( wp_should_load_separate_core_block_assets(), 'Expected wp_should_load_separate_core_block_assets() filters to return true' );948 $this->assert True( wp_should_load_block_assets_on_demand(), 'Expected wp_should_load_block_assets_on_demand() to return true' );949 $this->assert NotFalse( has_action( 'wp_template_enhancement_output_buffer_started', 'wp_hoist_late_printed_styles' ), 'Expected wp_template_enhancement_output_buffer_started action to be added for classic themes.' );986 $this->assertSame( $expected_on_demand, wp_should_load_separate_core_block_assets(), 'Expected wp_should_load_separate_core_block_assets() return value.' ); 987 $this->assertSame( $expected_on_demand, wp_should_load_block_assets_on_demand(), 'Expected wp_should_load_block_assets_on_demand() return value.' ); 988 $this->assertSame( $expected_buffer_started, (bool) has_action( 'wp_template_enhancement_output_buffer_started', 'wp_hoist_late_printed_styles' ), 'Expected wp_template_enhancement_output_buffer_started action added status.' ); 950 989 } 951 990 … … 953 992 * Data provider. 954 993 * 955 * @return array<string, array{set_up ?: Closure}>994 * @return array<string, array{set_up: Closure|null}> 956 995 */ 957 996 public function data_wp_hoist_late_printed_styles(): array { … … 976 1015 }, 977 1016 ), 1017 'block_library_removed' => array( 1018 'set_up' => static function () { 1019 wp_deregister_style( 'wp-block-library' ); 1020 }, 1021 ), 978 1022 ); 979 1023 } … … 1007 1051 $head_output = get_echo( 'wp_head' ); 1008 1052 1009 $placeholder_pattern = '#/\*wp_late_styles_placeholder:[a-f0-9-]+\*/#';1010 1011 $this->assertMatchesRegularExpression( $placeholder_pattern, $head_output, 'Expected the placeholder to be present' );1012 1053 $this->assertStringContainsString( 'early', $head_output, 'Expected the early-enqueued stylesheet to be present.' ); 1013 1054 … … 1025 1066 $filtered_buffer = apply_filters( 'wp_template_enhancement_output_buffer', $buffer ); 1026 1067 1027 $this->assertDoesNotMatchRegularExpression( $placeholder_pattern, $filtered_buffer, 'Expected the placeholder to be removed.' ); 1068 $this->assertStringContainsString( '</head>', $buffer, 'Expected the closing HEAD tag to be in the response.' ); 1069 1070 $this->assertDoesNotMatchRegularExpression( '#/\*wp_late_styles_placeholder:[a-f0-9-]+\*/#', $filtered_buffer, 'Expected the placeholder to be removed.' ); 1028 1071 $found_styles = array( 1029 1072 'HEAD' => array(),
Note: See TracChangeset
for help on using the changeset viewer.