- Timestamp:
- 11/30/2017 11:09:33 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-schema-validation.php
r42000 r42343 27 27 public function test_type_integer() { 28 28 $schema = array( 29 'type' => 'integer',29 'type' => 'integer', 30 30 'minimum' => 1, 31 31 'maximum' => 2, … … 65 65 public function test_format_email() { 66 66 $schema = array( 67 'type' => 'string',67 'type' => 'string', 68 68 'format' => 'email', 69 69 ); … … 75 75 public function test_format_date_time() { 76 76 $schema = array( 77 'type' => 'string',77 'type' => 'string', 78 78 'format' => 'date-time', 79 79 ); … … 88 88 public function test_format_ip() { 89 89 $schema = array( 90 'type' => 'string',90 'type' => 'string', 91 91 'format' => 'ip', 92 92 ); … … 114 114 public function test_type_array() { 115 115 $schema = array( 116 'type' => 'array',116 'type' => 'array', 117 117 'items' => array( 118 118 'type' => 'number', … … 125 125 public function test_type_array_nested() { 126 126 $schema = array( 127 'type' => 'array',128 'items' => array( 129 'type' => 'array',127 'type' => 'array', 128 'items' => array( 129 'type' => 'array', 130 130 'items' => array( 131 131 'type' => 'number', … … 138 138 public function test_type_array_as_csv() { 139 139 $schema = array( 140 'type' => 'array',140 'type' => 'array', 141 141 'items' => array( 142 142 'type' => 'number', … … 179 179 ), 180 180 ); 181 $this->assertWPError( rest_validate_value_from_schema( array( 'first' => '1', 'second' => '2' ), $schema ) ); 181 $this->assertWPError( 182 rest_validate_value_from_schema( 183 array( 184 'first' => '1', 185 'second' => '2', 186 ), $schema 187 ) 188 ); 182 189 } 183 190 … … 192 199 ); 193 200 $this->assertTrue( rest_validate_value_from_schema( array( 'a' => 1 ), $schema ) ); 194 $this->assertTrue( rest_validate_value_from_schema( array( 'a' => 1, 'b' => 2 ), $schema ) ); 201 $this->assertTrue( 202 rest_validate_value_from_schema( 203 array( 204 'a' => 1, 205 'b' => 2, 206 ), $schema 207 ) 208 ); 195 209 $this->assertWPError( rest_validate_value_from_schema( array( 'a' => 'invalid' ), $schema ) ); 196 210 } 197 211 198 212 public function test_type_object_additional_properties_false() { 213 $schema = array( 214 'type' => 'object', 215 'properties' => array( 216 'a' => array( 217 'type' => 'number', 218 ), 219 ), 220 'additionalProperties' => false, 221 ); 222 $this->assertTrue( rest_validate_value_from_schema( array( 'a' => 1 ), $schema ) ); 223 $this->assertWPError( 224 rest_validate_value_from_schema( 225 array( 226 'a' => 1, 227 'b' => 2, 228 ), $schema 229 ) 230 ); 231 } 232 233 public function test_type_object_nested() { 199 234 $schema = array( 200 235 'type' => 'object', 201 236 'properties' => array( 202 237 'a' => array( 203 'type' => 'number', 204 ), 205 ), 206 'additionalProperties' => false, 207 ); 208 $this->assertTrue( rest_validate_value_from_schema( array( 'a' => 1 ), $schema ) ); 209 $this->assertWPError( rest_validate_value_from_schema( array( 'a' => 1, 'b' => 2 ), $schema ) ); 210 } 211 212 public function test_type_object_nested() { 213 $schema = array( 214 'type' => 'object', 215 'properties' => array( 216 'a' => array( 217 'type' => 'object', 238 'type' => 'object', 218 239 'properties' => array( 219 240 'b' => array( 'type' => 'number' ), 220 241 'c' => array( 'type' => 'number' ), 221 ) 222 ) 242 ), 243 ), 223 244 ), 224 245 ); … … 234 255 ) 235 256 ); 236 $this->assertWPError( rest_validate_value_from_schema( array( 'a' => array( 'b' => 1, 'c' => 'invalid' ) ), $schema ) ); 257 $this->assertWPError( 258 rest_validate_value_from_schema( 259 array( 260 'a' => array( 261 'b' => 1, 262 'c' => 'invalid', 263 ), 264 ), $schema 265 ) 266 ); 237 267 $this->assertWPError( rest_validate_value_from_schema( array( 'a' => 1 ), $schema ) ); 238 268 } … … 243 273 'properties' => array( 244 274 'a' => array( 245 'type' => 'number' 275 'type' => 'number', 246 276 ), 247 277 ), … … 252 282 public function test_type_unknown() { 253 283 $schema = array( 254 'type' 284 'type' => 'lalala', 255 285 ); 256 286 $this->assertTrue( rest_validate_value_from_schema( 'Best lyrics', $schema ) );
Note: See TracChangeset
for help on using the changeset viewer.