mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
REST API: Enable sanitize_callback to return WP_Error.
Give developers the opportunity to reject incoming data without using the validation callback. It also enables us to do sanitization and validation in one function in instances where this could be useful. Props websupporter, rmccue. Fixes #37560. git-svn-id: https://develop.svn.wordpress.org/trunk@38601 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -309,6 +309,27 @@ class Tests_REST_Request extends WP_UnitTestCase {
|
||||
$this->assertEquals( 0, $this->request->get_param( 'somestring' ) );
|
||||
}
|
||||
|
||||
public function test_sanitize_params_error() {
|
||||
$this->request->set_url_params( array(
|
||||
'successparam' => '123',
|
||||
'failparam' => '123',
|
||||
));
|
||||
$this->request->set_attributes( array(
|
||||
'args' => array(
|
||||
'successparam' => array(
|
||||
'sanitize_callback' => 'absint',
|
||||
),
|
||||
'failparam' => array(
|
||||
'sanitize_callback' => array( $this, '_return_wp_error_on_validate_callback' ),
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
$valid = $this->request->sanitize_params();
|
||||
$this->assertWPError( $valid );
|
||||
$this->assertEquals( 'rest_invalid_param', $valid->get_error_code() );
|
||||
}
|
||||
|
||||
public function test_has_valid_params_required_flag() {
|
||||
$this->request->set_attributes( array(
|
||||
'args' => array(
|
||||
|
||||
Reference in New Issue
Block a user