REST API: Accept POST requests in the block renderer endpoint.
Rendering a block is idempotent, so a GET is the most natural request method. However, the maximum length of URLs prevented blocks with large attributes from being rendered. Props ryankienstra. Fixes #49680. git-svn-id: https://develop.svn.wordpress.org/trunk@47756 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
6ab90a209d
commit
5460e0df1e
@ -52,7 +52,7 @@ class WP_REST_Block_Renderer_Controller extends WP_REST_Controller {
|
||||
),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'methods' => array( WP_REST_Server::READABLE, WP_REST_Server::CREATABLE ),
|
||||
'callback' => array( $this, 'get_item' ),
|
||||
'permission_callback' => array( $this, 'get_item_permissions_check' ),
|
||||
'args' => array(
|
||||
|
@ -455,6 +455,25 @@ class REST_Block_Renderer_Controller_Test extends WP_Test_REST_Controller_Testca
|
||||
$this->assertEquals( $expected_title, $data['rendered'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a POST request, with the attributes in the body.
|
||||
*
|
||||
* @ticket 49680
|
||||
*/
|
||||
public function test_get_item_post_request() {
|
||||
wp_set_current_user( self::$user_id );
|
||||
$string_attribute = 'Lorem ipsum dolor';
|
||||
$attributes = array( 'some_string' => $string_attribute );
|
||||
$request = new WP_REST_Request( 'POST', self::$rest_api_route . self::$block_name );
|
||||
$request->set_param( 'context', 'edit' );
|
||||
$request->set_header( 'content-type', 'application/json' );
|
||||
$request->set_body( wp_json_encode( compact( 'attributes' ) ) );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
$this->assertContains( $string_attribute, $response->get_data()['rendered'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getting item with invalid post ID.
|
||||
*
|
||||
@ -503,7 +522,7 @@ class REST_Block_Renderer_Controller_Test extends WP_Test_REST_Controller_Testca
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
|
||||
$this->assertEqualSets( array( 'GET' ), $data['endpoints'][0]['methods'] );
|
||||
$this->assertEqualSets( array( 'GET', 'POST' ), $data['endpoints'][0]['methods'] );
|
||||
$this->assertEqualSets(
|
||||
array( 'name', 'context', 'attributes', 'post_id' ),
|
||||
array_keys( $data['endpoints'][0]['args'] )
|
||||
|
Loading…
Reference in New Issue
Block a user