Changeset 56745
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php
r56714 r56745 422 422 foreach ( $revisioned_meta_keys as $meta_key ) { 423 423 if ( isset( $meta[ $meta_key ] ) ) { 424 update_metadata( 'post', $revision_id, $meta_key, $meta[ $meta_key ]);424 update_metadata( 'post', $revision_id, $meta_key, wp_slash( $meta[ $meta_key ] ) ); 425 425 } 426 426 } -
trunk/tests/phpunit/tests/rest-api/rest-autosaves-controller.php
r56714 r56745 342 342 } 343 343 344 public function test_update_item_with_meta() { 345 wp_set_current_user( self::$editor_id ); 346 $request = new WP_REST_Request( 'POST', '/wp/v2/posts/' . self::$post_id . '/autosaves' ); 347 $request->add_header( 'Content-Type', 'application/x-www-form-urlencoded' ); 348 register_post_meta( 349 'post', 350 'foo', 351 array( 352 'show_in_rest' => true, 353 'revisions_enabled' => true, 354 'single' => true, 355 ) 356 ); 357 $params = $this->set_post_data( 358 array( 359 'id' => self::$post_id, 360 'author' => self::$contributor_id, 361 'meta' => array( 362 'foo' => 'bar', 363 ), 364 ) 365 ); 366 367 $request->set_body_params( $params ); 368 $response = rest_get_server()->dispatch( $request ); 369 370 $this->check_create_autosave_response( $response ); 371 372 $data = $response->get_data(); 373 $this->assertArrayHasKey( 'meta', $data ); 374 $this->assertArrayHasKey( 'foo', $data['meta'] ); 375 $this->assertSame( 'bar', $data['meta']['foo'] ); 376 } 377 378 public function test_update_item_with_json_meta() { 379 $meta = '[{\"content\":\"foot 1\",\"id\":\"fa97a10d-7401-42b9-ac54-df8f4510749a\"},{\"content\":\"fdddddoot 2\\\"\",\"id\":\"2216d0aa-34b8-42b4-b441-84dedc0406e0\"}]'; 380 wp_set_current_user( self::$editor_id ); 381 $request = new WP_REST_Request( 'POST', '/wp/v2/posts/' . self::$post_id . '/autosaves' ); 382 $request->add_header( 'Content-Type', 'application/x-www-form-urlencoded' ); 383 register_post_meta( 384 'post', 385 'foo', 386 array( 387 'show_in_rest' => true, 388 'revisions_enabled' => true, 389 'single' => true, 390 ) 391 ); 392 $params = $this->set_post_data( 393 array( 394 'id' => self::$post_id, 395 'author' => self::$contributor_id, 396 'meta' => array( 397 'foo' => $meta, 398 ), 399 ) 400 ); 401 402 $request->set_body_params( $params ); 403 $response = rest_get_server()->dispatch( $request ); 404 405 $this->check_create_autosave_response( $response ); 406 407 $data = $response->get_data(); 408 $this->assertArrayHasKey( 'meta', $data ); 409 $this->assertArrayHasKey( 'foo', $data['meta'] ); 410 $values = json_decode( wp_unslash( $data['meta']['foo'] ), true ); 411 $this->assertNotNull( $values ); 412 } 413 344 414 public function test_update_item_nopriv() { 345 415 wp_set_current_user( self::$contributor_id ); -
trunk/tests/phpunit/tests/rest-api/rest-post-meta-fields.php
r56714 r56745 3365 3365 * 3366 3366 * @group revision 3367 * @dataProvider test_revisioned_single_post_meta_with_posts_endpoint_page_and_cpt_data_provider3367 * @dataProvider data_revisioned_single_post_meta_with_posts_endpoint_page_and_cpt_data_provider 3368 3368 */ 3369 3369 public function test_revisioned_single_post_meta_with_posts_endpoint_page_and_cpt( $passed, $expected, $post_type ) { … … 3452 3452 * Provide data for the meta revision checks. 3453 3453 */ 3454 public function test_revisioned_single_post_meta_with_posts_endpoint_page_and_cpt_data_provider() {3454 public function data_revisioned_single_post_meta_with_posts_endpoint_page_and_cpt_data_provider() { 3455 3455 return array( 3456 3456 array( … … 3469 3469 'cpt', 3470 3470 ), 3471 3472 3471 ); 3473 3472 }
Note: See TracChangeset
for help on using the changeset viewer.