Changeset 39287
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
r39278 r39287 1042 1042 } 1043 1043 1044 if ( isset( $request['author_user_agent'] ) ) {1044 if ( ! empty( $request['author_user_agent'] ) ) { 1045 1045 $prepared_comment['comment_agent'] = $request['author_user_agent']; 1046 } elseif ( $request->get_header( 'user_agent' ) ) { 1047 $prepared_comment['comment_agent'] = $request->get_header( 'user_agent' ); 1046 1048 } 1047 1049 -
trunk/tests/phpunit/tests/rest-api/rest-comments-controller.php
r39196 r39287 1245 1245 $this->assertEquals( '139.130.4.5', $data['author_ip'] ); 1246 1246 $this->assertEquals( 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36', $data['author_user_agent'] ); 1247 } 1248 1249 public function test_create_comment_user_agent_header() { 1250 wp_set_current_user( self::$admin_id ); 1251 1252 $params = array( 1253 'post' => self::$post_id, 1254 'author_name' => 'Homer Jay Simpson', 1255 'author_email' => 'chunkylover53@aol.com', 1256 'author_url' => 'http://compuglobalhypermeganet.com', 1257 'content' => 'Here\’s to alcohol: the cause of, and solution to, all of life\’s problems.', 1258 ); 1259 1260 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); 1261 $request->add_header( 'content-type', 'application/json' ); 1262 $request->add_header( 'user_agent', 'Mozilla/4.0 (compatible; MSIE 5.5; AOL 4.0; Windows 95)' ); 1263 $request->set_body( wp_json_encode( $params ) ); 1264 1265 $response = $this->server->dispatch( $request ); 1266 $this->assertEquals( 201, $response->get_status() ); 1267 1268 $data = $response->get_data(); 1269 1270 $new_comment = get_comment( $data['id'] ); 1271 $this->assertEquals( 'Mozilla/4.0 (compatible; MSIE 5.5; AOL 4.0; Windows 95)', $new_comment->comment_agent ); 1247 1272 } 1248 1273
Note: See TracChangeset
for help on using the changeset viewer.