Skip to content
Closed
Prev Previous commit
Next Next commit
Fix (and extend) block type controller test coverage
  • Loading branch information
ockham committed Sep 14, 2023
commit ad879ca909eee627e63bb501ba5ee574eca42a0e
12 changes: 11 additions & 1 deletion tests/phpunit/tests/rest-api/rest-block-type-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ public function test_get_block_invalid_name() {
/**
* @ticket 47620
* @ticket 57585
* @ticket 59346
*/
public function test_get_item_invalid() {
$block_type = 'fake/invalid';
Expand All @@ -205,6 +206,7 @@ public function test_get_item_invalid() {
'attributes' => 'invalid_attributes',
'provides_context' => 'invalid_provides_context',
'uses_context' => 'invalid_uses_context',
'block_hooks' => 'invalid_block_hooks',
'category' => true,
'editor_script' => true,
'script' => true,
Expand Down Expand Up @@ -244,6 +246,7 @@ public function test_get_item_invalid() {
$data['attributes']
);
$this->assertSameSets( array( 'invalid_uses_context' ), $data['uses_context'] );
$this->assertSameSets( array(), $data['block_hooks'], 'invalid block_hooks defaults to empty array' );
$this->assertSameSets( array( 'invalid_keywords' ), $data['keywords'] );
$this->assertSameSets( array( 'invalid_parent' ), $data['parent'] );
$this->assertSameSets( array( 'invalid_ancestor' ), $data['ancestor'] );
Expand All @@ -266,6 +269,7 @@ public function test_get_item_invalid() {
/**
* @ticket 47620
* @ticket 57585
* @ticket 59346
*/
public function test_get_item_defaults() {
$block_type = 'fake/false';
Expand All @@ -276,6 +280,7 @@ public function test_get_item_defaults() {
'attributes' => false,
'provides_context' => false,
'uses_context' => false,
'block_hooks' => false,
'category' => false,
'editor_script' => false,
'script' => false,
Expand Down Expand Up @@ -314,6 +319,7 @@ public function test_get_item_defaults() {
$data['attributes']
);
$this->assertSameSets( array(), $data['provides_context'] );
$this->assertSameSets( array(), $data['block_hooks'], 'block_hooks defaults to empty array' );
$this->assertSameSets( array(), $data['uses_context'] );
$this->assertSameSets( array(), $data['keywords'] );
$this->assertSameSets( array(), $data['parent'] );
Expand Down Expand Up @@ -538,14 +544,15 @@ public function test_get_variation() {
/**
* @ticket 47620
* @ticket 57585
* @ticket 59346
*/
public function test_get_item_schema() {
wp_set_current_user( self::$admin_id );
$request = new WP_REST_Request( 'OPTIONS', '/wp/v2/block-types' );
$response = rest_get_server()->dispatch( $request );
$data = $response->get_data();
$properties = $data['schema']['properties'];
$this->assertCount( 29, $properties );
$this->assertCount( 30, $properties );
$this->assertArrayHasKey( 'api_version', $properties );
$this->assertArrayHasKey( 'title', $properties );
$this->assertArrayHasKey( 'icon', $properties );
Expand All @@ -568,6 +575,7 @@ public function test_get_item_schema() {
$this->assertArrayHasKey( 'example', $properties );
$this->assertArrayHasKey( 'uses_context', $properties );
$this->assertArrayHasKey( 'provides_context', $properties );
$this->assertArrayHasKey( 'block_hooks', $properties );
$this->assertArrayHasKey( 'variations', $properties );
$this->assertArrayHasKey( 'ancestor', $properties );
// Deprecated properties.
Expand Down Expand Up @@ -664,6 +672,7 @@ public function test_prepare_item_limit_fields() {
* Util check block type object against.
*
* @since 5.5.0
* @since 6.4.0 Added the `block_hooks` extra field.
*
* @param WP_Block_Type $block_type Sample block type.
* @param array $data Data to compare against.
Expand All @@ -690,6 +699,7 @@ protected function check_block_type_object( $block_type, $data, $links ) {
'parent',
'provides_context',
'uses_context',
'block_hooks',
'supports',
'styles',
'textdomain',
Expand Down