Ticket #38617: 38617.3.diff
File 38617.3.diff, 43.4 KB (added by , 8 years ago) |
---|
-
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 2749b12..405fc91 100644
a b class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { 594 594 'description' => __( 'Limit result set to attachments of a particular media type.' ), 595 595 'type' => 'string', 596 596 'enum' => array_keys( $media_types ), 597 'validate_callback' => 'rest_validate_request_arg',598 597 ); 599 598 600 599 $params['mime_type'] = array( -
src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php index 3454dc1..fc081f9 100644
a b class WP_REST_Comments_Controller extends WP_REST_Controller { 1102 1102 'type' => 'string', 1103 1103 'format' => 'ipv4', 1104 1104 'context' => array( 'edit' ), 1105 'arg_options' => array( 1106 'default' => '127.0.0.1', 1107 ), 1105 'default' => '127.0.0.1', 1108 1106 ), 1109 1107 'author_name' => array( 1110 1108 'description' => __( 'Display name for the object author.' ), … … class WP_REST_Comments_Controller extends WP_REST_Controller { 1176 1174 'description' => __( 'The id for the parent of the object.' ), 1177 1175 'type' => 'integer', 1178 1176 'context' => array( 'view', 'edit', 'embed' ), 1179 'arg_options' => array( 1180 'default' => 0, 1181 ), 1177 'default' => 0, 1182 1178 ), 1183 1179 'post' => array( 1184 1180 'description' => __( 'The id of the associated post object.' ), 1185 1181 'type' => 'integer', 1186 1182 'context' => array( 'view', 'edit' ), 1187 'arg_options' => array( 1188 'default' => 0, 1189 ), 1183 'default' => 0, 1190 1184 ), 1191 1185 'status' => array( 1192 1186 'description' => __( 'State of the object.' ), … … class WP_REST_Comments_Controller extends WP_REST_Controller { 1252 1246 'description' => __( 'Limit response to resources published after a given ISO8601 compliant date.' ), 1253 1247 'type' => 'string', 1254 1248 'format' => 'date-time', 1255 'validate_callback' => 'rest_validate_request_arg',1256 1249 ); 1257 1250 1258 1251 $query_params['author'] = array( 1259 1252 'description' => __( 'Limit result set to comments assigned to specific user ids. Requires authorization.' ), 1260 'sanitize_callback' => 'wp_parse_id_list',1261 1253 'type' => 'array', 1254 'items' => array( 1255 'type' => 'integer', 1256 ), 1262 1257 ); 1263 1258 1264 1259 $query_params['author_exclude'] = array( 1265 1260 'description' => __( 'Ensure result set excludes comments assigned to specific user ids. Requires authorization.' ), 1266 'sanitize_callback' => 'wp_parse_id_list',1267 1261 'type' => 'array', 1262 'items' => array( 1263 'type' => 'integer', 1264 ), 1268 1265 ); 1269 1266 1270 1267 $query_params['author_email'] = array( 1271 1268 'default' => null, 1272 1269 'description' => __( 'Limit result set to that from a specific author email. Requires authorization.' ), 1273 1270 'format' => 'email', 1274 'sanitize_callback' => 'sanitize_email',1275 1271 'type' => 'string', 1276 1272 ); 1277 1273 … … class WP_REST_Comments_Controller extends WP_REST_Controller { 1279 1275 'description' => __( 'Limit response to resources published before a given ISO8601 compliant date.' ), 1280 1276 'type' => 'string', 1281 1277 'format' => 'date-time', 1282 'validate_callback' => 'rest_validate_request_arg',1283 1278 ); 1284 1279 1285 1280 $query_params['exclude'] = array( 1286 1281 'description' => __( 'Ensure result set excludes specific ids.' ), 1287 1282 'type' => 'array', 1283 'items' => array( 1284 'type' => 'integer', 1285 ), 1288 1286 'default' => array(), 1289 'sanitize_callback' => 'wp_parse_id_list',1290 1287 ); 1291 1288 1292 1289 $query_params['include'] = array( 1293 1290 'description' => __( 'Limit result set to specific ids.' ), 1294 1291 'type' => 'array', 1292 'items' => array( 1293 'type' => 'integer', 1294 ), 1295 1295 'default' => array(), 1296 'sanitize_callback' => 'wp_parse_id_list',1297 1296 ); 1298 1297 1299 1298 $query_params['karma'] = array( 1300 1299 'default' => null, 1301 1300 'description' => __( 'Limit result set to that of a particular comment karma. Requires authorization.' ), 1302 'sanitize_callback' => 'absint',1303 1301 'type' => 'integer', 1304 'validate_callback' => 'rest_validate_request_arg',1305 1302 ); 1306 1303 1307 1304 $query_params['offset'] = array( 1308 1305 'description' => __( 'Offset the result set by a specific number of comments.' ), 1309 1306 'type' => 'integer', 1310 'sanitize_callback' => 'absint',1311 'validate_callback' => 'rest_validate_request_arg',1312 1307 ); 1313 1308 1314 1309 $query_params['order'] = array( 1315 1310 'description' => __( 'Order sort attribute ascending or descending.' ), 1316 1311 'type' => 'string', 1317 'sanitize_callback' => 'sanitize_key',1318 'validate_callback' => 'rest_validate_request_arg',1319 1312 'default' => 'desc', 1320 1313 'enum' => array( 1321 1314 'asc', … … class WP_REST_Comments_Controller extends WP_REST_Controller { 1326 1319 $query_params['orderby'] = array( 1327 1320 'description' => __( 'Sort collection by object attribute.' ), 1328 1321 'type' => 'string', 1329 'sanitize_callback' => 'sanitize_key',1330 'validate_callback' => 'rest_validate_request_arg',1331 1322 'default' => 'date_gmt', 1332 1323 'enum' => array( 1333 1324 'date', … … class WP_REST_Comments_Controller extends WP_REST_Controller { 1343 1334 $query_params['parent'] = array( 1344 1335 'default' => array(), 1345 1336 'description' => __( 'Limit result set to resources of specific parent ids.' ), 1346 'sanitize_callback' => 'wp_parse_id_list',1347 1337 'type' => 'array', 1338 'items' => array( 1339 'type' => 'integer', 1340 ), 1348 1341 ); 1349 1342 1350 1343 $query_params['parent_exclude'] = array( 1351 1344 'default' => array(), 1352 1345 'description' => __( 'Ensure result set excludes specific parent ids.' ), 1353 'sanitize_callback' => 'wp_parse_id_list',1354 1346 'type' => 'array', 1347 'items' => array( 1348 'type' => 'integer', 1349 ), 1355 1350 ); 1356 1351 1357 1352 $query_params['post'] = array( 1358 1353 'default' => array(), 1359 1354 'description' => __( 'Limit result set to resources assigned to specific post ids.' ), 1360 1355 'type' => 'array', 1361 'sanitize_callback' => 'wp_parse_id_list', 1356 'items' => array( 1357 'type' => 'integer', 1358 ), 1362 1359 ); 1363 1360 1364 1361 $query_params['status'] = array( -
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 0122f9a..723fc95 100644
a b class WP_REST_Posts_Controller extends WP_REST_Controller { 1975 1975 'items' => array( 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 ); 1994 1980 } … … class WP_REST_Posts_Controller extends WP_REST_Controller { 2013 1999 'description' => __( 'Limit response to resources published after a given ISO8601 compliant date.' ), 2014 2000 'type' => 'string', 2015 2001 'format' => 'date-time', 2016 'validate_callback' => 'rest_validate_request_arg',2017 2002 ); 2018 2003 2019 2004 if ( post_type_supports( $this->post_type, 'author' ) ) { 2020 2005 $params['author'] = array( 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 } 2033 2022 … … class WP_REST_Posts_Controller extends WP_REST_Controller { 2035 2024 'description' => __( 'Limit response to resources published before a given ISO8601 compliant date.' ), 2036 2025 'type' => 'string', 2037 2026 'format' => 'date-time', 2038 'validate_callback' => 'rest_validate_request_arg',2039 2027 ); 2040 2028 2041 2029 $params['exclude'] = array( 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 2048 2038 $params['include'] = array( 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 2055 2047 if ( 'page' === $this->post_type || post_type_supports( $this->post_type, 'page-attributes' ) ) { 2056 2048 $params['menu_order'] = array( 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 } 2063 2053 2064 2054 $params['offset'] = array( 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 2071 2059 $params['order'] = array( … … class WP_REST_Posts_Controller extends WP_REST_Controller { 2073 2061 'type' => 'string', 2074 2062 'default' => 'desc', 2075 2063 'enum' => array( 'asc', 'desc' ), 2076 'validate_callback' => 'rest_validate_request_arg',2077 2064 ); 2078 2065 2079 2066 $params['orderby'] = array( … … class WP_REST_Posts_Controller extends WP_REST_Controller { 2088 2075 'title', 2089 2076 'slug', 2090 2077 ), 2091 'validate_callback' => 'rest_validate_request_arg',2092 2078 ); 2093 2079 2094 2080 if ( 'page' === $this->post_type || post_type_supports( $this->post_type, 'page-attributes' ) ) { … … class WP_REST_Posts_Controller extends WP_REST_Controller { 2101 2087 $params['parent'] = array( 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 ); 2107 2095 $params['parent_exclude'] = array( 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 ); 2113 2103 } … … class WP_REST_Posts_Controller extends WP_REST_Controller { 2135 2125 $params[ $base ] = array( 2136 2126 'description' => sprintf( __( 'Limit result set to all items that have the specified term assigned in the %s taxonomy.' ), $base ), 2137 2127 'type' => 'array', 2138 'sanitize_callback' => 'wp_parse_id_list', 2128 'items' => array( 2129 'type' => 'integer', 2130 ), 2131 'default' => array(), 2132 ); 2133 2134 $params[ $base . '_exclude' ] = array( 2135 'description' => sprintf( __( 'Limit result set to all items except those that have the specified term assigned in the %s taxonomy.' ), $base ), 2136 'type' => 'array', 2137 'items' => array( 2138 'type' => 'integer', 2139 ), 2139 2140 'default' => array(), 2140 2141 ); 2141 2142 } … … class WP_REST_Posts_Controller extends WP_REST_Controller { 2144 2145 $params['sticky'] = array( 2145 2146 'description' => __( 'Limit result set to items that are sticky.' ), 2146 2147 'type' => 'boolean', 2147 'sanitize_callback' => 'rest_parse_request_arg',2148 2148 ); 2149 2149 } 2150 2150 -
src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php
diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php index 98a5e21..0f253a4 100644
a b class WP_REST_Taxonomies_Controller extends WP_REST_Controller { 301 301 $new_params['type'] = array( 302 302 'description' => __( 'Limit results to resources associated with a specific post type.' ), 303 303 'type' => 'string', 304 'validate_callback' => 'rest_validate_request_arg',305 304 ); 306 305 return $new_params; 307 306 } -
src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php
diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php index ceaa26b..c9f9f91 100644
a b class WP_REST_Terms_Controller extends WP_REST_Controller { 887 887 $query_params['exclude'] = array( 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 894 896 $query_params['include'] = array( 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 901 905 if ( ! $taxonomy->hierarchical ) { 902 906 $query_params['offset'] = array( 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 } 909 911 910 912 $query_params['order'] = array( 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( 916 917 'asc', 917 918 'desc', 918 919 ), 919 'validate_callback' => 'rest_validate_request_arg',920 920 ); 921 921 922 922 $query_params['orderby'] = array( 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( 928 927 'id', … … class WP_REST_Terms_Controller extends WP_REST_Controller { 933 932 'description', 934 933 'count', 935 934 ), 936 'validate_callback' => 'rest_validate_request_arg',937 935 ); 938 936 939 937 $query_params['hide_empty'] = array( 940 938 'description' => __( 'Whether to hide resources not assigned to any posts.' ), 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 947 943 if ( $taxonomy->hierarchical ) { 948 944 $query_params['parent'] = array( 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 } 955 949 … … class WP_REST_Terms_Controller extends WP_REST_Controller { 957 951 'description' => __( 'Limit result set to resources assigned to a specific post.' ), 958 952 'type' => 'integer', 959 953 'default' => null, 960 'validate_callback' => 'rest_validate_request_arg',961 954 ); 962 955 963 956 $query_params['slug'] = array( 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 969 961 return $query_params; -
src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php index bb3737d..1256c68 100644
a b class WP_REST_Users_Controller extends WP_REST_Controller { 1102 1102 'type' => 'string', 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( 1110 1107 'description' => __( 'Password for the resource (never included).' ), … … class WP_REST_Users_Controller extends WP_REST_Controller { 1171 1168 $query_params['exclude'] = 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 1178 1177 $query_params['include'] = array( 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 1185 1186 $query_params['offset'] = array( 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 1192 1191 $query_params['order'] = array( 1193 1192 'default' => 'asc', 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 1201 1198 $query_params['orderby'] = array( … … class WP_REST_Users_Controller extends WP_REST_Controller { 1210 1207 'email', 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 1218 1213 $query_params['slug'] = array( 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 1224 1218 $query_params['roles'] = array( 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 1230 1226 return $query_params; -
tests/phpunit/tests/rest-api/rest-categories-controller.php
diff --git a/tests/phpunit/tests/rest-api/rest-categories-controller.php b/tests/phpunit/tests/rest-api/rest-categories-controller.php index 440cb45..4212f5f 100644
a b class WP_Test_REST_Categories_Controller extends WP_Test_REST_Controller_Testcas 428 428 $this->assertEquals( 'Child', $data[0]['name'] ); 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 ) ); 433 442 $this->factory->term->create( array( 'name' => 'Cape', 'taxonomy' => 'robin' ) ); -
tests/phpunit/tests/rest-api/rest-comments-controller.php
diff --git a/tests/phpunit/tests/rest-api/rest-comments-controller.php b/tests/phpunit/tests/rest-api/rest-comments-controller.php index 8dc8c4c..6e8c89f 100644
a b class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase 300 300 $data = $response->get_data(); 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 305 314 public function test_get_items_exclude_query() { … … class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase 320 329 $data = $response->get_data(); 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 325 339 public function test_get_items_offset_query() { … … class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase 343 357 $request->set_param( 'page', 3 ); 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 348 366 public function test_get_items_order_query() { … … class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase 364 382 $response = $this->server->dispatch( $request ); 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 369 391 public function test_get_items_private_post_no_permissions() { … … class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase 402 424 $this->assertEquals( 200, $response->get_status() ); 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 ); 409 436 } … … class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase 441 468 $this->assertEquals( 200, $response->get_status() ); 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 ); 448 481 } … … class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase 470 503 $request->set_param( 'parent', array( $parent_id, $parent_id2 ) ); 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 475 512 public function test_get_items_parent_exclude_arg() { … … class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase 495 532 $request->set_param( 'parent_exclude', array( $parent_id, $parent_id2 ) ); 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 500 541 public function test_get_items_search_query() { … … class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase 957 998 $this->assertEquals( $comment_id, $collection_data[0]['id'] ); 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( 962 1025 'role' => 'subscriber', … … class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase 1057 1120 $this->assertErrorResponse( 'rest_comment_invalid_karma', $response, 403 ); 1058 1121 } 1059 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 ); 1162 } 1163 1060 1164 public function test_create_comment_status_without_permission() { 1061 1165 wp_set_current_user( self::$subscriber_id ); 1062 1166 … … class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase 1726 1830 $this->assertArrayHasKey( 'post', $properties ); 1727 1831 $this->assertArrayHasKey( 'status', $properties ); 1728 1832 $this->assertArrayHasKey( 'type', $properties ); 1833 1834 $this->assertEquals( '127.0.0.1', $properties['author_ip']['default'] ); 1835 $this->assertEquals( 0, $properties['parent']['default'] ); 1836 $this->assertEquals( 0, $properties['post']['default'] ); 1729 1837 } 1730 1838 1731 1839 public function test_get_item_schema_show_avatar() { -
tests/phpunit/tests/rest-api/rest-pages-controller.php
diff --git a/tests/phpunit/tests/rest-api/rest-pages-controller.php b/tests/phpunit/tests/rest-api/rest-pages-controller.php index 2ce9afe..a571803 100644
a b class WP_Test_REST_Pages_Controller extends WP_Test_REST_Post_Type_Controller_Te 95 95 $data = $response->get_data(); 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 100 104 public function test_get_items_parents_query() { … … class WP_Test_REST_Pages_Controller extends WP_Test_REST_Post_Type_Controller_Te 129 133 $data = $response->get_data(); 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 134 142 public function test_get_items_menu_order_query() { … … class WP_Test_REST_Pages_Controller extends WP_Test_REST_Post_Type_Controller_Te 156 164 $this->assertEquals( $id4, $data[1]['id'] ); 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 161 174 public function test_get_items_min_max_pages_query() { -
tests/phpunit/tests/rest-api/rest-posts-controller.php
diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php index dcebfe8..e489667 100644
a b class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te 92 92 'author_exclude', 93 93 'before', 94 94 'categories', 95 'categories_exclude', 95 96 'context', 96 97 'exclude', 97 98 'include', … … class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te 105 106 'status', 106 107 'sticky', 107 108 'tags', 109 'tags_exclude', 108 110 ), $keys ); 109 111 } 110 112 … … class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te 183 185 $this->assertEquals( 2, count( $data ) ); 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 188 195 public function test_get_items_include_query() { … … class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te 202 209 $data = $response->get_data(); 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 207 219 public function test_get_items_exclude_query() { … … class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te 224 236 $data = $response->get_data(); 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 229 245 public function test_get_items_search_query() { … … class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te 352 368 $response = $this->server->dispatch( $request ); 353 369 $data = $response->get_data(); 354 370 $this->assertEquals( 'Apple Cobbler', $data[0]['title']['rendered'] ); 371 // order=>asc,id should fail 372 $request->set_param( 'order', 'asc,id' ); 373 $response = $this->server->dispatch( $request ); 374 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 375 // orderby=>content should fail (invalid param test) 376 $request->set_param( 'order', 'asc' ); 377 $request->set_param( 'orderby', 'content' ); 378 $response = $this->server->dispatch( $request ); 379 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 355 380 } 356 381 357 382 public function test_get_items_with_orderby_relevance() { … … class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te 402 427 $request->set_param( 'page', 3 ); 403 428 $response = $this->server->dispatch( $request ); 404 429 $this->assertCount( 2, $response->get_data() ); 430 // Invalid 'offset' should error 431 $request->set_param( 'offset', 'moreplease' ); 432 $response = $this->server->dispatch( $request ); 433 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 405 434 } 406 435 407 436 public function test_get_items_tags_query() { … … class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te 458 487 459 488 $response = $this->server->dispatch( $request ); 460 489 $this->assertCount( 1, $response->get_data() ); 490 491 $request->set_param( 'tags', array( 'my-tag' ) ); 492 $response = $this->server->dispatch( $request ); 493 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 461 494 } 462 495 463 496 public function test_get_items_tags_and_categories_exclude_query() { … … class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te 480 513 $data = $response->get_data(); 481 514 $this->assertCount( 1, $data ); 482 515 $this->assertEquals( $id2, $data[0]['id'] ); 516 517 $request->set_param( 'tags_exclude', array( 'my-tag' ) ); 518 $response = $this->server->dispatch( $request ); 519 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 483 520 } 484 521 485 522 public function test_get_items_sticky_query() { … … class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te 497 534 $posts = $response->get_data(); 498 535 $post = $posts[0]; 499 536 $this->assertEquals( $id2, $post['id'] ); 537 538 $request->set_param( 'sticky', 'nothanks' ); 539 $response = $this->server->dispatch( $request ); 540 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 500 541 } 501 542 502 543 public function test_get_items_sticky_with_post__in_query() { … … class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te 1935 1976 $response = $this->server->dispatch( $request ); 1936 1977 $data = $response->get_data(); 1937 1978 $properties = $data['schema']['properties']; 1938 $this->assertEquals( 2 5, count( $properties ) );1979 $this->assertEquals( 23, count( $properties ) ); 1939 1980 $this->assertArrayHasKey( 'author', $properties ); 1940 1981 $this->assertArrayHasKey( 'comment_status', $properties ); 1941 1982 $this->assertArrayHasKey( 'content', $properties ); … … class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te 1958 1999 $this->assertArrayHasKey( 'title', $properties ); 1959 2000 $this->assertArrayHasKey( 'type', $properties ); 1960 2001 $this->assertArrayHasKey( 'tags', $properties ); 1961 $this->assertArrayHasKey( 'tags_exclude', $properties );1962 2002 $this->assertArrayHasKey( 'categories', $properties ); 1963 $this->assertArrayHasKey( 'categories_exclude', $properties );1964 2003 } 1965 2004 1966 2005 public function test_get_additional_field_registration() { -
tests/phpunit/tests/rest-api/rest-tags-controller.php
diff --git a/tests/phpunit/tests/rest-api/rest-tags-controller.php b/tests/phpunit/tests/rest-api/rest-tags-controller.php index 0bdae85..568b15a 100644
a b class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase { 98 98 $this->assertEquals( 2, count( $data ) ); 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 103 107 public function test_get_items_include_query() { … … class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase { 117 121 $data = $response->get_data(); 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 122 130 public function test_get_items_exclude_query() { … … class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase { 132 140 $data = $response->get_data(); 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 137 149 public function test_get_items_offset_query() { … … class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase { 151 163 $request->set_param( 'page', 3 ); 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 156 172 … … class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase { 181 197 $data = $response->get_data(); 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 186 206 public function test_get_items_orderby_id() { … … class WP_Test_REST_Tags_Controller extends WP_Test_REST_Controller_Testcase { 231 251 $data = $response->get_data(); 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 236 262 public function test_get_terms_post_args_paging() { -
tests/phpunit/tests/rest-api/rest-users-controller.php
diff --git a/tests/phpunit/tests/rest-api/rest-users-controller.php b/tests/phpunit/tests/rest-api/rest-users-controller.php index 4f89ac2..7dd2540 100644
a b class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase { 363 363 $this->assertErrorResponse( 'rest_forbidden_orderby', $response, 401 ); 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 ); 368 382 // 2 users created in __construct(), plus default user … … class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase { 379 393 $request->set_param( 'page', 3 ); 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 384 402 public function test_get_items_include_query() { … … class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase { 399 417 $data = $response->get_data(); 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 ); 405 428 $data = $response->get_data(); … … class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase { 421 444 $data = $response->get_data(); 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 426 453 public function test_get_items_search() {