Changeset 39105
- Timestamp:
- 11/03/2016 02:17:39 AM (8 years ago)
- Location:
- trunk
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
r39104 r39105 595 595 'type' => 'string', 596 596 'enum' => array_keys( $media_types ), 597 'validate_callback' => 'rest_validate_request_arg',598 597 ); 599 598 -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
r39101 r39105 1115 1115 'format' => 'ipv4', 1116 1116 'context' => array( 'edit' ), 1117 'arg_options' => array( 1118 'default' => '127.0.0.1', 1119 ), 1117 'default' => '127.0.0.1', 1120 1118 ), 1121 1119 'author_name' => array( … … 1189 1187 'type' => 'integer', 1190 1188 'context' => array( 'view', 'edit', 'embed' ), 1191 'arg_options' => array( 1192 'default' => 0, 1193 ), 1189 'default' => 0, 1194 1190 ), 1195 1191 'post' => array( … … 1197 1193 'type' => 'integer', 1198 1194 'context' => array( 'view', 'edit' ), 1199 'arg_options' => array( 1200 'default' => 0, 1201 ), 1195 'default' => 0, 1202 1196 ), 1203 1197 'status' => array( … … 1265 1259 'type' => 'string', 1266 1260 'format' => 'date-time', 1267 'validate_callback' => 'rest_validate_request_arg',1268 1261 ); 1269 1262 1270 1263 $query_params['author'] = array( 1271 1264 'description' => __( 'Limit result set to comments assigned to specific user ids. Requires authorization.' ), 1272 'sanitize_callback' => 'wp_parse_id_list',1273 1265 'type' => 'array', 1266 'items' => array( 1267 'type' => 'integer', 1268 ), 1274 1269 ); 1275 1270 1276 1271 $query_params['author_exclude'] = array( 1277 1272 'description' => __( 'Ensure result set excludes comments assigned to specific user ids. Requires authorization.' ), 1278 'sanitize_callback' => 'wp_parse_id_list',1279 1273 'type' => 'array', 1274 'items' => array( 1275 'type' => 'integer', 1276 ), 1280 1277 ); 1281 1278 … … 1284 1281 'description' => __( 'Limit result set to that from a specific author email. Requires authorization.' ), 1285 1282 'format' => 'email', 1286 'sanitize_callback' => 'sanitize_email',1287 1283 'type' => 'string', 1288 1284 ); … … 1292 1288 'type' => 'string', 1293 1289 'format' => 'date-time', 1294 'validate_callback' => 'rest_validate_request_arg',1295 1290 ); 1296 1291 … … 1298 1293 'description' => __( 'Ensure result set excludes specific ids.' ), 1299 1294 'type' => 'array', 1295 'items' => array( 1296 'type' => 'integer', 1297 ), 1300 1298 'default' => array(), 1301 'sanitize_callback' => 'wp_parse_id_list',1302 1299 ); 1303 1300 … … 1305 1302 'description' => __( 'Limit result set to specific ids.' ), 1306 1303 'type' => 'array', 1304 'items' => array( 1305 'type' => 'integer', 1306 ), 1307 1307 'default' => array(), 1308 'sanitize_callback' => 'wp_parse_id_list',1309 1308 ); 1310 1309 … … 1312 1311 'default' => null, 1313 1312 'description' => __( 'Limit result set to that of a particular comment karma. Requires authorization.' ), 1314 'sanitize_callback' => 'absint',1315 1313 'type' => 'integer', 1316 'validate_callback' => 'rest_validate_request_arg',1317 1314 ); 1318 1315 … … 1320 1317 'description' => __( 'Offset the result set by a specific number of comments.' ), 1321 1318 'type' => 'integer', 1322 'sanitize_callback' => 'absint',1323 'validate_callback' => 'rest_validate_request_arg',1324 1319 ); 1325 1320 … … 1327 1322 'description' => __( 'Order sort attribute ascending or descending.' ), 1328 1323 'type' => 'string', 1329 'sanitize_callback' => 'sanitize_key',1330 'validate_callback' => 'rest_validate_request_arg',1331 1324 'default' => 'desc', 1332 1325 'enum' => array( … … 1339 1332 'description' => __( 'Sort collection by object attribute.' ), 1340 1333 'type' => 'string', 1341 'sanitize_callback' => 'sanitize_key',1342 'validate_callback' => 'rest_validate_request_arg',1343 1334 'default' => 'date_gmt', 1344 1335 'enum' => array( … … 1356 1347 'default' => array(), 1357 1348 'description' => __( 'Limit result set to resources of specific parent ids.' ), 1358 'sanitize_callback' => 'wp_parse_id_list',1359 1349 'type' => 'array', 1350 'items' => array( 1351 'type' => 'integer', 1352 ), 1360 1353 ); 1361 1354 … … 1363 1356 'default' => array(), 1364 1357 'description' => __( 'Ensure result set excludes specific parent ids.' ), 1365 'sanitize_callback' => 'wp_parse_id_list',1366 1358 'type' => 'array', 1359 'items' => array( 1360 'type' => 'integer', 1361 ), 1367 1362 ); 1368 1363 … … 1371 1366 'description' => __( 'Limit result set to resources assigned to specific post ids.' ), 1372 1367 'type' => 'array', 1373 'sanitize_callback' => 'wp_parse_id_list', 1368 'items' => array( 1369 'type' => 'integer', 1370 ), 1374 1371 ); 1375 1372 -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
r39104 r39105 1976 1976 'type' => 'integer', 1977 1977 ), 1978 'arg_options' => array(1979 'sanitize_callback' => 'wp_parse_id_list',1980 ),1981 'context' => array( 'view', 'edit' ),1982 );1983 $schema['properties'][ $base . '_exclude' ] = array(1984 'description' => sprintf( __( 'The terms in the %s taxonomy that should not be assigned to the object.' ), $taxonomy->name ),1985 'type' => 'array',1986 'items' => array(1987 'type' => 'integer',1988 ),1989 'arg_options' => array(1990 'sanitize_callback' => 'wp_parse_id_list',1991 ),1992 1978 'context' => array( 'view', 'edit' ), 1993 1979 ); … … 2014 2000 'type' => 'string', 2015 2001 'format' => 'date-time', 2016 'validate_callback' => 'rest_validate_request_arg',2017 2002 ); 2018 2003 … … 2021 2006 'description' => __( 'Limit result set to posts assigned to specific authors.' ), 2022 2007 'type' => 'array', 2008 'items' => array( 2009 'type' => 'integer', 2010 ), 2023 2011 'default' => array(), 2024 'sanitize_callback' => 'wp_parse_id_list',2025 2012 ); 2026 2013 $params['author_exclude'] = array( 2027 2014 'description' => __( 'Ensure result set excludes posts assigned to specific authors.' ), 2028 2015 'type' => 'array', 2016 'items' => array( 2017 'type' => 'integer', 2018 ), 2029 2019 'default' => array(), 2030 'sanitize_callback' => 'wp_parse_id_list',2031 2020 ); 2032 2021 } … … 2036 2025 'type' => 'string', 2037 2026 'format' => 'date-time', 2038 'validate_callback' => 'rest_validate_request_arg',2039 2027 ); 2040 2028 … … 2042 2030 'description' => __( 'Ensure result set excludes specific ids.' ), 2043 2031 'type' => 'array', 2032 'items' => array( 2033 'type' => 'integer', 2034 ), 2044 2035 'default' => array(), 2045 'sanitize_callback' => 'wp_parse_id_list',2046 2036 ); 2047 2037 … … 2049 2039 'description' => __( 'Limit result set to specific ids.' ), 2050 2040 'type' => 'array', 2041 'items' => array( 2042 'type' => 'integer', 2043 ), 2051 2044 'default' => array(), 2052 'sanitize_callback' => 'wp_parse_id_list',2053 2045 ); 2054 2046 … … 2057 2049 'description' => __( 'Limit result set to resources with a specific menu_order value.' ), 2058 2050 'type' => 'integer', 2059 'sanitize_callback' => 'absint',2060 'validate_callback' => 'rest_validate_request_arg',2061 2051 ); 2062 2052 } … … 2065 2055 'description' => __( 'Offset the result set by a specific number of items.' ), 2066 2056 'type' => 'integer', 2067 'sanitize_callback' => 'absint',2068 'validate_callback' => 'rest_validate_request_arg',2069 2057 ); 2070 2058 … … 2074 2062 'default' => 'desc', 2075 2063 'enum' => array( 'asc', 'desc' ), 2076 'validate_callback' => 'rest_validate_request_arg',2077 2064 ); 2078 2065 … … 2089 2076 'slug', 2090 2077 ), 2091 'validate_callback' => 'rest_validate_request_arg',2092 2078 ); 2093 2079 … … 2102 2088 'description' => __( 'Limit result set to those of particular parent ids.' ), 2103 2089 'type' => 'array', 2104 'sanitize_callback' => 'wp_parse_id_list', 2090 'items' => array( 2091 'type' => 'integer', 2092 ), 2105 2093 'default' => array(), 2106 2094 ); … … 2108 2096 'description' => __( 'Limit result set to all items except those of a particular parent id.' ), 2109 2097 'type' => 'array', 2110 'sanitize_callback' => 'wp_parse_id_list', 2098 'items' => array( 2099 'type' => 'integer', 2100 ), 2111 2101 'default' => array(), 2112 2102 ); … … 2138 2128 'description' => sprintf( __( 'Limit result set to all items that have the specified term assigned in the %s taxonomy.' ), $base ), 2139 2129 'type' => 'array', 2140 'sanitize_callback' => 'wp_parse_id_list', 2130 'items' => array( 2131 'type' => 'integer', 2132 ), 2133 'default' => array(), 2134 ); 2135 2136 $params[ $base . '_exclude' ] = array( 2137 'description' => sprintf( __( 'Limit result set to all items except those that have the specified term assigned in the %s taxonomy.' ), $base ), 2138 'type' => 'array', 2139 'items' => array( 2140 'type' => 'integer', 2141 ), 2141 2142 'default' => array(), 2142 2143 ); … … 2147 2148 'description' => __( 'Limit result set to items that are sticky.' ), 2148 2149 'type' => 'boolean', 2149 'sanitize_callback' => 'rest_parse_request_arg',2150 2150 ); 2151 2151 } -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php
r39103 r39105 305 305 'description' => __( 'Limit results to resources associated with a specific post type.' ), 306 306 'type' => 'string', 307 'validate_callback' => 'rest_validate_request_arg',308 307 ); 309 308 return $new_params; -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php
r39033 r39105 888 888 'description' => __( 'Ensure result set excludes specific ids.' ), 889 889 'type' => 'array', 890 'items' => array( 891 'type' => 'integer', 892 ), 890 893 'default' => array(), 891 'sanitize_callback' => 'wp_parse_id_list',892 894 ); 893 895 … … 895 897 'description' => __( 'Limit result set to specific ids.' ), 896 898 'type' => 'array', 899 'items' => array( 900 'type' => 'integer', 901 ), 897 902 'default' => array(), 898 'sanitize_callback' => 'wp_parse_id_list',899 903 ); 900 904 … … 903 907 'description' => __( 'Offset the result set by a specific number of items.' ), 904 908 'type' => 'integer', 905 'sanitize_callback' => 'absint',906 'validate_callback' => 'rest_validate_request_arg',907 909 ); 908 910 } … … 911 913 'description' => __( 'Order sort attribute ascending or descending.' ), 912 914 'type' => 'string', 913 'sanitize_callback' => 'sanitize_key',914 915 'default' => 'asc', 915 916 'enum' => array( … … 917 918 'desc', 918 919 ), 919 'validate_callback' => 'rest_validate_request_arg',920 920 ); 921 921 … … 923 923 'description' => __( 'Sort collection by resource attribute.' ), 924 924 'type' => 'string', 925 'sanitize_callback' => 'sanitize_key',926 925 'default' => 'name', 927 926 'enum' => array( … … 934 933 'count', 935 934 ), 936 'validate_callback' => 'rest_validate_request_arg',937 935 ); 938 936 … … 941 939 'type' => 'boolean', 942 940 'default' => false, 943 'sanitize_callback' => 'rest_sanitize_request_arg',944 'validate_callback' => 'rest_validate_request_arg',945 941 ); 946 942 … … 949 945 'description' => __( 'Limit result set to resources assigned to a specific parent.' ), 950 946 'type' => 'integer', 951 'sanitize_callback' => 'absint',952 'validate_callback' => 'rest_validate_request_arg',953 947 ); 954 948 } … … 958 952 'type' => 'integer', 959 953 'default' => null, 960 'validate_callback' => 'rest_validate_request_arg',961 954 ); 962 955 … … 964 957 'description' => __( 'Limit result set to resources with a specific slug.' ), 965 958 'type' => 'string', 966 'validate_callback' => 'rest_validate_request_arg',967 959 ); 968 960 -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
r39096 r39105 1103 1103 ), 1104 1104 'context' => array( 'edit' ), 1105 'arg_options' => array(1106 'sanitize_callback' => 'wp_parse_slug_list',1107 ),1108 1105 ), 1109 1106 'password' => array( … … 1172 1169 'description' => __( 'Ensure result set excludes specific ids.' ), 1173 1170 'type' => 'array', 1171 'items' => array( 1172 'type' => 'integer', 1173 ), 1174 1174 'default' => array(), 1175 'sanitize_callback' => 'wp_parse_id_list',1176 1175 ); 1177 1176 … … 1179 1178 'description' => __( 'Limit result set to specific ids.' ), 1180 1179 'type' => 'array', 1180 'items' => array( 1181 'type' => 'integer', 1182 ), 1181 1183 'default' => array(), 1182 'sanitize_callback' => 'wp_parse_id_list',1183 1184 ); 1184 1185 … … 1186 1187 'description' => __( 'Offset the result set by a specific number of items.' ), 1187 1188 'type' => 'integer', 1188 'sanitize_callback' => 'absint',1189 'validate_callback' => 'rest_validate_request_arg',1190 1189 ); 1191 1190 … … 1194 1193 'description' => __( 'Order sort attribute ascending or descending.' ), 1195 1194 'enum' => array( 'asc', 'desc' ), 1196 'sanitize_callback' => 'sanitize_key',1197 1195 'type' => 'string', 1198 'validate_callback' => 'rest_validate_request_arg',1199 1196 ); 1200 1197 … … 1211 1208 'url', 1212 1209 ), 1213 'sanitize_callback' => 'sanitize_key',1214 1210 'type' => 'string', 1215 'validate_callback' => 'rest_validate_request_arg',1216 1211 ); 1217 1212 … … 1219 1214 'description' => __( 'Limit result set to resources with a specific slug.' ), 1220 1215 'type' => 'string', 1221 'validate_callback' => 'rest_validate_request_arg',1222 1216 ); 1223 1217 … … 1225 1219 'description' => __( 'Limit result set to resources matching at least one specific role provided. Accepts csv list or single role.' ), 1226 1220 'type' => 'array', 1227 'sanitize_callback' => 'wp_parse_slug_list', 1221 'items' => array( 1222 'type' => 'string', 1223 ), 1228 1224 ); 1229 1225 -
trunk/tests/phpunit/tests/rest-api/rest-categories-controller.php
r38975 r39105 429 429 } 430 430 431 public function test_get_terms_invalid_parent_arg() { 432 $category1 = $this->factory->category->create( array( 'name' => 'Parent' ) ); 433 $this->factory->category->create( array( 'name' => 'Child', 'parent' => $category1 ) ); 434 $request = new WP_REST_Request( 'GET', '/wp/v2/categories' ); 435 $request->set_param( 'parent', 'invalid-parent' ); 436 $response = $this->server->dispatch( $request ); 437 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 438 } 439 431 440 public function test_get_terms_private_taxonomy() { 432 441 register_taxonomy( 'robin', 'post', array( 'public' => false ) ); -
trunk/tests/phpunit/tests/rest-api/rest-comments-controller.php
r39101 r39105 301 301 $this->assertEquals( 2, count( $data ) ); 302 302 $this->assertEquals( $id3, $data[0]['id'] ); 303 // Orderby=>invalid should fail. 304 $request->set_param( 'orderby', 'invalid' ); 305 $response = $this->server->dispatch( $request ); 306 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 307 // fails on invalid id. 308 $request->set_param( 'orderby', array( 'include' ) ); 309 $request->set_param( 'include', array( 'invalid' ) ); 310 $response = $this->server->dispatch( $request ); 311 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 303 312 } 304 313 … … 321 330 $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) ); 322 331 $this->assertFalse( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) ); 332 333 // fails on invalid id. 334 $request->set_param( 'exclude', array( 'invalid' ) ); 335 $response = $this->server->dispatch( $request ); 336 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 323 337 } 324 338 … … 344 358 $response = $this->server->dispatch( $request ); 345 359 $this->assertCount( 2, $response->get_data() ); 360 // 'offset' with invalid value errors. 361 $request->set_param( 'offset', 'moreplease' ); 362 $response = $this->server->dispatch( $request ); 363 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 346 364 } 347 365 … … 365 383 $data = $response->get_data(); 366 384 $this->assertEquals( self::$approved_id, $data[0]['id'] ); 385 // order=>asc,id should fail 386 $request->set_param( 'order', 'asc,id' ); 387 $response = $this->server->dispatch( $request ); 388 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 367 389 } 368 390 … … 403 425 $comments = $response->get_data(); 404 426 $this->assertCount( 2, $comments ); 427 // Invalid author param errors 428 $request->set_param( 'author', 'skippy' ); 429 $response = $this->server->dispatch( $request ); 430 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 405 431 // Unavailable to unauthenticated; defaults to error 406 432 wp_set_current_user( 0 ); 433 $request->set_param( 'author', array( self::$author_id, self::$subscriber_id ) ); 407 434 $response = $this->server->dispatch( $request ); 408 435 $this->assertErrorResponse( 'rest_forbidden_param', $response, 401 ); … … 442 469 $comments = $response->get_data(); 443 470 $this->assertCount( 2, $comments ); 471 // 'author_exclude' for both invalid author 472 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 473 $request->set_param( 'author_exclude', 'skippy' ); 474 $response = $this->server->dispatch( $request ); 475 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 444 476 // Unavailable to unauthenticated; defaults to error 445 477 wp_set_current_user( 0 ); 478 $request->set_param( 'author_exclude', array( self::$author_id, self::$subscriber_id ) ); 446 479 $response = $this->server->dispatch( $request ); 447 480 $this->assertErrorResponse( 'rest_forbidden_param', $response, 401 ); … … 471 504 $response = $this->server->dispatch( $request ); 472 505 $this->assertCount( 2, $response->get_data() ); 506 // Invalid parent should error 507 $request->set_param( 'parent', 'invalid' ); 508 $response = $this->server->dispatch( $request ); 509 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 473 510 } 474 511 … … 496 533 $response = $this->server->dispatch( $request ); 497 534 $this->assertCount( 3, $response->get_data() ); 535 // Invalid parent id should error 536 $request->set_param( 'parent_exclude', 'invalid' ); 537 $response = $this->server->dispatch( $request ); 538 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 498 539 } 499 540 … … 958 999 } 959 1000 1001 public function test_create_comment_invalid_email() { 1002 $post_id = $this->factory->post->create(); 1003 wp_set_current_user( self::$admin_id ); 1004 1005 $params = array( 1006 'post' => $post_id, 1007 'author' => self::$admin_id, 1008 'author_name' => 'Comic Book Guy', 1009 'author_email' => 'hello:)', 1010 'author_url' => 'http://androidsdungeon.com', 1011 'content' => 'Worst Comment Ever!', 1012 'date' => '2014-11-07T10:14:25', 1013 ); 1014 1015 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); 1016 $request->add_header( 'content-type', 'application/json' ); 1017 $request->set_body( wp_json_encode( $params ) ); 1018 1019 $response = $this->server->dispatch( $request ); 1020 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 1021 } 1022 960 1023 public function test_create_item_current_user() { 961 1024 $user_id = $this->factory->user->create( array( … … 1056 1119 1057 1120 $this->assertErrorResponse( 'rest_comment_invalid_karma', $response, 403 ); 1121 } 1122 1123 public function test_create_comment_invalid_post() { 1124 wp_set_current_user( self::$subscriber_id ); 1125 1126 $params = array( 1127 'post' => 'some-slug', 1128 'author_name' => 'Homer Jay Simpson', 1129 'author_email' => 'chunkylover53@aol.com', 1130 'author_url' => 'http://compuglobalhypermeganet.com', 1131 'content' => 'Here\’s to alcohol: the cause of, and solution to, all of life\’s problems.', 1132 'author' => self::$subscriber_id, 1133 ); 1134 1135 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); 1136 $request->add_header( 'content-type', 'application/json' ); 1137 $request->set_body( wp_json_encode( $params ) ); 1138 $response = $this->server->dispatch( $request ); 1139 1140 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 1141 } 1142 1143 public function test_create_comment_karma_invalid_value() { 1144 wp_set_current_user( self::$subscriber_id ); 1145 1146 $params = array( 1147 'post' => self::$post_id, 1148 'author_name' => 'Homer Jay Simpson', 1149 'author_email' => 'chunkylover53@aol.com', 1150 'author_url' => 'http://compuglobalhypermeganet.com', 1151 'content' => 'Here\’s to alcohol: the cause of, and solution to, all of life\’s problems.', 1152 'author' => self::$subscriber_id, 1153 'karma' => 'themostkarmaever', 1154 ); 1155 1156 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); 1157 $request->add_header( 'content-type', 'application/json' ); 1158 $request->set_body( wp_json_encode( $params ) ); 1159 $response = $this->server->dispatch( $request ); 1160 1161 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 1058 1162 } 1059 1163 … … 1894 1998 $this->assertArrayHasKey( 'status', $properties ); 1895 1999 $this->assertArrayHasKey( 'type', $properties ); 2000 2001 $this->assertEquals( '127.0.0.1', $properties['author_ip']['default'] ); 2002 $this->assertEquals( 0, $properties['parent']['default'] ); 2003 $this->assertEquals( 0, $properties['post']['default'] ); 1896 2004 } 1897 2005 -
trunk/tests/phpunit/tests/rest-api/rest-pages-controller.php
r39047 r39105 96 96 $this->assertEquals( 1, count( $data ) ); 97 97 $this->assertEquals( $id2, $data[0]['id'] ); 98 // Invalid parent should fail 99 $request->set_param( 'parent', 'some-slug' ); 100 $response = $this->server->dispatch( $request ); 101 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 98 102 } 99 103 … … 130 134 $this->assertEquals( 1, count( $data ) ); 131 135 $this->assertEquals( $id1, $data[0]['id'] ); 136 // Invalid parent_exclude should error 137 $request->set_param( 'parent_exclude', 'some-slug' ); 138 $response = $this->server->dispatch( $request ); 139 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 132 140 } 133 141 … … 157 165 $this->assertEquals( $id2, $data[2]['id'] ); 158 166 $this->assertEquals( $id3, $data[3]['id'] ); 167 // Invalid menu_order should fail 168 $request = new WP_REST_Request( 'GET', '/wp/v2/pages' ); 169 $request->set_param( 'menu_order', 'top-first' ); 170 $response = $this->server->dispatch( $request ); 171 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 159 172 } 160 173 -
trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php
r39104 r39105 93 93 'before', 94 94 'categories', 95 'categories_exclude', 95 96 'context', 96 97 'exclude', … … 106 107 'sticky', 107 108 'tags', 109 'tags_exclude', 108 110 ), $keys ); 109 111 } … … 184 186 $this->assertNotEquals( self::$editor_id, $data[0]['author'] ); 185 187 $this->assertNotEquals( self::$editor_id, $data[1]['author'] ); 188 // invalid author_exclude errors 189 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 190 $request->set_param( 'author_exclude', 'invalid' ); 191 $response = $this->server->dispatch( $request ); 192 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 186 193 } 187 194 … … 203 210 $this->assertEquals( 2, count( $data ) ); 204 211 $this->assertEquals( $id1, $data[0]['id'] ); 212 // Invalid include should error 213 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 214 $request->set_param( 'include', 'invalid' ); 215 $response = $this->server->dispatch( $request ); 216 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 205 217 } 206 218 … … 225 237 $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) ); 226 238 $this->assertFalse( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) ); 239 240 $request->set_param( 'exclude', 'invalid' ); 241 $response = $this->server->dispatch( $request ); 242 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 227 243 } 228 244 … … 407 423 $data = $response->get_data(); 408 424 $this->assertEquals( 'Apple Cobbler', $data[0]['title']['rendered'] ); 425 // order=>asc,id should fail 426 $request->set_param( 'order', 'asc,id' ); 427 $response = $this->server->dispatch( $request ); 428 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 429 // orderby=>content should fail (invalid param test) 430 $request->set_param( 'order', 'asc' ); 431 $request->set_param( 'orderby', 'content' ); 432 $response = $this->server->dispatch( $request ); 433 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 409 434 } 410 435 … … 457 482 $response = $this->server->dispatch( $request ); 458 483 $this->assertCount( 2, $response->get_data() ); 484 // Invalid 'offset' should error 485 $request->set_param( 'offset', 'moreplease' ); 486 $response = $this->server->dispatch( $request ); 487 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 459 488 } 460 489 … … 513 542 $response = $this->server->dispatch( $request ); 514 543 $this->assertCount( 1, $response->get_data() ); 544 545 $request->set_param( 'tags', array( 'my-tag' ) ); 546 $response = $this->server->dispatch( $request ); 547 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 515 548 } 516 549 … … 535 568 $this->assertCount( 1, $data ); 536 569 $this->assertEquals( $id2, $data[0]['id'] ); 570 571 $request->set_param( 'tags_exclude', array( 'my-tag' ) ); 572 $response = $this->server->dispatch( $request ); 573 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 537 574 } 538 575 … … 552 589 $post = $posts[0]; 553 590 $this->assertEquals( $id2, $post['id'] ); 591 592 $request->set_param( 'sticky', 'nothanks' ); 593 $response = $this->server->dispatch( $request ); 594 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 554 595 } 555 596 … … 1990 2031 $data = $response->get_data(); 1991 2032 $properties = $data['schema']['properties']; 1992 $this->assertEquals( 2 5, count( $properties ) );2033 $this->assertEquals( 23, count( $properties ) ); 1993 2034 $this->assertArrayHasKey( 'author', $properties ); 1994 2035 $this->assertArrayHasKey( 'comment_status', $properties ); … … 2013 2054 $this->assertArrayHasKey( 'type', $properties ); 2014 2055 $this->assertArrayHasKey( 'tags', $properties ); 2015 $this->assertArrayHasKey( 'tags_exclude', $properties );2016 2056 $this->assertArrayHasKey( 'categories', $properties ); 2017 $this->assertArrayHasKey( 'categories_exclude', $properties );2018 2057 } 2019 2058 -
trunk/tests/phpunit/tests/rest-api/rest-tags-controller.php
r38974 r39105 99 99 $this->assertEquals( 'Season 5', $data[0]['name'] ); 100 100 $this->assertEquals( 'The Be Sharps', $data[1]['name'] ); 101 // invalid value should fail 102 $request->set_param( 'hide_empty', 'nothanks' ); 103 $response = $this->server->dispatch( $request ); 104 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 101 105 } 102 106 … … 118 122 $this->assertEquals( 2, count( $data ) ); 119 123 $this->assertEquals( $id3, $data[0]['id'] ); 124 // Include invalid value shoud fail 125 $request->set_param( 'include', array( 'myterm' ) ); 126 $response = $this->server->dispatch( $request ); 127 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 120 128 } 121 129 … … 133 141 $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) ); 134 142 $this->assertFalse( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) ); 143 // Invalid exclude value should fail 144 $request->set_param( 'exclude', array( 'invalid' ) ); 145 $response = $this->server->dispatch( $request ); 146 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 135 147 } 136 148 … … 152 164 $response = $this->server->dispatch( $request ); 153 165 $this->assertCount( 2, $response->get_data() ); 166 // 'offset' invalid value shoudl fail 167 $request->set_param( 'offset', 'moreplease' ); 168 $response = $this->server->dispatch( $request ); 169 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 154 170 } 155 171 … … 182 198 $this->assertEquals( 2, count( $data ) ); 183 199 $this->assertEquals( 'Apple', $data[0]['name'] ); 200 // Invalid orderby should fail. 201 $request->set_param( 'orderby', 'invalid' ); 202 $response = $this->server->dispatch( $request ); 203 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 184 204 } 185 205 … … 232 252 $this->assertEquals( 2, count( $data ) ); 233 253 $this->assertEquals( 'DC', $data[0]['name'] ); 254 255 // Invalid post should error. 256 $request = new WP_REST_Request( 'GET', '/wp/v2/tags' ); 257 $request->set_param( 'post', 'invalid-post' ); 258 $response = $this->server->dispatch( $request ); 259 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 234 260 } 235 261 -
trunk/tests/phpunit/tests/rest-api/rest-users-controller.php
r39096 r39105 364 364 } 365 365 366 public function test_get_items_invalid_order() { 367 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 368 $request->set_param( 'order', 'asc,id' ); 369 $response = $this->server->dispatch( $request ); 370 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 371 } 372 373 public function test_get_items_invalid_orderby() { 374 $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); 375 $request->set_param( 'orderby', 'invalid' ); 376 $response = $this->server->dispatch( $request ); 377 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 378 } 379 366 380 public function test_get_items_offset() { 367 381 wp_set_current_user( self::$user ); … … 380 394 $response = $this->server->dispatch( $request ); 381 395 $this->assertCount( 2, $response->get_data() ); 396 // 'offset' invalid value should error 397 $request->set_param( 'offset', 'moreplease' ); 398 $response = $this->server->dispatch( $request ); 399 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 382 400 } 383 401 … … 400 418 $this->assertEquals( 2, count( $data ) ); 401 419 $this->assertEquals( $id3, $data[0]['id'] ); 420 // Invalid include should fail 421 $request->set_param( 'include', 'invalid' ); 422 $response = $this->server->dispatch( $request ); 423 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 402 424 // No privileges 425 $request->set_param( 'include', array( $id3, $id1 ) ); 403 426 wp_set_current_user( 0 ); 404 427 $response = $this->server->dispatch( $request ); … … 422 445 $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) ); 423 446 $this->assertFalse( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) ); 447 // Invalid exlude value should error. 448 $request->set_param( 'exclude', 'none-of-those-please' ); 449 $response = $this->server->dispatch( $request ); 450 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 424 451 } 425 452
Note: See TracChangeset
for help on using the changeset viewer.