- Timestamp:
- 10/04/2017 08:26:44 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-schema-validation.php
r39896 r41727 182 182 } 183 183 184 public function test_type_object() { 185 $schema = array( 186 'type' => 'object', 187 'properties' => array( 188 'a' => array( 189 'type' => 'number' 190 ), 191 ), 192 ); 193 $this->assertTrue( rest_validate_value_from_schema( array( 'a' => 1 ), $schema ) ); 194 $this->assertWPError( rest_validate_value_from_schema( array( 'a' => 'invalid' ), $schema ) ); 195 } 196 197 public function test_type_object_nested() { 198 $schema = array( 199 'type' => 'object', 200 'properties' => array( 201 'a' => array( 202 'type' => 'object', 203 'properties' => array( 204 'b' => array( 'type' => 'number' ), 205 'c' => array( 'type' => 'number' ), 206 ) 207 ) 208 ), 209 ); 210 $this->assertTrue( 211 rest_validate_value_from_schema( 212 array( 213 'a' => array( 214 'b' => '1', 215 'c' => 3, 216 ), 217 ), 218 $schema 219 ) 220 ); 221 $this->assertWPError( rest_validate_value_from_schema( array( 'a' => array( 'b' => 1, 'c' => 'invalid' ) ), $schema ) ); 222 $this->assertWPError( rest_validate_value_from_schema( array( 'a' => 1 ), $schema ) ); 223 } 224 225 public function test_type_object_stdclass() { 226 $schema = array( 227 'type' => 'object', 228 'properties' => array( 229 'a' => array( 230 'type' => 'number' 231 ), 232 ), 233 ); 234 $this->assertTrue( rest_validate_value_from_schema( (object) array( 'a' => 1 ), $schema ) ); 235 } 236 184 237 public function test_type_unknown() { 185 238 $schema = array(
Note: See TracChangeset
for help on using the changeset viewer.