Changeset 44127
- Timestamp:
- 12/14/2018 12:54:51 AM (6 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/5.0 merged: 43770
- Property svn:mergeinfo changed
-
trunk/src/wp-includes/blocks.php
r44118 r44127 263 263 return $rendered_content; 264 264 } 265 266 /** 267 * Returns the current version of the block format that the content string is using. 268 * 269 * If the string doesn't contain blocks, it returns 0. 270 * 271 * @since 5.0.0 272 * 273 * @param string $content Content to test. 274 * @return int The block format version. 275 */ 276 function block_version( $content ) { 277 return has_blocks( $content ) ? 1 : 0; 278 } -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
r43987 r44127 1522 1522 if ( in_array( 'content', $fields, true ) ) { 1523 1523 $data['content'] = array( 1524 'raw' => $post->post_content,1524 'raw' => $post->post_content, 1525 1525 /** This filter is documented in wp-includes/post-template.php */ 1526 'rendered' => post_password_required( $post ) ? '' : apply_filters( 'the_content', $post->post_content ), 1527 'protected' => (bool) $post->post_password, 1526 'rendered' => post_password_required( $post ) ? '' : apply_filters( 'the_content', $post->post_content ), 1527 'protected' => (bool) $post->post_password, 1528 'block_version' => block_version( $post->post_content ), 1528 1529 ); 1529 1530 } … … 2063 2064 ), 2064 2065 'properties' => array( 2065 'raw' => array(2066 'raw' => array( 2066 2067 'description' => __( 'Content for the object, as it exists in the database.' ), 2067 2068 'type' => 'string', 2068 2069 'context' => array( 'edit' ), 2069 2070 ), 2070 'rendered' => array(2071 'rendered' => array( 2071 2072 'description' => __( 'HTML content for the object, transformed for display.' ), 2072 2073 'type' => 'string', … … 2074 2075 'readonly' => true, 2075 2076 ), 2076 'protected' => array( 2077 'block_version' => array( 2078 'description' => __( 'Version of the content block format used by the object.' ), 2079 'type' => 'integer', 2080 'context' => array( 'edit' ), 2081 'readonly' => true, 2082 ), 2083 'protected' => array( 2077 2084 'description' => __( 'Whether the content is protected with a password.' ), 2078 2085 'type' => 'boolean', -
trunk/tests/phpunit/tests/blocks/block-type.php
r43742 r44127 311 311 return json_encode( $attributes ); 312 312 } 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 } 313 356 } -
trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php
r43981 r44127 1553 1553 $this->assertEquals( '', $data['excerpt']['rendered'] ); 1554 1554 $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'] ); 1555 1614 } 1556 1615 -
trunk/tests/qunit/fixtures/wp-api-generated.js
r44126 r44127 4351 4351 "date": "2017-02-14T00:00:00", 4352 4352 "date_gmt": "2017-02-14T00:00:00", 4353 "id": 3 6734,4353 "id": 3153, 4354 4354 "modified": "2017-02-14T00:00:00", 4355 4355 "modified_gmt": "2017-02-14T00:00:00", 4356 "parent": 3 6733,4357 "slug": "3 6733-revision-v1",4356 "parent": 3152, 4357 "slug": "3152-revision-v1", 4358 4358 "guid": { 4359 "rendered": "http://example.org/?p=3 6734"4359 "rendered": "http://example.org/?p=3153" 4360 4360 }, 4361 4361 "title": { … … 4371 4371 "parent": [ 4372 4372 { 4373 "href": "http://example.org/index.php?rest_route=/wp/v2/posts/3 6733"4373 "href": "http://example.org/index.php?rest_route=/wp/v2/posts/3152" 4374 4374 } 4375 4375 ] … … 4406 4406 "date": "2017-02-14T00:00:00", 4407 4407 "date_gmt": "2017-02-14T00:00:00", 4408 "id": 3 6735,4408 "id": 3154, 4409 4409 "modified": "2017-02-14T00:00:00", 4410 4410 "modified_gmt": "2017-02-14T00:00:00", 4411 "parent": 3 6733,4412 "slug": "3 6733-autosave-v1",4411 "parent": 3152, 4412 "slug": "3152-autosave-v1", 4413 4413 "guid": { 4414 "rendered": "http://example.org/?p=3 6735"4414 "rendered": "http://example.org/?p=3154" 4415 4415 }, 4416 4416 "title": { … … 4426 4426 "parent": [ 4427 4427 { 4428 "href": "http://example.org/index.php?rest_route=/wp/v2/posts/3 6733"4428 "href": "http://example.org/index.php?rest_route=/wp/v2/posts/3152" 4429 4429 } 4430 4430 ] … … 4437 4437 "date": "2017-02-14T00:00:00", 4438 4438 "date_gmt": "2017-02-14T00:00:00", 4439 "id": 3 6735,4439 "id": 3154, 4440 4440 "modified": "2017-02-14T00:00:00", 4441 4441 "modified_gmt": "2017-02-14T00:00:00", 4442 "parent": 3 6733,4443 "slug": "3 6733-autosave-v1",4442 "parent": 3152, 4443 "slug": "3152-autosave-v1", 4444 4444 "guid": { 4445 "rendered": "http://example.org/?p=3 6735"4445 "rendered": "http://example.org/?p=3154" 4446 4446 }, 4447 4447 "title": { … … 4611 4611 "date": "2017-02-14T00:00:00", 4612 4612 "date_gmt": "2017-02-14T00:00:00", 4613 "id": 3 6737,4613 "id": 3156, 4614 4614 "modified": "2017-02-14T00:00:00", 4615 4615 "modified_gmt": "2017-02-14T00:00:00", 4616 "parent": 3 6736,4617 "slug": "3 6736-revision-v1",4616 "parent": 3155, 4617 "slug": "3155-revision-v1", 4618 4618 "guid": { 4619 "rendered": "http://example.org/?p=3 6737"4619 "rendered": "http://example.org/?p=3156" 4620 4620 }, 4621 4621 "title": { … … 4631 4631 "parent": [ 4632 4632 { 4633 "href": "http://example.org/index.php?rest_route=/wp/v2/pages/3 6736"4633 "href": "http://example.org/index.php?rest_route=/wp/v2/pages/3155" 4634 4634 } 4635 4635 ] … … 4666 4666 "date": "2017-02-14T00:00:00", 4667 4667 "date_gmt": "2017-02-14T00:00:00", 4668 "id": 3 6738,4668 "id": 3157, 4669 4669 "modified": "2017-02-14T00:00:00", 4670 4670 "modified_gmt": "2017-02-14T00:00:00", 4671 "parent": 3 6736,4672 "slug": "3 6736-autosave-v1",4671 "parent": 3155, 4672 "slug": "3155-autosave-v1", 4673 4673 "guid": { 4674 "rendered": "http://example.org/?p=3 6738"4674 "rendered": "http://example.org/?p=3157" 4675 4675 }, 4676 4676 "title": { … … 4686 4686 "parent": [ 4687 4687 { 4688 "href": "http://example.org/index.php?rest_route=/wp/v2/pages/3 6736"4688 "href": "http://example.org/index.php?rest_route=/wp/v2/pages/3155" 4689 4689 } 4690 4690 ] … … 4697 4697 "date": "2017-02-14T00:00:00", 4698 4698 "date_gmt": "2017-02-14T00:00:00", 4699 "id": 3 6738,4699 "id": 3157, 4700 4700 "modified": "2017-02-14T00:00:00", 4701 4701 "modified_gmt": "2017-02-14T00:00:00", 4702 "parent": 3 6736,4703 "slug": "3 6736-autosave-v1",4702 "parent": 3155, 4703 "slug": "3155-autosave-v1", 4704 4704 "guid": { 4705 "rendered": "http://example.org/?p=3 6738"4705 "rendered": "http://example.org/?p=3157" 4706 4706 }, 4707 4707 "title": {
Note: See TracChangeset
for help on using the changeset viewer.