mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
Editor: Add selectors field to block type definition
Adds support for the new selectors property for block types. It adds it to the allowed metadata when registering a block type, makes the WP_Block_Type class aware of it, exposes it through the block types REST API, and the get_block_editor_server_block_settings function. Corresponding work in the Gutenberg plugin: https://github.com/WordPress/gutenberg/pull/46496. Fixes #57585. Props aaronrobertshaw, hellofromTonya. git-svn-id: https://develop.svn.wordpress.org/trunk@55673 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -27,6 +27,9 @@
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"selectors": {
|
||||
"root": ".wp-block-notice"
|
||||
},
|
||||
"supports": {
|
||||
"align": true,
|
||||
"lightBlockWrapper": true
|
||||
|
||||
@@ -826,6 +826,7 @@ class Tests_Admin_IncludesPost extends WP_UnitTestCase {
|
||||
'category' => 'common',
|
||||
'render_callback' => 'foo',
|
||||
'ancestor' => array( 'core/test-ancestor' ),
|
||||
'selectors' => array( 'root' => '.wp-block-test' ),
|
||||
);
|
||||
|
||||
register_block_type( $name, $settings );
|
||||
@@ -845,6 +846,7 @@ class Tests_Admin_IncludesPost extends WP_UnitTestCase {
|
||||
'lock' => array( 'type' => 'object' ),
|
||||
),
|
||||
'usesContext' => array(),
|
||||
'selectors' => array( 'root' => '.wp-block-test' ),
|
||||
'category' => 'common',
|
||||
'styles' => array(),
|
||||
'ancestor' => array( 'core/test-ancestor' ),
|
||||
|
||||
@@ -483,6 +483,7 @@ class Tests_Blocks_Register extends WP_UnitTestCase {
|
||||
*
|
||||
* @ticket 50263
|
||||
* @ticket 50328
|
||||
* @ticket 57585
|
||||
*/
|
||||
public function test_block_registers_with_metadata_fixture() {
|
||||
$result = register_block_type_from_metadata(
|
||||
@@ -515,6 +516,12 @@ class Tests_Blocks_Register extends WP_UnitTestCase {
|
||||
$result->provides_context
|
||||
);
|
||||
$this->assertSameSets( array( 'groupId' ), $result->uses_context );
|
||||
// @ticket 57585
|
||||
$this->assertSame(
|
||||
array( 'root' => '.wp-block-notice' ),
|
||||
$result->selectors,
|
||||
'Block type should contain selectors from metadata.'
|
||||
);
|
||||
$this->assertSame(
|
||||
array(
|
||||
'align' => true,
|
||||
|
||||
@@ -196,6 +196,7 @@ class REST_Block_Type_Controller_Test extends WP_Test_REST_Controller_Testcase {
|
||||
|
||||
/**
|
||||
* @ticket 47620
|
||||
* @ticket 57585
|
||||
*/
|
||||
public function test_get_item_invalid() {
|
||||
$block_type = 'fake/invalid';
|
||||
@@ -216,6 +217,7 @@ class REST_Block_Type_Controller_Test extends WP_Test_REST_Controller_Testcase {
|
||||
'example' => 'invalid_example',
|
||||
'parent' => 'invalid_parent',
|
||||
'ancestor' => 'invalid_ancestor',
|
||||
'selectors' => 'invalid_selectors',
|
||||
'supports' => 'invalid_supports',
|
||||
'styles' => array(),
|
||||
'render_callback' => 'invalid_callback',
|
||||
@@ -247,6 +249,7 @@ class REST_Block_Type_Controller_Test extends WP_Test_REST_Controller_Testcase {
|
||||
$this->assertSameSets( array( 'invalid_keywords' ), $data['keywords'] );
|
||||
$this->assertSameSets( array( 'invalid_parent' ), $data['parent'] );
|
||||
$this->assertSameSets( array( 'invalid_ancestor' ), $data['ancestor'] );
|
||||
$this->assertSameSets( array(), $data['selectors'], 'invalid selectors defaults to empty array' );
|
||||
$this->assertSameSets( array(), $data['supports'] );
|
||||
$this->assertSameSets( array(), $data['styles'] );
|
||||
$this->assertNull( $data['example'] );
|
||||
@@ -265,6 +268,7 @@ class REST_Block_Type_Controller_Test extends WP_Test_REST_Controller_Testcase {
|
||||
|
||||
/**
|
||||
* @ticket 47620
|
||||
* @ticket 57585
|
||||
*/
|
||||
public function test_get_item_defaults() {
|
||||
$block_type = 'fake/false';
|
||||
@@ -284,6 +288,7 @@ class REST_Block_Type_Controller_Test extends WP_Test_REST_Controller_Testcase {
|
||||
'keywords' => false,
|
||||
'parent' => false,
|
||||
'ancestor' => false,
|
||||
'selectors' => false,
|
||||
'supports' => false,
|
||||
'styles' => false,
|
||||
'render_callback' => false,
|
||||
@@ -316,6 +321,7 @@ class REST_Block_Type_Controller_Test extends WP_Test_REST_Controller_Testcase {
|
||||
$this->assertSameSets( array(), $data['keywords'] );
|
||||
$this->assertSameSets( array(), $data['parent'] );
|
||||
$this->assertSameSets( array(), $data['ancestor'] );
|
||||
$this->assertSameSets( array(), $data['selectors'], 'selectors defaults to empty array' );
|
||||
$this->assertSameSets( array(), $data['supports'] );
|
||||
$this->assertSameSets( array(), $data['styles'] );
|
||||
$this->assertNull( $data['example'] );
|
||||
@@ -534,6 +540,7 @@ class REST_Block_Type_Controller_Test extends WP_Test_REST_Controller_Testcase {
|
||||
|
||||
/**
|
||||
* @ticket 47620
|
||||
* @ticket 57585
|
||||
*/
|
||||
public function test_get_item_schema() {
|
||||
wp_set_current_user( self::$admin_id );
|
||||
@@ -541,7 +548,7 @@ class REST_Block_Type_Controller_Test extends WP_Test_REST_Controller_Testcase {
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$properties = $data['schema']['properties'];
|
||||
$this->assertCount( 28, $properties );
|
||||
$this->assertCount( 29, $properties );
|
||||
$this->assertArrayHasKey( 'api_version', $properties );
|
||||
$this->assertArrayHasKey( 'title', $properties );
|
||||
$this->assertArrayHasKey( 'icon', $properties );
|
||||
@@ -551,6 +558,7 @@ class REST_Block_Type_Controller_Test extends WP_Test_REST_Controller_Testcase {
|
||||
$this->assertArrayHasKey( 'textdomain', $properties );
|
||||
$this->assertArrayHasKey( 'name', $properties );
|
||||
$this->assertArrayHasKey( 'attributes', $properties );
|
||||
$this->assertArrayHasKey( 'selectors', $properties, 'schema must contain selectors' );
|
||||
$this->assertArrayHasKey( 'supports', $properties );
|
||||
$this->assertArrayHasKey( 'category', $properties );
|
||||
$this->assertArrayHasKey( 'is_dynamic', $properties );
|
||||
|
||||
Reference in New Issue
Block a user