Ticket #41692: 41692.2.diff
File 41692.2.diff, 6.9 KB (added by , 6 years ago) |
---|
-
src/wp-includes/post.php
diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index e52ae57..fb17cc4 100644
a b function create_initial_post_types() { 82 82 'query_var' => false, 83 83 'show_in_nav_menus' => false, 84 84 'delete_with_user' => true, 85 'supports' => array( 'title', 'author', 'comments' ),85 'supports' => array( 'title', 'author', 'comments', 'thumbnail' ), 86 86 'show_in_rest' => true, 87 87 'rest_base' => 'media', 88 88 'rest_controller_class' => 'WP_REST_Attachments_Controller', -
src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php index 76802fe..d26545c 100644
a b class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { 178 178 update_post_meta( $id, '_wp_attachment_image_alt', sanitize_text_field( $request['alt_text'] ) ); 179 179 } 180 180 181 if ( isset( $request['featured_media'] ) ) { 182 $this->handle_featured_media( $request['featured_media'], $id ); 183 } 184 181 185 $fields_update = $this->update_additional_fields_for_object( $attachment, $request ); 182 186 183 187 if ( is_wp_error( $fields_update ) ) { -
src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php index 018b66e..31c7d66 100644
a b class WP_REST_Posts_Controller extends WP_REST_Controller { 1828 1828 'comments', 1829 1829 'revisions', 1830 1830 'custom-fields', 1831 'thumbnail', 1831 1832 ), 1832 1833 ); 1833 1834 foreach ( $post_type_attributes as $attribute ) { -
tests/phpunit/tests/rest-api/rest-attachments-controller.php
diff --git a/tests/phpunit/tests/rest-api/rest-attachments-controller.php b/tests/phpunit/tests/rest-api/rest-attachments-controller.php index 98a079b..1d79a7a 100644
a b class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control 697 697 $this->assertEquals( '', $attachment['alt_text'] ); 698 698 } 699 699 700 public function test_create_update_post_with_featured_media() { 701 702 wp_set_current_user( self::$editor_id ); 703 704 $request = new WP_REST_Request( 'POST', '/wp/v2/media' ); 705 $request->set_file_params( array( 706 'file' => array( 707 'file' => file_get_contents( $this->test_file ), 708 'name' => 'canola.jpg', 709 'size' => filesize( $this->test_file ), 710 'tmp_name' => $this->test_file, 711 ), 712 ) ); 713 $request->set_header( 'Content-MD5', md5_file( $this->test_file ) ); 714 715 $file = DIR_TESTDATA . '/images/canola.jpg'; 716 $this->attachment_id = $this->factory->attachment->create_object( $file, 0, array( 717 'post_mime_type' => 'image/jpeg', 718 'menu_order' => rand( 1, 100 ), 719 ) ); 720 721 $request->set_param( 'featured_media', $this->attachment_id ); 722 723 $response = $this->server->dispatch( $request ); 724 $data = $response->get_data(); 725 726 $this->assertEquals( 201, $response->get_status() ); 727 728 $new_attachment = get_post( $data['id'] ); 729 730 $this->assertEquals( $this->attachment_id, (int) get_post_thumbnail_id( $new_attachment->ID ) ); 731 $this->assertEquals( $this->attachment_id, $data['featured_media'] ); 732 733 $request = new WP_REST_Request( 'PUT', '/wp/v2/media/' . $new_attachment->ID ); 734 $params = $this->set_post_data( array( 735 'featured_media' => 0, 736 ) ); 737 $request->set_body_params( $params ); 738 $response = $this->server->dispatch( $request ); 739 $this->assertEquals( 200, $response->get_status() ); 740 $data = $response->get_data(); 741 $this->assertEquals( 0, $data['featured_media'] ); 742 $this->assertEquals( 0, (int) get_post_thumbnail_id( $new_attachment->ID ) ); 743 } 744 700 745 public function test_update_item() { 701 746 wp_set_current_user( self::$editor_id ); 702 747 $attachment_id = $this->factory->attachment->create_object( $this->test_file, 0, array( … … class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control 1079 1124 $response = $this->server->dispatch( $request ); 1080 1125 $data = $response->get_data(); 1081 1126 $properties = $data['schema']['properties']; 1082 $this->assertEquals( 2 4, count( $properties ) );1127 $this->assertEquals( 25, count( $properties ) ); 1083 1128 $this->assertArrayHasKey( 'author', $properties ); 1084 1129 $this->assertArrayHasKey( 'alt_text', $properties ); 1085 1130 $this->assertArrayHasKey( 'caption', $properties ); … … class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control 1110 1155 $this->assertArrayHasKey( 'raw', $properties['title']['properties'] ); 1111 1156 $this->assertArrayHasKey( 'rendered', $properties['title']['properties'] ); 1112 1157 $this->assertArrayHasKey( 'type', $properties ); 1158 $this->assertArrayHasKey( 'featured_media', $properties ); 1113 1159 } 1114 1160 1115 1161 public function test_get_additional_field_registration() { -
tests/qunit/fixtures/wp-api-generated.js
diff --git a/tests/qunit/fixtures/wp-api-generated.js b/tests/qunit/fixtures/wp-api-generated.js index 72bcc5e..c0911dc 100644
a b mockedApiResponse.Schema = { 1549 1549 "description": "The ID for the author of the object.", 1550 1550 "type": "integer" 1551 1551 }, 1552 "featured_media": { 1553 "required": false, 1554 "description": "The ID of the featured media for the object.", 1555 "type": "integer" 1556 }, 1552 1557 "comment_status": { 1553 1558 "required": false, 1554 1559 "enum": [ … … mockedApiResponse.Schema = { 1689 1694 "description": "The ID for the author of the object.", 1690 1695 "type": "integer" 1691 1696 }, 1697 "featured_media": { 1698 "required": false, 1699 "description": "The ID of the featured media for the object.", 1700 "type": "integer" 1701 }, 1692 1702 "comment_status": { 1693 1703 "required": false, 1694 1704 "enum": [ … … mockedApiResponse.MediaCollection = [ 3904 3914 "rendered": "REST API Client Fixture: Attachment" 3905 3915 }, 3906 3916 "author": 0, 3917 "featured_media": 0, 3907 3918 "comment_status": "open", 3908 3919 "ping_status": "closed", 3909 3920 "template": "", … … mockedApiResponse.MediaModel = { 3965 3976 "rendered": "REST API Client Fixture: Attachment" 3966 3977 }, 3967 3978 "author": 0, 3979 "featured_media": 0, 3968 3980 "comment_status": "open", 3969 3981 "ping_status": "closed", 3970 3982 "template": "",