Make WordPress Core


Ignore:
Timestamp:
10/19/2018 05:57:38 PM (8 years 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/blocks/block-type.php

    r43742 r43770  
    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.