Changeset 55102
- Timestamp:
- 01/19/2023 09:46:58 PM (2 years ago)
- Location:
- trunk/tests/phpunit/tests/rest-api
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php
r54428 r55102 1679 1679 } 1680 1680 1681 public function test_search_item_by_filename() { 1682 $id1 = self::factory()->attachment->create_object( 1683 self::$test_file, 1684 0, 1685 array( 1686 'post_mime_type' => 'image/jpeg', 1687 ) 1688 ); 1689 $id2 = self::factory()->attachment->create_object( 1690 self::$test_file2, 1691 0, 1692 array( 1693 'post_mime_type' => 'image/png', 1694 ) 1695 ); 1696 1697 $filename = wp_basename( self::$test_file2 ); 1698 1699 $request = new WP_REST_Request( 'GET', '/wp/v2/media' ); 1700 $request->set_param( 'search', $filename ); 1701 $response = rest_get_server()->dispatch( $request ); 1702 $data = $response->get_data(); 1703 1704 $this->assertCount( 1, $data ); 1705 $this->assertSame( $id2, $data[0]['id'] ); 1706 $this->assertSame( 'image/png', $data[0]['mime_type'] ); 1707 } 1708 1709 public function additional_field_get_callback( $object, $request ) { 1681 public function additional_field_get_callback( $object, $field_name ) { 1710 1682 return 123; 1711 1683 } … … 1715 1687 return new WP_Error( 'rest_invalid_param', 'Testing an error.', array( 'status' => 400 ) ); 1716 1688 } 1689 } 1690 1691 public function test_search_item_by_filename() { 1692 $id1 = self::factory()->attachment->create_object( 1693 self::$test_file, 1694 0, 1695 array( 1696 'post_mime_type' => 'image/jpeg', 1697 ) 1698 ); 1699 $id2 = self::factory()->attachment->create_object( 1700 self::$test_file2, 1701 0, 1702 array( 1703 'post_mime_type' => 'image/png', 1704 ) 1705 ); 1706 1707 $filename = wp_basename( self::$test_file2 ); 1708 1709 $request = new WP_REST_Request( 'GET', '/wp/v2/media' ); 1710 $request->set_param( 'search', $filename ); 1711 $response = rest_get_server()->dispatch( $request ); 1712 $data = $response->get_data(); 1713 1714 $this->assertCount( 1, $data ); 1715 $this->assertSame( $id2, $data[0]['id'] ); 1716 $this->assertSame( 'image/png', $data[0]['mime_type'] ); 1717 1717 } 1718 1718 -
trunk/tests/phpunit/tests/rest-api/rest-autosaves-controller.php
r54130 r55102 515 515 } 516 516 517 public function additional_field_get_callback( $object ) {518 return get_post_meta( $object['id'], 'my_custom_int', true );519 } 520 521 public function additional_field_update_callback( $value, $post ) {522 update_post_meta( $post->ID, 'my_custom_int', $value );517 public function additional_field_get_callback( $object, $field_name ) { 518 return get_post_meta( $object['id'], $field_name, true ); 519 } 520 521 public function additional_field_update_callback( $value, $post, $field_name ) { 522 update_post_meta( $post->ID, $field_name, $value ); 523 523 } 524 524 -
trunk/tests/phpunit/tests/rest-api/rest-categories-controller.php
r54891 r55102 1181 1181 } 1182 1182 1183 public function additional_field_get_callback( $object, $ request) {1183 public function additional_field_get_callback( $object, $field_name ) { 1184 1184 return 123; 1185 1185 } -
trunk/tests/phpunit/tests/rest-api/rest-comments-controller.php
r54891 r55102 3299 3299 } 3300 3300 3301 public function additional_field_get_callback( $object ) {3302 return get_comment_meta( $object['id'], 'my_custom_int', true );3303 } 3304 3305 public function additional_field_update_callback( $value, $comment ) {3301 public function additional_field_get_callback( $object, $field_name ) { 3302 return get_comment_meta( $object['id'], $field_name, true ); 3303 } 3304 3305 public function additional_field_update_callback( $value, $comment, $field_name ) { 3306 3306 if ( 'returnError' === $value ) { 3307 3307 return new WP_Error( 'rest_invalid_param', 'Testing an error.', array( 'status' => 400 ) ); 3308 3308 } 3309 update_comment_meta( $comment->comment_ID, 'my_custom_int', $value );3309 update_comment_meta( $comment->comment_ID, $field_name, $value ); 3310 3310 } 3311 3311 -
trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php
r54855 r55102 4587 4587 } 4588 4588 4589 public function additional_field_get_callback( $object ) {4590 return get_post_meta( $object['id'], 'my_custom_int', true );4591 } 4592 4593 public function additional_field_update_callback( $value, $post ) {4589 public function additional_field_get_callback( $object, $field_name ) { 4590 return get_post_meta( $object['id'], $field_name, true ); 4591 } 4592 4593 public function additional_field_update_callback( $value, $post, $field_name ) { 4594 4594 if ( 'returnError' === $value ) { 4595 4595 return new WP_Error( 'rest_invalid_param', 'Testing an error.', array( 'status' => 400 ) ); 4596 4596 } 4597 update_post_meta( $post->ID, 'my_custom_int', $value );4597 update_post_meta( $post->ID, $field_name, $value ); 4598 4598 } 4599 4599 -
trunk/tests/phpunit/tests/rest-api/rest-revisions-controller.php
r53948 r55102 403 403 } 404 404 405 public function additional_field_get_callback( $object ) {406 return get_post_meta( $object['id'], 'my_custom_int', true );407 } 408 409 public function additional_field_update_callback( $value, $post ) {410 update_post_meta( $post->ID, 'my_custom_int', $value );405 public function additional_field_get_callback( $object, $field_name ) { 406 return get_post_meta( $object['id'], $field_name, true ); 407 } 408 409 public function additional_field_update_callback( $value, $post, $field_name ) { 410 update_post_meta( $post->ID, $field_name, $value ); 411 411 } 412 412 -
trunk/tests/phpunit/tests/rest-api/rest-tags-controller.php
r54891 r55102 1325 1325 } 1326 1326 1327 public function additional_field_get_callback( $object, $field_name ) { 1328 return 123; 1329 } 1330 1331 public function additional_field_update_callback( $value, $tag ) { 1332 if ( 'returnError' === $value ) { 1333 return new WP_Error( 'rest_invalid_param', 'Testing an error.', array( 'status' => 400 ) ); 1334 } 1335 } 1336 1327 1337 /** 1328 1338 * @ticket 38504 … … 1395 1405 $this->assertArrayHasKey( $edit_field, $data ); 1396 1406 $this->assertArrayNotHasKey( $view_field, $data ); 1397 }1398 1399 public function additional_field_get_callback( $object, $request ) {1400 return 123;1401 }1402 1403 public function additional_field_update_callback( $value, $tag ) {1404 if ( 'returnError' === $value ) {1405 return new WP_Error( 'rest_invalid_param', 'Testing an error.', array( 'status' => 400 ) );1406 }1407 1407 } 1408 1408 -
trunk/tests/phpunit/tests/rest-api/rest-users-controller.php
r54891 r55102 2826 2826 } 2827 2827 2828 public function additional_field_get_callback( $object, $field_name ) { 2829 return get_user_meta( $object['id'], $field_name, true ); 2830 } 2831 2832 public function additional_field_update_callback( $value, $user, $field_name ) { 2833 if ( 'returnError' === $value ) { 2834 return new WP_Error( 'rest_invalid_param', 'Testing an error.', array( 'status' => 400 ) ); 2835 } 2836 update_user_meta( $user->ID, $field_name, $value ); 2837 } 2838 2828 2839 /** 2829 2840 * @ticket 39701 … … 3073 3084 } 3074 3085 3075 public function additional_field_get_callback( $object ) {3076 return get_user_meta( $object['id'], 'my_custom_int', true );3077 }3078 3079 public function additional_field_update_callback( $value, $user ) {3080 if ( 'returnError' === $value ) {3081 return new WP_Error( 'rest_invalid_param', 'Testing an error.', array( 'status' => 400 ) );3082 }3083 update_user_meta( $user->ID, 'my_custom_int', $value );3084 }3085 3086 3086 protected function check_user_data( $user, $data, $context, $links ) { 3087 3087 $this->assertSame( $user->ID, $data['id'] );
Note: See TracChangeset
for help on using the changeset viewer.