Changeset 53268
- Timestamp:
- 04/26/2022 09:48:20 AM (3 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-block-type.php
r53084 r53268 204 204 */ 205 205 public $style = null; 206 207 /** 208 * Attributes supported by every block. 209 * 210 * @since 6.0.0 211 * @var array 212 */ 213 const GLOBAL_ATTRIBUTES = array( 214 'lock' => array( 'type' => 'object' ), 215 ); 206 216 207 217 /** … … 356 366 $args['name'] = $this->name; 357 367 368 // Setup attributes if needed. 369 if ( ! isset( $args['attributes'] ) || ! is_array( $args['attributes'] ) ) { 370 $args['attributes'] = array(); 371 } 372 373 // Register core attributes. 374 foreach ( static::GLOBAL_ATTRIBUTES as $attr_key => $attr_schema ) { 375 if ( ! array_key_exists( $attr_key, $args['attributes'] ) ) { 376 $args['attributes'][ $attr_key ] = $attr_schema; 377 } 378 } 379 358 380 /** 359 381 * Filters the arguments for registering a block type. -
trunk/tests/phpunit/tests/admin/includesPost.php
r53084 r53268 845 845 'description' => '', 846 846 'icon' => 'text', 847 'attributes' => array( 848 'lock' => array( 'type' => 'object' ), 849 ), 847 850 'usesContext' => array(), 848 851 'category' => 'common', -
trunk/tests/phpunit/tests/blocks/register.php
r53091 r53268 393 393 'selector' => '.message', 394 394 ), 395 'lock' => array( 'type' => 'object' ), 395 396 ), 396 397 $result->attributes -
trunk/tests/phpunit/tests/blocks/wpBlock.php
r53152 r53268 83 83 84 84 $this->assertInstanceOf( WP_Block_Type::class, $block->block_type ); 85 $this->assertSame( 86 $block_type_settings['attributes'], 85 $this->assertSameSetsWithIndex( 86 array( 87 'defaulted' => array( 88 'type' => 'number', 89 'default' => 10, 90 ), 91 'lock' => array( 'type' => 'object' ), 92 ), 87 93 $block->block_type->attributes 88 94 ); -
trunk/tests/phpunit/tests/blocks/wpBlockType.php
r52010 r53268 83 83 $this->assertSame( $args['render_callback'], $block_type->render_callback ); 84 84 $this->assertSame( $args['foo'], $block_type->foo ); 85 } 86 87 /* 88 * @ticket 55567 89 * @covers WP_Block_Type::set_props 90 */ 91 public function test_core_attributes() { 92 $block_type = new WP_Block_Type( 'core/fake', array() ); 93 94 $this->assertSameSetsWithIndex( 95 array( 96 'lock' => array( 'type' => 'object' ), 97 ), 98 $block_type->attributes 99 ); 100 } 101 102 /* 103 * @ticket 55567 104 * @covers WP_Block_Type::set_props 105 */ 106 public function test_core_attributes_matches_custom() { 107 $block_type = new WP_Block_Type( 108 'core/fake', 109 array( 110 'attributes' => array( 111 'lock' => array( 112 'type' => 'string', 113 ), 114 ), 115 ) 116 ); 117 118 // Backward compatibility: Don't override attributes with the same name. 119 $this->assertSameSetsWithIndex( 120 array( 121 'lock' => array( 'type' => 'string' ), 122 ), 123 $block_type->attributes 124 ); 85 125 } 86 126 -
trunk/tests/phpunit/tests/rest-api/rest-block-type-controller.php
r53084 r53268 244 244 $this->assertNull( $data['style'] ); 245 245 $this->assertSameSets( array(), $data['provides_context'] ); 246 $this->assertSameSets( array(), $data['attributes'] ); 246 $this->assertSameSetsWithIndex( 247 array( 248 'lock' => array( 'type' => 'object' ), 249 ), 250 $data['attributes'] 251 ); 247 252 $this->assertSameSets( array( 'invalid_uses_context' ), $data['uses_context'] ); 248 253 $this->assertSameSets( array( 'invalid_keywords' ), $data['keywords'] ); … … 300 305 $this->assertNull( $data['editor_style'] ); 301 306 $this->assertNull( $data['style'] ); 302 $this->assertSameSets( array(), $data['attributes'] ); 307 $this->assertSameSetsWithIndex( 308 array( 309 'lock' => array( 'type' => 'object' ), 310 ), 311 $data['attributes'] 312 ); 303 313 $this->assertSameSets( array(), $data['provides_context'] ); 304 314 $this->assertSameSets( array(), $data['uses_context'] );
Note: See TracChangeset
for help on using the changeset viewer.