Make WordPress Core


Ignore:
Timestamp:
12/14/2018 12:54:51 AM (6 years ago)
Author:
pento
Message:

REST API: Include block_version on Post content object.

The block_version denotes which version of Blocks the post_content contains. Introduces new block_version() function for versioning Blocks.

Merges [43770] from the 5.0 branch to trunk.

Props danielbachhuber, birgire.
Fixes #43887.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php

    r43981 r44127  
    15531553        $this->assertEquals( '', $data['excerpt']['rendered'] );
    15541554        $this->assertTrue( $data['excerpt']['protected'] );
     1555    }
     1556
     1557    /**
     1558     * The post response should not have `block_version` when in view context.
     1559     *
     1560     * @ticket 43887
     1561     */
     1562    public function test_get_post_should_not_have_block_version_when_context_view() {
     1563        $post_id = $this->factory->post->create(
     1564            array(
     1565                'post_content' => '<!-- wp:core/separator -->',
     1566            )
     1567        );
     1568
     1569        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) );
     1570        $response = rest_get_server()->dispatch( $request );
     1571        $data     = $response->get_data();
     1572        $this->assertFalse( isset( $data['content']['block_version'] ) );
     1573    }
     1574
     1575    /**
     1576     * The post response should have `block_version` indicate that block content is present when in edit context.
     1577     *
     1578     * @ticket 43887
     1579     */
     1580    public function test_get_post_should_have_block_version_indicate_block_content_when_context_edit() {
     1581        wp_set_current_user( self::$editor_id );
     1582
     1583        $post_id = $this->factory->post->create(
     1584            array(
     1585                'post_content' => '<!-- wp:core/separator -->',
     1586            )
     1587        );
     1588
     1589        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) );
     1590        $request->set_param( 'context', 'edit' );
     1591        $response = rest_get_server()->dispatch( $request );
     1592        $data     = $response->get_data();
     1593        $this->assertSame( 1, $data['content']['block_version'] );
     1594    }
     1595
     1596    /**
     1597     * The post response should have `block_version` indicate that no block content is present when in edit context.
     1598     *
     1599     * @ticket 43887
     1600     */
     1601    public function test_get_post_should_have_block_version_indicate_no_block_content_when_context_edit() {
     1602        wp_set_current_user( self::$editor_id );
     1603
     1604        $post_id = $this->factory->post->create(
     1605            array(
     1606                'post_content' => '<hr />',
     1607            )
     1608        );
     1609        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) );
     1610        $request->set_param( 'context', 'edit' );
     1611        $response = rest_get_server()->dispatch( $request );
     1612        $data     = $response->get_data();
     1613        $this->assertSame( 0, $data['content']['block_version'] );
    15551614    }
    15561615
Note: See TracChangeset for help on using the changeset viewer.