WordPress.org

Make WordPress Core

Changeset 39896


Ignore:
Timestamp:
01/13/17 04:37:03 (2 months ago)
Author:
SergeyBiryukov
Message:

REST API: Improve error messages for number relational validation.

Props jblz.
Fixes #39054.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api.php

    r39638 r39896  
    10691069            if ( ! empty( $args['exclusiveMinimum'] ) && $value <= $args['minimum'] ) { 
    10701070                /* translators: 1: parameter, 2: minimum number */ 
    1071                 return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be greater than %2$d (exclusive)' ), $param, $args['minimum'] ) ); 
     1071                return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be greater than %2$d' ), $param, $args['minimum'] ) ); 
    10721072            } elseif ( empty( $args['exclusiveMinimum'] ) && $value < $args['minimum'] ) { 
    10731073                /* translators: 1: parameter, 2: minimum number */ 
    1074                 return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be greater than %2$d (inclusive)' ), $param, $args['minimum'] ) ); 
     1074                return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be greater than or equal to %2$d' ), $param, $args['minimum'] ) ); 
    10751075            } 
    10761076        } elseif ( isset( $args['maximum'] ) && ! isset( $args['minimum'] ) ) { 
    10771077            if ( ! empty( $args['exclusiveMaximum'] ) && $value >= $args['maximum'] ) { 
    10781078                /* translators: 1: parameter, 2: maximum number */ 
    1079                 return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be less than %2$d (exclusive)' ), $param, $args['maximum'] ) ); 
     1079                return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be less than %2$d' ), $param, $args['maximum'] ) ); 
    10801080            } elseif ( empty( $args['exclusiveMaximum'] ) && $value > $args['maximum'] ) { 
    10811081                /* translators: 1: parameter, 2: maximum number */ 
    1082                 return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be less than %2$d (inclusive)' ), $param, $args['maximum'] ) ); 
     1082                return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s must be less than or equal to %2$d' ), $param, $args['maximum'] ) ); 
    10831083            } 
    10841084        } elseif ( isset( $args['maximum'] ) && isset( $args['minimum'] ) ) { 
  • trunk/tests/phpunit/tests/rest-api/rest-categories-controller.php

    r39126 r39896  
    187187        $data = $response->get_data(); 
    188188        $first_error = array_shift( $data['data']['params'] ); 
    189         $this->assertContains( 'page must be greater than 1 (inclusive)', $first_error ); 
     189        $this->assertContains( 'page must be greater than or equal to 1', $first_error ); 
    190190    } 
    191191 
  • trunk/tests/phpunit/tests/rest-api/rest-schema-validation.php

    r39296 r39896  
    2020        $this->assertTrue( rest_validate_value_from_schema( 1, $schema ) ); 
    2121        $this->assertTrue( rest_validate_value_from_schema( 2, $schema ) ); 
     22        $this->assertWPError( rest_validate_value_from_schema( 0.9, $schema ) ); 
    2223        $this->assertWPError( rest_validate_value_from_schema( 3, $schema ) ); 
    2324        $this->assertWPError( rest_validate_value_from_schema( true, $schema ) ); 
     
    3233        $this->assertTrue( rest_validate_value_from_schema( 1, $schema ) ); 
    3334        $this->assertTrue( rest_validate_value_from_schema( 2, $schema ) ); 
     35        $this->assertWPError( rest_validate_value_from_schema( 0, $schema ) ); 
    3436        $this->assertWPError( rest_validate_value_from_schema( 3, $schema ) ); 
    3537        $this->assertWPError( rest_validate_value_from_schema( 1.1, $schema ) ); 
Note: See TracChangeset for help on using the changeset viewer.