WordPress.org

Make WordPress Core


Ignore:
Timestamp:
04/27/2018 03:05:40 AM (4 years ago)
Author:
pento
Message:

REST API: Include viewable attribute on Post Type resource for edit context

For the block editor to be able to expose the Preview button correctly, it needs to know the is_post_type_viewable() setting, this change adds it to the Post Type response.

Props danielbachhuber.
Fixes #43739.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-post-types-controller.php

    r42724 r43007  
    129129        $data       = $response->get_data();
    130130        $properties = $data['schema']['properties'];
    131         $this->assertEquals( 9, count( $properties ) );
     131        $this->assertEquals( 10, count( $properties ) );
    132132        $this->assertArrayHasKey( 'capabilities', $properties );
    133133        $this->assertArrayHasKey( 'description', $properties );
    134134        $this->assertArrayHasKey( 'hierarchical', $properties );
     135        $this->assertArrayHasKey( 'viewable', $properties );
    135136        $this->assertArrayHasKey( 'labels', $properties );
    136137        $this->assertArrayHasKey( 'name', $properties );
     
    192193            $this->assertEquals( $post_type_obj->cap, $data['capabilities'] );
    193194            $this->assertEquals( $post_type_obj->labels, $data['labels'] );
     195            if ( in_array( $post_type_obj->name, array( 'post', 'page' ), true ) ) {
     196                $viewable = true;
     197            } else {
     198                $viewable = is_post_type_viewable( $post_type_obj );
     199            }
     200            $this->assertEquals( $viewable, $data['viewable'] );
    194201            $this->assertEquals( get_all_post_type_supports( $post_type_obj->name ), $data['supports'] );
    195202        } else {
    196203            $this->assertFalse( isset( $data['capabilities'] ) );
     204            $this->assertFalse( isset( $data['viewable'] ) );
    197205            $this->assertFalse( isset( $data['labels'] ) );
    198206            $this->assertFalse( isset( $data['supports'] ) );
Note: See TracChangeset for help on using the changeset viewer.