Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block Types: Add metadata global attribute #5608

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/wp-includes/class-wp-block-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,13 @@ class WP_Block_Type {
/**
* Attributes supported by every block.
*
* @since 6.0.0
* @since 6.0.0 Added `lock`.
* @since 6.5.0 Added `metadata`.
* @var array
*/
const GLOBAL_ATTRIBUTES = array(
'lock' => array( 'type' => 'object' ),
'lock' => array( 'type' => 'object' ),
'metadata' => array( 'type' => 'object' ),
);

/**
Expand Down
3 changes: 2 additions & 1 deletion tests/phpunit/tests/admin/includesPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,8 @@ public function test_get_block_editor_server_block_settings() {
'description' => '',
'icon' => 'text',
'attributes' => array(
'lock' => array( 'type' => 'object' ),
'lock' => array( 'type' => 'object' ),
'metadata' => array( 'type' => 'object' ),
),
'usesContext' => array(),
'blockHooks' => array( 'core/post-content' => 'before' ),
Expand Down
6 changes: 4 additions & 2 deletions tests/phpunit/tests/blocks/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,7 @@ public function data_register_block_registers_with_args_override_returns_false_w
* @ticket 50263
* @ticket 50328
* @ticket 57585
* @ticket 59797
*/
public function test_block_registers_with_metadata_fixture() {
$result = register_block_type_from_metadata(
Expand All @@ -744,10 +745,11 @@ public function test_block_registers_with_metadata_fixture() {
$this->assertSameSets( array( 'alert', 'message' ), $result->keywords );
$this->assertSame(
array(
'message' => array(
'message' => array(
'type' => 'string',
),
'lock' => array( 'type' => 'object' ),
'lock' => array( 'type' => 'object' ),
'metadata' => array( 'type' => 'object' ),
),
$result->attributes
);
Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/tests/blocks/wpBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function test_constructor_assigns_properties_from_parsed_block() {

/**
* @ticket 49927
* @ticket 59797
*/
public function test_constructor_assigns_block_type_from_registry() {
$block_type_settings = array(
Expand All @@ -83,6 +84,7 @@ public function test_constructor_assigns_block_type_from_registry() {
'default' => 10,
),
'lock' => array( 'type' => 'object' ),
'metadata' => array( 'type' => 'object' ),
),
$block->block_type->attributes
);
Expand Down
13 changes: 10 additions & 3 deletions tests/phpunit/tests/blocks/wpBlockType.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,39 +80,46 @@ public function test_set_props() {

/*
* @ticket 55567
* @ticket 59797
* @covers WP_Block_Type::set_props
*/
public function test_core_attributes() {
$block_type = new WP_Block_Type( 'core/fake', array() );

$this->assertSameSetsWithIndex(
array(
'lock' => array( 'type' => 'object' ),
'lock' => array( 'type' => 'object' ),
'metadata' => array( 'type' => 'object' ),
),
$block_type->attributes
);
}

/*
* @ticket 55567
* @ticket 59797
* @covers WP_Block_Type::set_props
*/
public function test_core_attributes_matches_custom() {
$block_type = new WP_Block_Type(
'core/fake',
array(
'attributes' => array(
'lock' => array(
'lock' => array(
'type' => 'string',
),
'metadata' => array(
'type' => 'number',
),
),
)
);

// Backward compatibility: Don't override attributes with the same name.
$this->assertSameSetsWithIndex(
array(
'lock' => array( 'type' => 'string' ),
'lock' => array( 'type' => 'string' ),
'metadata' => array( 'type' => 'number' ),
),
$block_type->attributes
);
Expand Down
8 changes: 6 additions & 2 deletions tests/phpunit/tests/rest-api/rest-block-type-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ public function test_get_block_invalid_name() {
* @ticket 47620
* @ticket 57585
* @ticket 59346
* @ticket 59797
*/
public function test_get_item_invalid() {
$block_type = 'fake/invalid';
Expand Down Expand Up @@ -242,7 +243,8 @@ public function test_get_item_invalid() {
$this->assertNull( $data['textdomain'] );
$this->assertSameSetsWithIndex(
array(
'lock' => array( 'type' => 'object' ),
'lock' => array( 'type' => 'object' ),
'metadata' => array( 'type' => 'object' ),
),
$data['attributes']
);
Expand Down Expand Up @@ -272,6 +274,7 @@ public function test_get_item_invalid() {
* @ticket 47620
* @ticket 57585
* @ticket 59346
* @ticket 59797
*/
public function test_get_item_defaults() {
$block_type = 'fake/false';
Expand Down Expand Up @@ -316,7 +319,8 @@ public function test_get_item_defaults() {
$this->assertNull( $data['textdomain'] );
$this->assertSameSetsWithIndex(
array(
'lock' => array( 'type' => 'object' ),
'lock' => array( 'type' => 'object' ),
'metadata' => array( 'type' => 'object' ),
),
$data['attributes']
);
Expand Down
Loading