Skip to content

Commit

Permalink
Update DocBlocks, add ticket refs and assertion messages
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrobertshaw committed Mar 17, 2023
1 parent 635ffee commit 82d1762
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/wp-admin/includes/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -2178,6 +2178,7 @@ function taxonomy_meta_box_sanitize_cb_input( $taxonomy, $terms ) {
* of a block relevant for client registration.
*
* @since 5.0.0
* @since 6.3.0 Added `selectors` and `editor_selectors` fields.
*
* @return array An associative array of registered block data.
*/
Expand Down
1 change: 1 addition & 0 deletions src/wp-includes/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ function get_block_metadata_i18n_schema() {
* @since 5.7.0 Added support for `textdomain` field and i18n handling for all translatable fields.
* @since 5.9.0 Added support for `variations` and `viewScript` fields.
* @since 6.1.0 Added support for `render` field.
* @since 6.3.0 Added `selectors` and `editor_selectors` fields.
*
* @param string $file_or_folder Path to the JSON file with metadata definition for
* the block or path to the folder where the `block.json` file is located.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ public function get_item( $request ) {
*
* @since 5.5.0
* @since 5.9.0 Renamed `$block_type` to `$item` to match parent class for PHP 8 named parameter support.
* @since 6.3.0 Added `selectors` and `editor_selectors` fields.
*
* @param WP_Block_Type $item Block type data.
* @param WP_REST_Request $request Full details about the request.
Expand Down Expand Up @@ -381,6 +382,7 @@ protected function prepare_links( $block_type ) {
* Retrieves the block type' schema, conforming to JSON Schema.
*
* @since 5.5.0
* @since 6.3.0 Added `selectors` and `editor_selectors` fields.
*
* @return array Item schema data.
*/
Expand Down
9 changes: 7 additions & 2 deletions tests/phpunit/tests/blocks/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ public function test_metadata_not_found_in_the_current_directory() {
*
* @ticket 50263
* @ticket 50328
* @ticket 57585
*/
public function test_block_registers_with_metadata_fixture() {
$result = register_block_type_from_metadata(
Expand Down Expand Up @@ -515,13 +516,17 @@ public function test_block_registers_with_metadata_fixture() {
$result->provides_context
);
$this->assertSameSets( array( 'groupId' ), $result->uses_context );
// @ticket 57585
$this->assertSame(
array( 'root' => '.editor-only.wp-block-notice' ),
$result->editor_selectors
$result->editor_selectors,
'Block type should contain editor selectors from metadata.'
);
// @ticket 57585
$this->assertSame(
array( 'root' => '.wp-block-notice' ),
$result->selectors
$result->selectors,
'Block type should contain selectors from metadata.'
);
$this->assertSame(
array(
Expand Down
15 changes: 9 additions & 6 deletions tests/phpunit/tests/rest-api/rest-block-type-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ public function test_get_block_invalid_name() {

/**
* @ticket 47620
* @ticket 57585
*/
public function test_get_item_invalid() {
$block_type = 'fake/invalid';
Expand Down Expand Up @@ -249,8 +250,8 @@ public function test_get_item_invalid() {
$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['editor_selectors'] );
$this->assertSameSets( array(), $data['selectors'] );
$this->assertSameSets( array(), $data['editor_selectors'], 'invalid editor_selectors defaults to empty array' );
$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'] );
Expand All @@ -269,6 +270,7 @@ public function test_get_item_invalid() {

/**
* @ticket 47620
* @ticket 57585
*/
public function test_get_item_defaults() {
$block_type = 'fake/false';
Expand Down Expand Up @@ -322,8 +324,8 @@ public function test_get_item_defaults() {
$this->assertSameSets( array(), $data['keywords'] );
$this->assertSameSets( array(), $data['parent'] );
$this->assertSameSets( array(), $data['ancestor'] );
$this->assertSameSets( array(), $data['editor_selectors'] );
$this->assertSameSets( array(), $data['selectors'] );
$this->assertSameSets( array(), $data['editor_selectors'], 'editor_selectors defaults to empty array' );
$this->assertSameSets( array(), $data['selectors'], 'selectors defaults to empty array' );
$this->assertSameSets( array(), $data['supports'] );
$this->assertSameSets( array(), $data['styles'] );
$this->assertNull( $data['example'] );
Expand Down Expand Up @@ -542,6 +544,7 @@ public function test_get_variation() {

/**
* @ticket 47620
* @ticket 57585
*/
public function test_get_item_schema() {
wp_set_current_user( self::$admin_id );
Expand All @@ -559,8 +562,8 @@ public function test_get_item_schema() {
$this->assertArrayHasKey( 'textdomain', $properties );
$this->assertArrayHasKey( 'name', $properties );
$this->assertArrayHasKey( 'attributes', $properties );
$this->assertArrayHasKey( 'editor_selectors', $properties );
$this->assertArrayHasKey( 'selectors', $properties );
$this->assertArrayHasKey( 'editor_selectors', $properties, 'schema must contain editor_selectors' );
$this->assertArrayHasKey( 'selectors', $properties, 'schema must contain selectors' );
$this->assertArrayHasKey( 'supports', $properties );
$this->assertArrayHasKey( 'category', $properties );
$this->assertArrayHasKey( 'is_dynamic', $properties );
Expand Down

0 comments on commit 82d1762

Please sign in to comment.