- Timestamp:
- 11/19/2018 02:09:07 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/5.0/tests/phpunit/tests/rest-api/rest-posts-controller.php
r43770 r43908 3366 3366 } 3367 3367 3368 /** 3369 * @ticket 45220 3370 */ 3371 public function test_get_additional_field_registration_null_schema() { 3372 register_rest_field( 'post', 'my_custom_int', array( 3373 'schema' => null, 3374 'get_callback' => array( $this, 'additional_field_get_callback' ), 3375 'update_callback' => null, 3376 ) ); 3377 $post_id = $this->factory->post->create(); 3378 3379 // 'my_custom_int' should appear because ?_fields= isn't set. 3380 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $post_id ); 3381 $response = $this->server->dispatch( $request ); 3382 $this->assertArrayHasKey( 'my_custom_int', $response->data ); 3383 3384 // 'my_custom_int' should appear because it's present in ?_fields=. 3385 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $post_id ); 3386 $request->set_param( '_fields', 'title,my_custom_int' ); 3387 $response = $this->server->dispatch( $request ); 3388 $this->assertArrayHasKey( 'my_custom_int', $response->data ); 3389 3390 // 'my_custom_int' should not appear because it's not present in ?_fields=. 3391 $request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . $post_id ); 3392 $request->set_param( '_fields', 'title' ); 3393 $response = $this->server->dispatch( $request ); 3394 $this->assertArrayNotHasKey( 'my_custom_int', $response->data ); 3395 3396 global $wp_rest_additional_fields; 3397 $wp_rest_additional_fields = array(); 3398 } 3399 3368 3400 public function test_additional_field_update_errors() { 3369 3401 $schema = array(
Note: See TracChangeset
for help on using the changeset viewer.