Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function register_routes() {
),
),
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(
Expand Down
21 changes: 20 additions & 1 deletion tests/phpunit/tests/rest-api/rest-block-renderer-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,25 @@ public function test_get_item_with_post_context() {
$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.
*
Expand Down Expand Up @@ -503,7 +522,7 @@ public function test_get_item_schema() {
$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'] )
Expand Down