| | 1467 | /** |
| | 1468 | * The post response should have `block_version` indicate that block content is present when in view context. |
| | 1469 | * |
| | 1470 | * @ticket 43887 |
| | 1471 | */ |
| | 1472 | public function test_get_post_should_have_block_version_indicate_content_blocks_when_context_view() { |
| | 1473 | $post_id = $this->factory->post->create( |
| | 1474 | array( |
| | 1475 | 'post_content' => '<!-- wp:separator -->', |
| | 1476 | ) |
| | 1477 | ); |
| | 1478 | |
| | 1479 | $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) ); |
| | 1480 | $response = rest_get_server()->dispatch( $request ); |
| | 1481 | |
| | 1482 | $this->check_get_post_response( $response, 'view' ); |
| | 1483 | $data = $response->get_data(); |
| | 1484 | |
| | 1485 | $this->assertSame( 1, $data['content']['block_version'] ); |
| | 1486 | } |
| | 1487 | |
| | 1488 | /** |
| | 1489 | * The post response should have `block_version` indicate that block content is present when in view context. |
| | 1490 | * |
| | 1491 | * @ticket 43887 |
| | 1492 | */ |
| | 1493 | public function test_get_post_should_have_block_version_indicate_no_content_blocks_when_context_view() { |
| | 1494 | $post_id = $this->factory->post->create( |
| | 1495 | array( |
| | 1496 | 'post_content' => '<hr/>', |
| | 1497 | ) |
| | 1498 | ); |
| | 1499 | |
| | 1500 | $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) ); |
| | 1501 | $response = rest_get_server()->dispatch( $request ); |
| | 1502 | |
| | 1503 | $this->check_get_post_response( $response, 'view' ); |
| | 1504 | $data = $response->get_data(); |
| | 1505 | |
| | 1506 | $this->assertSame( 0, $data['content']['block_version'] ); |
| | 1507 | } |
| | 1508 | |
| | 1509 | /** |
| | 1510 | * The post response should have `block_version` indicate that block content is present when in edit context. |
| | 1511 | * |
| | 1512 | * @ticket 43887 |
| | 1513 | */ |
| | 1514 | public function test_get_post_should_have_block_version_indicate_block_content_when_context_edit() { |
| | 1515 | wp_set_current_user( self::$editor_id ); |
| | 1516 | |
| | 1517 | $post_id = $this->factory->post->create( |
| | 1518 | array( |
| | 1519 | 'post_content' => '<!-- wp:separator -->', |
| | 1520 | ) |
| | 1521 | ); |
| | 1522 | |
| | 1523 | $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) ); |
| | 1524 | $request->set_param( 'context', 'edit' ); |
| | 1525 | $response = rest_get_server()->dispatch( $request ); |
| | 1526 | |
| | 1527 | $this->check_get_post_response( $response, 'edit' ); |
| | 1528 | $data = $response->get_data(); |
| | 1529 | |
| | 1530 | $this->assertSame( 1, $data['content']['block_version'] ); |
| | 1531 | } |
| | 1532 | |
| | 1533 | /** |
| | 1534 | * The post response should have `block_version` indicate that no block content is present when in edit context. |
| | 1535 | * |
| | 1536 | * @ticket 43887 |
| | 1537 | */ |
| | 1538 | public function test_get_post_should_have_block_version_indicate_no_block_content_when_context_edit() { |
| | 1539 | wp_set_current_user( self::$editor_id ); |
| | 1540 | |
| | 1541 | $post_id = $this->factory->post->create( |
| | 1542 | array( |
| | 1543 | 'post_content' => '<hr/>', |
| | 1544 | ) |
| | 1545 | ); |
| | 1546 | |
| | 1547 | $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', $post_id ) ); |
| | 1548 | $request->set_param( 'context', 'edit' ); |
| | 1549 | $response = rest_get_server()->dispatch( $request ); |
| | 1550 | |
| | 1551 | $this->check_get_post_response( $response, 'edit' ); |
| | 1552 | $data = $response->get_data(); |
| | 1553 | |
| | 1554 | $this->assertSame( 0, $data['content']['block_version'] ); |
| | 1555 | } |
| | 1556 | |