Changeset 49981
- Timestamp:
- 01/19/2021 11:04:03 AM (4 years ago)
- Location:
- trunk
- Files:
-
- 7 added
- 1 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks.php
r49948 r49981 135 135 $script_asset['version'] 136 136 ); 137 return $result ? $script_handle : false; 137 if ( ! $result ) { 138 return false; 139 } 140 141 if ( ! empty( $metadata['textdomain'] ) ) { 142 wp_set_script_translations( $script_handle, $metadata['textdomain'] ); 143 } 144 145 return $script_handle; 138 146 } 139 147 … … 230 238 foreach ( $property_mappings as $key => $mapped_key ) { 231 239 if ( isset( $metadata[ $key ] ) ) { 232 $settings[ $mapped_key ] = $metadata[ $key ]; 240 $value = $metadata[ $key ]; 241 if ( empty( $metadata['textdomain'] ) ) { 242 $settings[ $mapped_key ] = $value; 243 continue; 244 } 245 $textdomain = $metadata['textdomain']; 246 switch ( $key ) { 247 case 'title': 248 case 'description': 249 // phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText,WordPress.WP.I18n.NonSingularStringLiteralContext,WordPress.WP.I18n.NonSingularStringLiteralDomain 250 $settings[ $mapped_key ] = translate_with_gettext_context( $value, sprintf( 'block %s', $key ), $textdomain ); 251 break; 252 case 'keywords': 253 $settings[ $mapped_key ] = array(); 254 if ( ! is_array( $value ) ) { 255 continue 2; 256 } 257 258 foreach ( $value as $keyword ) { 259 // phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText,WordPress.WP.I18n.NonSingularStringLiteralDomain 260 $settings[ $mapped_key ][] = translate_with_gettext_context( $keyword, 'block keyword', $textdomain ); 261 } 262 263 break; 264 case 'styles': 265 $settings[ $mapped_key ] = array(); 266 if ( ! is_array( $value ) ) { 267 continue 2; 268 } 269 270 foreach ( $value as $style ) { 271 if ( ! empty( $style['label'] ) ) { 272 // phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText,WordPress.WP.I18n.NonSingularStringLiteralDomain 273 $style['label'] = translate_with_gettext_context( $style['label'], 'block style label', $textdomain ); 274 } 275 $settings[ $mapped_key ][] = $style; 276 } 277 278 break; 279 default: 280 $settings[ $mapped_key ] = $value; 281 } 233 282 } 234 283 } -
trunk/tests/phpunit/tests/blocks/register.php
r49948 r49981 63 63 $registry = WP_Block_Type_Registry::get_instance(); 64 64 65 foreach ( array( 'core/test-static', 'core/test-dynamic', ' my-plugin/notice' ) as $block_name ) {65 foreach ( array( 'core/test-static', 'core/test-dynamic', 'tests/notice' ) as $block_name ) { 66 66 if ( $registry->is_registered( $block_name ) ) { 67 67 $registry->unregister( $block_name ); … … 194 194 'file' => __FILE__, 195 195 'name' => 'unit-tests/test-block', 196 'script' => 'file:./ fixtures/missing-asset.js',196 'script' => 'file:./blocks/notice/missing-asset.js', 197 197 ); 198 198 $result = register_block_script_handle( $metadata, 'script' ); … … 218 218 function test_success_register_block_script_handle() { 219 219 $metadata = array( 220 'file' => __FILE__,220 'file' => DIR_TESTDATA . '/blocks/notice/block.json', 221 221 'name' => 'unit-tests/test-block', 222 'script' => 'file:./ fixtures/block.js',222 'script' => 'file:./block.js', 223 223 ); 224 224 $result = register_block_script_handle( $metadata, 'script' ); … … 263 263 function test_success_register_block_style_handle() { 264 264 $metadata = array( 265 'file' => __FILE__,265 'file' => DIR_TESTDATA . '/blocks/notice/block.json', 266 266 'name' => 'unit-tests/test-block', 267 'style' => 'file:./ fixtures/block.css',267 'style' => 'file:./block.css', 268 268 ); 269 269 $result = register_block_style_handle( $metadata, 'style' ); … … 304 304 function test_block_registers_with_metadata_fixture() { 305 305 $result = register_block_type_from_metadata( 306 __DIR__ . '/fixtures'306 DIR_TESTDATA . '/blocks/notice' 307 307 ); 308 308 309 309 $this->assertInstanceOf( 'WP_Block_Type', $result ); 310 310 $this->assertSame( 2, $result->api_version ); 311 $this->assertSame( ' my-plugin/notice', $result->name );311 $this->assertSame( 'tests/notice', $result->name ); 312 312 $this->assertSame( 'Notice', $result->title ); 313 313 $this->assertSame( 'common', $result->category ); … … 328 328 $this->assertSame( 329 329 array( 330 ' my-plugin/message' => 'message',330 'tests/message' => 'message', 331 331 ), 332 332 $result->provides_context … … 362 362 $result->example 363 363 ); 364 $this->assertSame( 'my-plugin-notice-editor-script', $result->editor_script ); 365 $this->assertSame( 'my-plugin-notice-script', $result->script ); 366 $this->assertSame( 'my-plugin-notice-editor-style', $result->editor_style ); 367 $this->assertSame( 'my-plugin-notice-style', $result->style ); 364 $this->assertSame( 'tests-notice-editor-script', $result->editor_script ); 365 $this->assertSame( 'tests-notice-script', $result->script ); 366 $this->assertSame( 'tests-notice-editor-style', $result->editor_style ); 367 $this->assertSame( 'tests-notice-style', $result->style ); 368 } 369 370 /** 371 * @ticket 52301 372 */ 373 function test_block_registers_with_metadata_i18n_support() { 374 function filter_set_locale_to_polish() { 375 return 'pl_PL'; 376 } 377 add_filter( 'locale', 'filter_set_locale_to_polish' ); 378 load_textdomain( 'notice', WP_LANG_DIR . '/plugins/notice-pl_PL.mo' ); 379 380 $result = register_block_type_from_metadata( 381 DIR_TESTDATA . '/blocks/notice' 382 ); 383 384 unload_textdomain( 'notice' ); 385 remove_filter( 'locale', 'filter_set_locale_to_polish' ); 386 387 $this->assertInstanceOf( 'WP_Block_Type', $result ); 388 $this->assertSame( 'tests/notice', $result->name ); 389 $this->assertSame( 'Powiadomienie', $result->title ); 390 $this->assertSame( 'Wyświetla ostrzeżenie, błąd lub powiadomienie o sukcesie…', $result->description ); 391 $this->assertSameSets( array( 'ostrzeżenie', 'wiadomość' ), $result->keywords ); 392 $this->assertSame( 393 array( 394 array( 395 'name' => 'default', 396 'label' => 'Domyślny', 397 'isDefault' => true, 398 ), 399 array( 400 'name' => 'other', 401 'label' => 'Inny', 402 ), 403 ), 404 $result->styles 405 ); 368 406 } 369 407 … … 434 472 add_filter( 'block_type_metadata', $filter_metadata_registration, 10, 2 ); 435 473 $result = register_block_type_from_metadata( 436 __DIR__ . '/fixtures'474 DIR_TESTDATA . '/blocks/notice' 437 475 ); 438 476 remove_filter( 'block_type_metadata', $filter_metadata_registration ); … … 452 490 add_filter( 'block_type_metadata_settings', $filter_metadata_registration, 10, 2 ); 453 491 $result = register_block_type_from_metadata( 454 __DIR__ . '/fixtures'492 DIR_TESTDATA . '/blocks/notice' 455 493 ); 456 494 remove_filter( 'block_type_metadata_settings', $filter_metadata_registration );
Note: See TracChangeset
for help on using the changeset viewer.