WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/19/2018 05:57:38 PM (22 months ago)
Author:
danielbachhuber
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.

Props danielbachhuber, birgire.
Fixes #43887.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/5.0/tests/phpunit/tests/rest-api/rest-posts-controller.php

    r43732 r43770  
    13311331        $this->assertEquals( '', $data['excerpt']['rendered'] );
    13321332        $this->assertTrue( $data['excerpt']['protected'] );
     1333    }
     1334
     1335    /**
     1336     * The post response should not have `block_version` when in view context.
     1337     *
     1338     * @ticket 43887
     1339     */
     1340    public function test_get_post_should_not_have_block_version_when_context_view() {
     1341        $post_id = $this->factory->post->create(
     1342            array(
     1343                'post_content' => '<!-- wp:core/separator -->',
     1344            )
     1345        );
     1346
     1347        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) );
     1348        $response = rest_get_server()->dispatch( $request );
     1349        $data = $response->get_data();
     1350        $this->assertFalse( isset( $data['content']['block_version'] ) );
     1351    }
     1352
     1353    /**
     1354     * The post response should have `block_version` indicate that block content is present when in edit context.
     1355     *
     1356     * @ticket 43887
     1357     */
     1358    public function test_get_post_should_have_block_version_indicate_block_content_when_context_edit() {
     1359        wp_set_current_user( self::$editor_id );
     1360
     1361        $post_id = $this->factory->post->create(
     1362            array(
     1363                'post_content' => '<!-- wp:core/separator -->',
     1364            )
     1365        );
     1366
     1367        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) );
     1368        $request->set_param( 'context', 'edit' );
     1369        $response = rest_get_server()->dispatch( $request );
     1370        $data = $response->get_data();
     1371        $this->assertSame( 1, $data['content']['block_version'] );
     1372    }
     1373   
     1374    /**
     1375     * The post response should have `block_version` indicate that no block content is present when in edit context.
     1376     *
     1377     * @ticket 43887
     1378     */
     1379    public function test_get_post_should_have_block_version_indicate_no_block_content_when_context_edit() {
     1380        wp_set_current_user( self::$editor_id );
     1381
     1382        $post_id = $this->factory->post->create(
     1383            array(
     1384                'post_content' => '<hr />',
     1385            )
     1386        );
     1387        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) );
     1388        $request->set_param( 'context', 'edit' );
     1389        $response = rest_get_server()->dispatch( $request );
     1390        $data = $response->get_data();
     1391        $this->assertSame( 0, $data['content']['block_version'] );
    13331392    }
    13341393
Note: See TracChangeset for help on using the changeset viewer.