Changeset 35890
- Timestamp:
- 12/12/2015 06:22:02 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
-
.gitignore (modified) (1 diff)
-
src/wp-includes/rest-api/class-wp-rest-request.php (modified) (2 diffs)
-
tests/phpunit/tests/rest-api/rest-request.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/.gitignore
r35254 r35890 1 1 # gitignore file for WordPress Core 2 2 .svn 3 3 # Configuration files with possibly sensitive information 4 4 wp-config.php -
trunk/src/wp-includes/rest-api/class-wp-rest-request.php
r35750 r35890 852 852 853 853 if ( is_wp_error( $valid_check ) ) { 854 $invalid_params[ ] = sprintf( '%s (%s)', $key, $valid_check->get_error_message());854 $invalid_params[ $key ] = $valid_check->get_error_message(); 855 855 } 856 856 } … … 858 858 859 859 if ( $invalid_params ) { 860 return new WP_Error( 'rest_invalid_param', sprintf( __( 'Invalid parameter(s): %s' ), implode( ', ', $invalid_params) ), array( 'status' => 400, 'params' => $invalid_params ) );860 return new WP_Error( 'rest_invalid_param', sprintf( __( 'Invalid parameter(s): %s' ), implode( ', ', array_keys( $invalid_params ) ) ), array( 'status' => 400, 'params' => $invalid_params ) ); 861 861 } 862 862 -
trunk/tests/phpunit/tests/rest-api/rest-request.php
r34928 r35890 392 392 $this->assertArrayHasKey( 'someotherinteger', $data['params'] ); 393 393 } 394 395 public function test_invalid_params_error_response_format() { 396 $this->request->set_url_params( array( 397 'someinteger' => '123', 398 'someotherparams' => '123', 399 )); 400 401 $this->request->set_attributes( array( 402 'args' => array( 403 'someinteger' => array( 404 'validate_callback' => '__return_false', 405 ), 406 'someotherparams' => array( 407 'validate_callback' => array( $this, '_return_wp_error_on_validate_callback' ), 408 ), 409 ), 410 )); 411 412 $valid = $this->request->has_valid_params(); 413 $this->assertWPError( $valid ); 414 $error_data = $valid->get_error_data(); 415 416 $this->assertEquals( array( 'someinteger', 'someotherparams' ), array_keys( $error_data['params'] ) ); 417 $this->assertEquals( 'This is not valid!', $error_data['params']['someotherparams'] ); 418 } 419 420 public function _return_wp_error_on_validate_callback() { 421 return new WP_Error( 'some-error', 'This is not valid!' ); 422 } 394 423 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)