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/blocks/block-type.php

    r43742 r44127  
    311311        return json_encode( $attributes );
    312312    }
     313
     314    /**
     315     * Testing the block version.
     316     *
     317     * @ticket 43887
     318     *
     319     * @dataProvider data_block_version
     320     *
     321     * @param string|null $content  Content.
     322     * @param int         $expected Expected block version.
     323     */
     324    public function test_block_version( $content, $expected ) {
     325        $this->assertSame( $expected, block_version( $content ) );
     326    }
     327
     328    /**
     329     * Test cases for test_block_version().
     330     *
     331     * @since 5.0.0
     332     *
     333     * @return array {
     334     *     @type array {
     335     *         @type string|null Content.
     336     *         @type int         Expected block version.
     337     *     }
     338     * }
     339     */
     340    public function data_block_version() {
     341        return array(
     342            // Null.
     343            array( null, 0 ),
     344            // Empty post content.
     345            array( '', 0 ),
     346            // Post content without blocks.
     347            array( '<hr class="wp-block-separator" />', 0 ),
     348            // Post content with a block.
     349            array( '<!-- wp:core/separator -->', 1 ),
     350            // Post content with a fake block.
     351            array( '<!-- wp:core/fake --><!-- /wp:core/fake -->', 1 ),
     352            // Post content with an invalid block.
     353            array( '<!- - wp:core/separator -->', 0 ),
     354        );
     355    }
    313356}
Note: See TracChangeset for help on using the changeset viewer.