From 4b3bd68a2bbe7e4dde1cade6c057b118aca4de6a Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 1 Nov 2023 17:27:57 +0100 Subject: [PATCH 1/7] Block Types: Add metadata global attribute --- src/wp-includes/class-wp-block-type.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/class-wp-block-type.php b/src/wp-includes/class-wp-block-type.php index b8ffb92e559b2..73bd1fd304a2f 100644 --- a/src/wp-includes/class-wp-block-type.php +++ b/src/wp-includes/class-wp-block-type.php @@ -243,10 +243,12 @@ class WP_Block_Type { * Attributes supported by every block. * * @since 6.0.0 + * @since 6.5.0 Added metadata global attribute. * @var array */ const GLOBAL_ATTRIBUTES = array( - 'lock' => array( 'type' => 'object' ), + 'lock' => array( 'type' => 'object' ), + 'metadata' => array( 'type' => 'object' ), ); /** From 37468aea9bcec8d14ea6d9fec675cc73ca7630b0 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 2 Nov 2023 15:56:33 +0100 Subject: [PATCH 2/7] Attempt to fix tests --- tests/phpunit/tests/admin/includesPost.php | 3 ++- tests/phpunit/tests/blocks/register.php | 5 +++-- tests/phpunit/tests/blocks/wpBlock.php | 1 + tests/phpunit/tests/blocks/wpBlockType.php | 9 +++++++-- .../tests/rest-api/rest-block-type-controller.php | 6 ++++-- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/tests/phpunit/tests/admin/includesPost.php b/tests/phpunit/tests/admin/includesPost.php index 5b07f23568b9d..dcf0a4952f4b5 100644 --- a/tests/phpunit/tests/admin/includesPost.php +++ b/tests/phpunit/tests/admin/includesPost.php @@ -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' ), diff --git a/tests/phpunit/tests/blocks/register.php b/tests/phpunit/tests/blocks/register.php index 525d7498ae300..7c8950c4c9987 100644 --- a/tests/phpunit/tests/blocks/register.php +++ b/tests/phpunit/tests/blocks/register.php @@ -744,10 +744,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 ); diff --git a/tests/phpunit/tests/blocks/wpBlock.php b/tests/phpunit/tests/blocks/wpBlock.php index dcafe53378ef3..2e9a6e633ff9b 100644 --- a/tests/phpunit/tests/blocks/wpBlock.php +++ b/tests/phpunit/tests/blocks/wpBlock.php @@ -83,6 +83,7 @@ public function test_constructor_assigns_block_type_from_registry() { 'default' => 10, ), 'lock' => array( 'type' => 'object' ), + 'metadata' => array( 'type' => 'object' ), ), $block->block_type->attributes ); diff --git a/tests/phpunit/tests/blocks/wpBlockType.php b/tests/phpunit/tests/blocks/wpBlockType.php index 330d082bc2f1c..69c9acbcb6557 100644 --- a/tests/phpunit/tests/blocks/wpBlockType.php +++ b/tests/phpunit/tests/blocks/wpBlockType.php @@ -87,7 +87,8 @@ public function test_core_attributes() { $this->assertSameSetsWithIndex( array( - 'lock' => array( 'type' => 'object' ), + 'lock' => array( 'type' => 'object' ), + 'metadata' => array( 'type' => 'object' ), ), $block_type->attributes ); @@ -105,6 +106,9 @@ public function test_core_attributes_matches_custom() { 'lock' => array( 'type' => 'string', ), + 'metadata' => array( + 'type' => 'number', + ) ), ) ); @@ -112,7 +116,8 @@ public function test_core_attributes_matches_custom() { // 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 ); diff --git a/tests/phpunit/tests/rest-api/rest-block-type-controller.php b/tests/phpunit/tests/rest-api/rest-block-type-controller.php index 2745b61195863..838221f796fa6 100644 --- a/tests/phpunit/tests/rest-api/rest-block-type-controller.php +++ b/tests/phpunit/tests/rest-api/rest-block-type-controller.php @@ -242,7 +242,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'] ); @@ -316,7 +317,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'] ); From 7c95590880c5e56dad40bac03c603ce4caf85c5c Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 2 Nov 2023 17:25:46 +0100 Subject: [PATCH 3/7] Trailing comma --- tests/phpunit/tests/blocks/wpBlockType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/blocks/wpBlockType.php b/tests/phpunit/tests/blocks/wpBlockType.php index 69c9acbcb6557..e4f91a02359c8 100644 --- a/tests/phpunit/tests/blocks/wpBlockType.php +++ b/tests/phpunit/tests/blocks/wpBlockType.php @@ -108,7 +108,7 @@ public function test_core_attributes_matches_custom() { ), 'metadata' => array( 'type' => 'number', - ) + ), ), ) ); From e372252de8071680a41f5f2bd27284d473ab29f8 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 2 Nov 2023 17:36:50 +0100 Subject: [PATCH 4/7] Add ticket references to tests --- tests/phpunit/tests/blocks/register.php | 1 + tests/phpunit/tests/blocks/wpBlock.php | 1 + tests/phpunit/tests/blocks/wpBlockType.php | 2 ++ tests/phpunit/tests/rest-api/rest-block-type-controller.php | 2 ++ 4 files changed, 6 insertions(+) diff --git a/tests/phpunit/tests/blocks/register.php b/tests/phpunit/tests/blocks/register.php index 7c8950c4c9987..012171e38acfe 100644 --- a/tests/phpunit/tests/blocks/register.php +++ b/tests/phpunit/tests/blocks/register.php @@ -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( diff --git a/tests/phpunit/tests/blocks/wpBlock.php b/tests/phpunit/tests/blocks/wpBlock.php index 2e9a6e633ff9b..f3edcb8302d81 100644 --- a/tests/phpunit/tests/blocks/wpBlock.php +++ b/tests/phpunit/tests/blocks/wpBlock.php @@ -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( diff --git a/tests/phpunit/tests/blocks/wpBlockType.php b/tests/phpunit/tests/blocks/wpBlockType.php index e4f91a02359c8..d86276adb5279 100644 --- a/tests/phpunit/tests/blocks/wpBlockType.php +++ b/tests/phpunit/tests/blocks/wpBlockType.php @@ -80,6 +80,7 @@ public function test_set_props() { /* * @ticket 55567 + * @ticket 59797 * @covers WP_Block_Type::set_props */ public function test_core_attributes() { @@ -96,6 +97,7 @@ public function test_core_attributes() { /* * @ticket 55567 + * @ticket 59797 * @covers WP_Block_Type::set_props */ public function test_core_attributes_matches_custom() { diff --git a/tests/phpunit/tests/rest-api/rest-block-type-controller.php b/tests/phpunit/tests/rest-api/rest-block-type-controller.php index 838221f796fa6..8b49d2c034a20 100644 --- a/tests/phpunit/tests/rest-api/rest-block-type-controller.php +++ b/tests/phpunit/tests/rest-api/rest-block-type-controller.php @@ -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'; @@ -273,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'; From 5e9d4e36adc4851885e20ce88ef2a8758dd9f8c7 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 2 Nov 2023 17:40:53 +0100 Subject: [PATCH 5/7] Whitespace --- tests/phpunit/tests/blocks/wpBlockType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/blocks/wpBlockType.php b/tests/phpunit/tests/blocks/wpBlockType.php index d86276adb5279..d2c7a13e6b345 100644 --- a/tests/phpunit/tests/blocks/wpBlockType.php +++ b/tests/phpunit/tests/blocks/wpBlockType.php @@ -105,7 +105,7 @@ public function test_core_attributes_matches_custom() { 'core/fake', array( 'attributes' => array( - 'lock' => array( + 'lock' => array( 'type' => 'string', ), 'metadata' => array( From 95edef88f36b7b71bb51a943318639e03066af13 Mon Sep 17 00:00:00 2001 From: Bernie Reiter <96308+ockham@users.noreply.github.com> Date: Mon, 6 Nov 2023 15:07:02 +0100 Subject: [PATCH 6/7] Add note about lock attribute in PHPDoc. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Greg Ziółkowski --- src/wp-includes/class-wp-block-type.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/class-wp-block-type.php b/src/wp-includes/class-wp-block-type.php index 73bd1fd304a2f..423dc85f60ce3 100644 --- a/src/wp-includes/class-wp-block-type.php +++ b/src/wp-includes/class-wp-block-type.php @@ -242,7 +242,7 @@ class WP_Block_Type { /** * Attributes supported by every block. * - * @since 6.0.0 + * @since 6.0.0 Added lock global attribute. * @since 6.5.0 Added metadata global attribute. * @var array */ From c9d8c0876c48df0bb14190f5c229d3e7dc668630 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 6 Nov 2023 15:12:57 +0100 Subject: [PATCH 7/7] Rephrase PHPDoc a bit --- src/wp-includes/class-wp-block-type.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/class-wp-block-type.php b/src/wp-includes/class-wp-block-type.php index 423dc85f60ce3..b783a80c4bd82 100644 --- a/src/wp-includes/class-wp-block-type.php +++ b/src/wp-includes/class-wp-block-type.php @@ -242,8 +242,8 @@ class WP_Block_Type { /** * Attributes supported by every block. * - * @since 6.0.0 Added lock global attribute. - * @since 6.5.0 Added metadata global attribute. + * @since 6.0.0 Added `lock`. + * @since 6.5.0 Added `metadata`. * @var array */ const GLOBAL_ATTRIBUTES = array(