Changeset 56566
- Timestamp:
- 09/13/2023 02:32:33 PM (13 months ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/class-wp-rest-server.php
r56193 r56566 1274 1274 1275 1275 $response = new WP_REST_Response( $available ); 1276 $response->add_link( 'help', 'https://developer.wordpress.org/rest-api/' ); 1277 $this->add_active_theme_link_to_index( $response ); 1278 $this->add_site_logo_to_index( $response ); 1279 $this->add_site_icon_to_index( $response ); 1276 1277 $fields = isset( $request['_fields'] ) ? $request['_fields'] : ''; 1278 $fields = wp_parse_list( $fields ); 1279 if ( empty( $fields ) ) { 1280 $fields[] = '_links'; 1281 } 1282 1283 if ( $request->has_param( '_embed' ) ) { 1284 $fields[] = '_embedded'; 1285 } 1286 1287 if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { 1288 $response->add_link( 'help', 'https://developer.wordpress.org/rest-api/' ); 1289 $this->add_active_theme_link_to_index( $response ); 1290 $this->add_site_logo_to_index( $response ); 1291 $this->add_site_icon_to_index( $response ); 1292 } 1280 1293 1281 1294 /** -
trunk/tests/phpunit/tests/rest-api.php
r55562 r56566 2513 2513 $this->assertArrayHasKey( 'routes', $preload_data['/']['body'] ); 2514 2514 2515 // Filtered request only has the desired fields + links2515 // Filtered request only has the desired fields. 2516 2516 $this->assertSame( 2517 2517 array_keys( $preload_data['/?_fields=description']['body'] ), 2518 array( 'description' , '_links')2518 array( 'description' ) 2519 2519 ); 2520 2520 } -
trunk/tests/phpunit/tests/rest-api/rest-server.php
r56559 r56566 1118 1118 $this->assertArrayHasKey( 'site_icon', $data ); 1119 1119 $this->assertArrayHasKey( 'site_icon_url', $data ); 1120 } 1121 1122 /** 1123 * @ticket 57902 1124 * 1125 * @covers WP_REST_Server::get_index 1126 */ 1127 public function test_get_index_fields_name() { 1128 $server = new WP_REST_Server(); 1129 1130 $request = new WP_REST_Request( 'GET', '/' ); 1131 $request->set_param( '_fields', 'name' ); 1132 $index = $server->dispatch( $request ); 1133 $index = rest_filter_response_fields( $index, $server, $request ); 1134 $data = $index->get_data(); 1135 $links = $index->get_links(); 1136 1137 $this->assertArrayHasKey( 'name', $data ); 1138 $this->assertArrayNotHasKey( 'help', $links ); 1139 } 1140 1141 /** 1142 * @ticket 57902 1143 * 1144 * @covers WP_REST_Server::get_index 1145 * 1146 * @dataProvider data_get_index_should_return_help_and_not_name 1147 * 1148 * @param string $field The field to add to the request. 1149 */ 1150 public function test_get_index_should_return_help_and_not_name( $field ) { 1151 $server = new WP_REST_Server(); 1152 1153 $request = new WP_REST_Request( 'GET', '/' ); 1154 $request->set_param( '_fields', $field ); 1155 $index = $server->dispatch( $request ); 1156 $index = rest_filter_response_fields( $index, $server, $request ); 1157 $data = $index->get_data(); 1158 $links = $index->get_links(); 1159 1160 $this->assertArrayNotHasKey( 'name', $data ); 1161 $this->assertArrayHasKey( 'help', $links ); 1162 } 1163 1164 /** 1165 * Data provider. 1166 * 1167 * @throws Exception 1168 * 1169 * @return array 1170 */ 1171 public function data_get_index_should_return_help_and_not_name() { 1172 return self::text_array_to_dataprovider( array( '_links', '_embedded' ) ); 1120 1173 } 1121 1174
Note: See TracChangeset
for help on using the changeset viewer.