Changeset 43770 for branches/5.0
- Timestamp:
- 10/19/2018 05:57:38 PM (6 years ago)
- Location:
- branches/5.0
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/5.0/src/wp-includes/blocks.php
r43752 r43770 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 } -
branches/5.0/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
r43737 r43770 1510 1510 if ( in_array( 'content', $fields, true ) ) { 1511 1511 $data['content'] = array( 1512 'raw' => $post->post_content,1512 'raw' => $post->post_content, 1513 1513 /** This filter is documented in wp-includes/post-template.php */ 1514 'rendered' => post_password_required( $post ) ? '' : apply_filters( 'the_content', $post->post_content ), 1515 'protected' => (bool) $post->post_password, 1514 'rendered' => post_password_required( $post ) ? '' : apply_filters( 'the_content', $post->post_content ), 1515 'protected' => (bool) $post->post_password, 1516 'block_version' => block_version( $post->post_content ), 1516 1517 ); 1517 1518 } … … 2063 2064 'readonly' => true, 2064 2065 ), 2066 'block_version' => array( 2067 'description' => __( 'Version of the content block format used by the object.' ), 2068 'type' => 'integer', 2069 'context' => array( 'edit' ), 2070 'readonly' => true, 2071 ), 2065 2072 'protected' => array( 2066 2073 'description' => __( 'Whether the content is protected with a password.' ), -
branches/5.0/tests/phpunit/tests/blocks/block-type.php
r43742 r43770 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 } -
branches/5.0/tests/phpunit/tests/rest-api/rest-posts-controller.php
r43732 r43770 1331 1331 $this->assertEquals( '', $data['excerpt']['rendered'] ); 1332 1332 $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'] ); 1333 1392 } 1334 1393 -
branches/5.0/tests/qunit/fixtures/wp-api-generated.js
r43768 r43770 4343 4343 "date": "2017-02-14T00:00:00", 4344 4344 "date_gmt": "2017-02-14T00:00:00", 4345 "id": 367 07,4345 "id": 36710, 4346 4346 "modified": "2017-02-14T00:00:00", 4347 4347 "modified_gmt": "2017-02-14T00:00:00", 4348 "parent": 3670 6,4349 "slug": "3670 6-revision-v1",4348 "parent": 36709, 4349 "slug": "36709-revision-v1", 4350 4350 "guid": { 4351 "rendered": "http://example.org/?p=367 07"4351 "rendered": "http://example.org/?p=36710" 4352 4352 }, 4353 4353 "title": { … … 4363 4363 "parent": [ 4364 4364 { 4365 "href": "http://example.org/index.php?rest_route=/wp/v2/posts/3670 6"4365 "href": "http://example.org/index.php?rest_route=/wp/v2/posts/36709" 4366 4366 } 4367 4367 ] … … 4398 4398 "date": "2017-02-14T00:00:00", 4399 4399 "date_gmt": "2017-02-14T00:00:00", 4400 "id": 367 08,4400 "id": 36711, 4401 4401 "modified": "2017-02-14T00:00:00", 4402 4402 "modified_gmt": "2017-02-14T00:00:00", 4403 "parent": 3670 6,4404 "slug": "3670 6-autosave-v1",4403 "parent": 36709, 4404 "slug": "36709-autosave-v1", 4405 4405 "guid": { 4406 "rendered": "http://example.org/?p=367 08"4406 "rendered": "http://example.org/?p=36711" 4407 4407 }, 4408 4408 "title": { … … 4418 4418 "parent": [ 4419 4419 { 4420 "href": "http://example.org/index.php?rest_route=/wp/v2/posts/3670 6"4420 "href": "http://example.org/index.php?rest_route=/wp/v2/posts/36709" 4421 4421 } 4422 4422 ] … … 4429 4429 "date": "2017-02-14T00:00:00", 4430 4430 "date_gmt": "2017-02-14T00:00:00", 4431 "id": 367 08,4431 "id": 36711, 4432 4432 "modified": "2017-02-14T00:00:00", 4433 4433 "modified_gmt": "2017-02-14T00:00:00", 4434 "parent": 3670 6,4435 "slug": "3670 6-autosave-v1",4434 "parent": 36709, 4435 "slug": "36709-autosave-v1", 4436 4436 "guid": { 4437 "rendered": "http://example.org/?p=367 08"4437 "rendered": "http://example.org/?p=36711" 4438 4438 }, 4439 4439 "title": { … … 4603 4603 "date": "2017-02-14T00:00:00", 4604 4604 "date_gmt": "2017-02-14T00:00:00", 4605 "id": 3671 0,4605 "id": 36713, 4606 4606 "modified": "2017-02-14T00:00:00", 4607 4607 "modified_gmt": "2017-02-14T00:00:00", 4608 "parent": 367 09,4609 "slug": "367 09-revision-v1",4608 "parent": 36712, 4609 "slug": "36712-revision-v1", 4610 4610 "guid": { 4611 "rendered": "http://example.org/?p=3671 0"4611 "rendered": "http://example.org/?p=36713" 4612 4612 }, 4613 4613 "title": { … … 4623 4623 "parent": [ 4624 4624 { 4625 "href": "http://example.org/index.php?rest_route=/wp/v2/pages/367 09"4625 "href": "http://example.org/index.php?rest_route=/wp/v2/pages/36712" 4626 4626 } 4627 4627 ] … … 4658 4658 "date": "2017-02-14T00:00:00", 4659 4659 "date_gmt": "2017-02-14T00:00:00", 4660 "id": 3671 1,4660 "id": 36714, 4661 4661 "modified": "2017-02-14T00:00:00", 4662 4662 "modified_gmt": "2017-02-14T00:00:00", 4663 "parent": 367 09,4664 "slug": "367 09-autosave-v1",4663 "parent": 36712, 4664 "slug": "36712-autosave-v1", 4665 4665 "guid": { 4666 "rendered": "http://example.org/?p=3671 1"4666 "rendered": "http://example.org/?p=36714" 4667 4667 }, 4668 4668 "title": { … … 4678 4678 "parent": [ 4679 4679 { 4680 "href": "http://example.org/index.php?rest_route=/wp/v2/pages/367 09"4680 "href": "http://example.org/index.php?rest_route=/wp/v2/pages/36712" 4681 4681 } 4682 4682 ] … … 4689 4689 "date": "2017-02-14T00:00:00", 4690 4690 "date_gmt": "2017-02-14T00:00:00", 4691 "id": 3671 1,4691 "id": 36714, 4692 4692 "modified": "2017-02-14T00:00:00", 4693 4693 "modified_gmt": "2017-02-14T00:00:00", 4694 "parent": 367 09,4695 "slug": "367 09-autosave-v1",4694 "parent": 36712, 4695 "slug": "36712-autosave-v1", 4696 4696 "guid": { 4697 "rendered": "http://example.org/?p=3671 1"4697 "rendered": "http://example.org/?p=36714" 4698 4698 }, 4699 4699 "title": {
Note: See TracChangeset
for help on using the changeset viewer.