Changeset 63563
- Timestamp:
- 09/09/2026 02:50:06 PM (2 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/blocks/registerCoreBlockStyleHandles.php
r61008 r63563 55 55 * @ticket 58528 56 56 * 57 * @dataProvider data_block_data58 *59 57 * @covers ::register_core_block_style_handles 60 58 * @covers ::wp_should_load_separate_core_block_assets 61 *62 * @param string $name The block name.63 * @param array $schema The block's schema.64 59 */ 65 public function test_wp_should_load_separate_core_block_assets_false( $name, $schema) {60 public function test_wp_should_load_separate_core_block_assets_false() { 66 61 add_filter( 'should_load_separate_core_block_assets', '__return_false' ); 67 $this->assertFalse( wp_should_load_separate_core_block_assets(), 'Core blocks are not expected to load separate assets' );68 62 register_core_block_style_handles(); 69 63 70 foreach ( self::STYLE_FIELDS as $style_field => $filename ) { 71 $style_handle = $schema[ $style_field ]; 72 if ( is_array( $style_handle ) ) { 73 continue; 64 foreach ( $this->get_block_data() as $name => $schema ) { 65 $this->assertFalse( wp_should_load_separate_core_block_assets(), "Block {$name}: Core blocks are not expected to load separate assets" ); 66 67 foreach ( self::STYLE_FIELDS as $style_field => $filename ) { 68 $style_handle = $schema[ $style_field ]; 69 if ( is_array( $style_handle ) ) { 70 continue; 71 } 72 73 $this->assertArrayNotHasKey( $style_handle, $GLOBALS['wp_styles']->registered, "Block {$name}: The key should not exist, as this style should not be registered" ); 74 74 } 75 76 $this->assertArrayNotHasKey( $style_handle, $GLOBALS['wp_styles']->registered, 'The key should not exist, as this style should not be registered' );77 75 } 78 76 } … … 82 80 * @ticket 58528 83 81 * 84 * @dataProvider data_block_data85 *86 82 * @covers ::register_core_block_style_handles 87 83 * @covers ::wp_should_load_separate_core_block_assets 88 *89 * @param string $name The block name.90 * @param array $schema The block's schema.91 84 */ 92 public function test_wp_should_load_separate_core_block_assets_true( $name, $schema) {85 public function test_wp_should_load_separate_core_block_assets_true() { 93 86 add_filter( 'should_load_separate_core_block_assets', '__return_true' ); 94 $this->assertTrue( wp_should_load_separate_core_block_assets(), 'Core assets are expected to load separately' );95 87 register_core_block_style_handles(); 96 88 97 89 $wp_styles = $GLOBALS['wp_styles']; 98 90 99 foreach ( self::STYLE_FIELDS as $style_field => $filename ) { 100 $style_handle = $schema[ $style_field ]; 101 if ( is_array( $style_handle ) ) { 102 continue; 103 } 91 foreach ( $this->get_block_data() as $name => $schema ) { 92 $this->assertTrue( wp_should_load_separate_core_block_assets(), "Block {$name}: Core assets are expected to load separately" ); 104 93 105 $this->assertArrayHasKey( $style_handle, $wp_styles->registered, 'The key should exist, as this style should be registered' ); 106 if ( false === $wp_styles->registered[ $style_handle ]->src ) { 107 $this->assertEmpty( $wp_styles->registered[ $style_handle ]->extra, 'If source is false, style path should not be set' ); 108 } else { 109 $this->assertStringContainsString( $this->includes_url, $wp_styles->registered[ $style_handle ]->src, 'Source of style should contain the includes url' ); 110 $this->assertNotEmpty( $wp_styles->registered[ $style_handle ]->extra, 'The path of the style should exist' ); 111 $this->assertArrayHasKey( 'path', $wp_styles->registered[ $style_handle ]->extra, 'The path key of the style should exist in extra array' ); 112 $this->assertNotEmpty( $wp_styles->registered[ $style_handle ]->extra['path'], 'The path key of the style should not be empty' ); 94 foreach ( self::STYLE_FIELDS as $style_field => $filename ) { 95 $style_handle = $schema[ $style_field ]; 96 if ( is_array( $style_handle ) ) { 97 continue; 98 } 99 100 $this->assertArrayHasKey( $style_handle, $wp_styles->registered, "Block {$name}: The key should exist, as this style should be registered" ); 101 if ( false === $wp_styles->registered[ $style_handle ]->src ) { 102 $this->assertEmpty( $wp_styles->registered[ $style_handle ]->extra, "Block {$name}: If source is false, style path should not be set" ); 103 } else { 104 $this->assertStringContainsString( $this->includes_url, $wp_styles->registered[ $style_handle ]->src, "Block {$name}: Source of style should contain the includes url" ); 105 $this->assertNotEmpty( $wp_styles->registered[ $style_handle ]->extra, "Block {$name}: The path of the style should exist" ); 106 $this->assertArrayHasKey( 'path', $wp_styles->registered[ $style_handle ]->extra, "Block {$name}: The path key of the style should exist in extra array" ); 107 $this->assertNotEmpty( $wp_styles->registered[ $style_handle ]->extra['path'], "Block {$name}: The path key of the style should not be empty" ); 108 } 113 109 } 114 110 } … … 117 113 /** 118 114 * @ticket 58560 119 *120 * @dataProvider data_block_data121 *122 * @param string $name The block name.123 115 */ 124 public function test_wp_should_load_separate_core_block_assets_current_theme_supports( $name) {116 public function test_wp_should_load_separate_core_block_assets_current_theme_supports() { 125 117 add_filter( 'should_load_separate_core_block_assets', '__return_true' ); 126 118 add_theme_support( 'wp-block-styles' ); … … 129 121 $wp_styles = $GLOBALS['wp_styles']; 130 122 131 $style_handle = "wp-block-{$name}-theme"; 123 foreach ( array_keys( $this->get_block_data() ) as $name ) { 124 $style_handle = "wp-block-{$name}-theme"; 132 125 133 $this->assertArrayHasKey( $style_handle, $wp_styles->registered, 'The key should exist, as this style should be registered' ); 134 if ( false === $wp_styles->registered[ $style_handle ]->src ) { 135 $this->assertEmpty( $wp_styles->registered[ $style_handle ]->extra, 'If source is false, style path should not be set' ); 136 } else { 137 $this->assertStringContainsString( $this->includes_url, $wp_styles->registered[ $style_handle ]->src, 'Source of style should contain the includes url' ); 138 $this->assertNotEmpty( $wp_styles->registered[ $style_handle ]->extra, 'The path of the style should exist' ); 139 $this->assertArrayHasKey( 'path', $wp_styles->registered[ $style_handle ]->extra, 'The path key of the style should exist in extra array' ); 140 $this->assertNotEmpty( $wp_styles->registered[ $style_handle ]->extra['path'], 'The path key of the style should not be empty' ); 126 $this->assertArrayHasKey( $style_handle, $wp_styles->registered, "Block {$name}: The key should exist, as this style should be registered" ); 127 if ( false === $wp_styles->registered[ $style_handle ]->src ) { 128 $this->assertEmpty( $wp_styles->registered[ $style_handle ]->extra, "Block {$name}: If source is false, style path should not be set" ); 129 } else { 130 $this->assertStringContainsString( $this->includes_url, $wp_styles->registered[ $style_handle ]->src, "Block {$name}: Source of style should contain the includes url" ); 131 $this->assertNotEmpty( $wp_styles->registered[ $style_handle ]->extra, "Block {$name}: The path of the style should exist" ); 132 $this->assertArrayHasKey( 'path', $wp_styles->registered[ $style_handle ]->extra, "Block {$name}: The path key of the style should exist in extra array" ); 133 $this->assertNotEmpty( $wp_styles->registered[ $style_handle ]->extra['path'], "Block {$name}: The path key of the style should not be empty" ); 134 } 141 135 } 142 136 } … … 144 138 /** 145 139 * @ticket 59715 146 *147 * @dataProvider data_block_data148 *149 * @param string $name The block name.150 140 */ 151 public function test_register_core_block_style_handles_should_load_rtl_stylesheets_for_rtl_text_direction( $name) {141 public function test_register_core_block_style_handles_should_load_rtl_stylesheets_for_rtl_text_direction() { 152 142 global $wp_locale; 153 143 … … 160 150 $wp_styles = $GLOBALS['wp_styles']; 161 151 162 $style_handle = "wp-block-{$name}-theme";163 164 152 $wp_locale->text_direction = $orig_text_dir; 165 153 166 $this->assertArrayHasKey( $style_handle, $wp_styles->registered, 'The key should exist, as this style should be registered' ); 167 if ( false === $wp_styles->registered[ $style_handle ]->src ) { 168 $this->assertEmpty( $wp_styles->registered[ $style_handle ]->extra, 'If source is false, style path should not be set' ); 169 } else { 170 $this->assertStringContainsString( $this->includes_url, $wp_styles->registered[ $style_handle ]->src, 'Source of style should contain the includes url' ); 171 $this->assertNotEmpty( $wp_styles->registered[ $style_handle ]->extra, 'The path of the style should exist' ); 172 $this->assertArrayHasKey( 'path', $wp_styles->registered[ $style_handle ]->extra, 'The path key of the style should exist in extra array' ); 173 $this->assertNotEmpty( $wp_styles->registered[ $style_handle ]->extra['path'], 'The path key of the style should not be empty' ); 174 $this->assertArrayHasKey( 'rtl', $wp_styles->registered[ $style_handle ]->extra, 'The rtl key of the style should exist in extra array' ); 154 foreach ( array_keys( $this->get_block_data() ) as $name ) { 155 $style_handle = "wp-block-{$name}-theme"; 156 157 $this->assertArrayHasKey( $style_handle, $wp_styles->registered, "Block {$name}: The key should exist, as this style should be registered" ); 158 if ( false === $wp_styles->registered[ $style_handle ]->src ) { 159 $this->assertEmpty( $wp_styles->registered[ $style_handle ]->extra, "Block {$name}: If source is false, style path should not be set" ); 160 } else { 161 $this->assertStringContainsString( $this->includes_url, $wp_styles->registered[ $style_handle ]->src, "Block {$name}: Source of style should contain the includes url" ); 162 $this->assertNotEmpty( $wp_styles->registered[ $style_handle ]->extra, "Block {$name}: The path of the style should exist" ); 163 $this->assertArrayHasKey( 'path', $wp_styles->registered[ $style_handle ]->extra, "Block {$name}: The path key of the style should exist in extra array" ); 164 $this->assertNotEmpty( $wp_styles->registered[ $style_handle ]->extra['path'], "Block {$name}: The path key of the style should not be empty" ); 165 $this->assertArrayHasKey( 'rtl', $wp_styles->registered[ $style_handle ]->extra, "Block {$name}: The rtl key of the style should exist in extra array" ); 166 } 175 167 } 176 168 } 177 169 178 public function data_block_data() { 170 /** 171 * Gets the blocks to check after registering styles once per scenario. 172 * 173 * @return array[] Block schemas keyed by block name. 174 */ 175 private function get_block_data() { 179 176 $core_blocks_meta = require ABSPATH . WPINC . '/blocks/blocks-json.php'; 180 177 … … 192 189 } 193 190 194 $data[ $name ] = array( $name, $schema );191 $data[ $name ] = $schema; 195 192 } 196 193
Note:
See TracChangeset
for help on using the changeset viewer.