- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-request-validation.php
r39931 r42343 13 13 14 14 public function test_validate_within_min_max_range_inclusive() { 15 $request = new WP_REST_Request( 'GET', '/wp/v2/foo', array( 16 'args' => array( 17 'minmaxrange' => array( 18 'type' => 'integer', 19 'minimum' => 2, 20 'maximum' => 10, 15 $request = new WP_REST_Request( 16 'GET', '/wp/v2/foo', array( 17 'args' => array( 18 'minmaxrange' => array( 19 'type' => 'integer', 20 'minimum' => 2, 21 'maximum' => 10, 22 ), 21 23 ), 22 ) ,23 ) );24 $ret = rest_validate_request_arg( 1, $request, 'minmaxrange' );24 ) 25 ); 26 $ret = rest_validate_request_arg( 1, $request, 'minmaxrange' ); 25 27 $this->assertEquals( 'minmaxrange must be between 2 (inclusive) and 10 (inclusive)', $ret->get_error_message() ); 26 28 $ret = rest_validate_request_arg( 2, $request, 'minmaxrange' ); … … 33 35 34 36 public function test_validate_within_min_max_range_min_exclusive() { 35 $request = new WP_REST_Request( 'GET', '/wp/v2/foo', array( 36 'args' => array( 37 'minmaxrange' => array( 38 'type' => 'integer', 39 'minimum' => 2, 40 'maximum' => 10, 41 'exclusiveMinimum' => true, 37 $request = new WP_REST_Request( 38 'GET', '/wp/v2/foo', array( 39 'args' => array( 40 'minmaxrange' => array( 41 'type' => 'integer', 42 'minimum' => 2, 43 'maximum' => 10, 44 'exclusiveMinimum' => true, 45 ), 42 46 ), 43 ) ,44 ) );45 $ret = rest_validate_request_arg( 1, $request, 'minmaxrange' );47 ) 48 ); 49 $ret = rest_validate_request_arg( 1, $request, 'minmaxrange' ); 46 50 $this->assertEquals( 'minmaxrange must be between 2 (exclusive) and 10 (inclusive)', $ret->get_error_message() ); 47 51 $ret = rest_validate_request_arg( 2, $request, 'minmaxrange' ); … … 58 62 59 63 public function test_validate_within_min_max_range_max_exclusive() { 60 $request = new WP_REST_Request( 'GET', '/wp/v2/foo', array( 61 'args' => array( 62 'minmaxrange' => array( 63 'type' => 'integer', 64 'minimum' => 2, 65 'maximum' => 10, 66 'exclusiveMaximum' => true, 64 $request = new WP_REST_Request( 65 'GET', '/wp/v2/foo', array( 66 'args' => array( 67 'minmaxrange' => array( 68 'type' => 'integer', 69 'minimum' => 2, 70 'maximum' => 10, 71 'exclusiveMaximum' => true, 72 ), 67 73 ), 68 ) ,69 ) );70 $ret = rest_validate_request_arg( 1, $request, 'minmaxrange' );74 ) 75 ); 76 $ret = rest_validate_request_arg( 1, $request, 'minmaxrange' ); 71 77 $this->assertEquals( 'minmaxrange must be between 2 (inclusive) and 10 (exclusive)', $ret->get_error_message() ); 72 78 $ret = rest_validate_request_arg( 2, $request, 'minmaxrange' ); … … 83 89 84 90 public function test_validate_within_min_max_range_both_exclusive() { 85 $request = new WP_REST_Request( 'GET', '/wp/v2/foo', array( 86 'args' => array( 87 'minmaxrange' => array( 88 'type' => 'integer', 89 'minimum' => 2, 90 'maximum' => 10, 91 'exclusiveMinimum' => true, 92 'exclusiveMaximum' => true, 91 $request = new WP_REST_Request( 92 'GET', '/wp/v2/foo', array( 93 'args' => array( 94 'minmaxrange' => array( 95 'type' => 'integer', 96 'minimum' => 2, 97 'maximum' => 10, 98 'exclusiveMinimum' => true, 99 'exclusiveMaximum' => true, 100 ), 93 101 ), 94 ) ,95 ) );96 $ret = rest_validate_request_arg( 1, $request, 'minmaxrange' );102 ) 103 ); 104 $ret = rest_validate_request_arg( 1, $request, 'minmaxrange' ); 97 105 $this->assertEquals( 'minmaxrange must be between 2 (exclusive) and 10 (exclusive)', $ret->get_error_message() ); 98 106 $ret = rest_validate_request_arg( 2, $request, 'minmaxrange' ); … … 109 117 110 118 public function test_validate_greater_than_min_inclusive() { 111 $request = new WP_REST_Request( 'GET', '/wp/v2/foo', array( 112 'args' => array( 113 'greaterthanmin' => array( 114 'type' => 'integer', 115 'minimum' => 2, 119 $request = new WP_REST_Request( 120 'GET', '/wp/v2/foo', array( 121 'args' => array( 122 'greaterthanmin' => array( 123 'type' => 'integer', 124 'minimum' => 2, 125 ), 116 126 ), 117 ) ,118 ) );119 $ret = rest_validate_request_arg( 1, $request, 'greaterthanmin' );127 ) 128 ); 129 $ret = rest_validate_request_arg( 1, $request, 'greaterthanmin' ); 120 130 $this->assertEquals( 'greaterthanmin must be greater than or equal to 2', $ret->get_error_message() ); 121 131 $ret = rest_validate_request_arg( 2, $request, 'greaterthanmin' ); … … 124 134 125 135 public function test_validate_greater_than_min_exclusive() { 126 $request = new WP_REST_Request( 'GET', '/wp/v2/foo', array( 127 'args' => array( 128 'greaterthanmin' => array( 129 'type' => 'integer', 130 'minimum' => 2, 131 'exclusiveMinimum' => true, 136 $request = new WP_REST_Request( 137 'GET', '/wp/v2/foo', array( 138 'args' => array( 139 'greaterthanmin' => array( 140 'type' => 'integer', 141 'minimum' => 2, 142 'exclusiveMinimum' => true, 143 ), 132 144 ), 133 ) ,134 ) );135 $ret = rest_validate_request_arg( 1, $request, 'greaterthanmin' );145 ) 146 ); 147 $ret = rest_validate_request_arg( 1, $request, 'greaterthanmin' ); 136 148 $this->assertEquals( 'greaterthanmin must be greater than 2', $ret->get_error_message() ); 137 149 $ret = rest_validate_request_arg( 2, $request, 'greaterthanmin' ); … … 142 154 143 155 public function test_validate_less_than_max_inclusive() { 144 $request = new WP_REST_Request( 'GET', '/wp/v2/foo', array( 145 'args' => array( 146 'lessthanmax' => array( 147 'type' => 'integer', 148 'maximum' => 10, 156 $request = new WP_REST_Request( 157 'GET', '/wp/v2/foo', array( 158 'args' => array( 159 'lessthanmax' => array( 160 'type' => 'integer', 161 'maximum' => 10, 162 ), 149 163 ), 150 ) ,151 ) );152 $ret = rest_validate_request_arg( 11, $request, 'lessthanmax' );164 ) 165 ); 166 $ret = rest_validate_request_arg( 11, $request, 'lessthanmax' ); 153 167 $this->assertEquals( 'lessthanmax must be less than or equal to 10', $ret->get_error_message() ); 154 168 $ret = rest_validate_request_arg( 10, $request, 'lessthanmax' ); … … 157 171 158 172 public function test_validate_less_than_max_exclusive() { 159 $request = new WP_REST_Request( 'GET', '/wp/v2/foo', array( 160 'args' => array( 161 'lessthanmax' => array( 162 'type' => 'integer', 163 'maximum' => 10, 164 'exclusiveMaximum' => true, 173 $request = new WP_REST_Request( 174 'GET', '/wp/v2/foo', array( 175 'args' => array( 176 'lessthanmax' => array( 177 'type' => 'integer', 178 'maximum' => 10, 179 'exclusiveMaximum' => true, 180 ), 165 181 ), 166 ) ,167 ) );168 $ret = rest_validate_request_arg( 11, $request, 'lessthanmax' );182 ) 183 ); 184 $ret = rest_validate_request_arg( 11, $request, 'lessthanmax' ); 169 185 $this->assertEquals( 'lessthanmax must be less than 10', $ret->get_error_message() ); 170 186 $ret = rest_validate_request_arg( 10, $request, 'lessthanmax' );
Note: See TracChangeset
for help on using the changeset viewer.