- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-schema-sanitization.php
r42000 r42343 14 14 public function test_type_number() { 15 15 $schema = array( 16 'type' 16 'type' => 'number', 17 17 ); 18 18 $this->assertEquals( 1, rest_sanitize_value_from_schema( 1, $schema ) ); … … 58 58 public function test_format_email() { 59 59 $schema = array( 60 'type' => 'string',60 'type' => 'string', 61 61 'format' => 'email', 62 62 ); … … 68 68 public function test_format_ip() { 69 69 $schema = array( 70 'type' => 'string',70 'type' => 'string', 71 71 'format' => 'ip', 72 72 ); … … 79 79 public function test_type_array() { 80 80 $schema = array( 81 'type' => 'array',81 'type' => 'array', 82 82 'items' => array( 83 83 'type' => 'number', … … 90 90 public function test_type_array_nested() { 91 91 $schema = array( 92 'type' => 'array',93 'items' => array( 94 'type' => 'array',92 'type' => 'array', 93 'items' => array( 94 'type' => 'array', 95 95 'items' => array( 96 96 'type' => 'number', … … 104 104 public function test_type_array_as_csv() { 105 105 $schema = array( 106 'type' => 'array',106 'type' => 'array', 107 107 'items' => array( 108 108 'type' => 'number', … … 139 139 public function test_type_array_is_associative() { 140 140 $schema = array( 141 'type' => 'array',141 'type' => 'array', 142 142 'items' => array( 143 143 'type' => 'string', 144 144 ), 145 145 ); 146 $this->assertEquals( array( '1', '2' ), rest_sanitize_value_from_schema( array( 'first' => '1', 'second' => '2' ), $schema ) ); 146 $this->assertEquals( 147 array( '1', '2' ), rest_sanitize_value_from_schema( 148 array( 149 'first' => '1', 150 'second' => '2', 151 ), $schema 152 ) 153 ); 147 154 } 148 155 … … 152 159 'properties' => array( 153 160 'a' => array( 154 'type' => 'number' 161 'type' => 'number', 155 162 ), 156 163 ), … … 158 165 $this->assertEquals( array( 'a' => 1 ), rest_sanitize_value_from_schema( array( 'a' => 1 ), $schema ) ); 159 166 $this->assertEquals( array( 'a' => 1 ), rest_sanitize_value_from_schema( array( 'a' => '1' ), $schema ) ); 160 $this->assertEquals( array( 'a' => 1, 'b' => 1 ), rest_sanitize_value_from_schema( array( 'a' => '1', 'b' => 1 ), $schema ) ); 167 $this->assertEquals( 168 array( 169 'a' => 1, 170 'b' => 1, 171 ), rest_sanitize_value_from_schema( 172 array( 173 'a' => '1', 174 'b' => 1, 175 ), $schema 176 ) 177 ); 161 178 } 162 179 163 180 public function test_type_object_strips_additional_properties() { 181 $schema = array( 182 'type' => 'object', 183 'properties' => array( 184 'a' => array( 185 'type' => 'number', 186 ), 187 ), 188 'additionalProperties' => false, 189 ); 190 $this->assertEquals( array( 'a' => 1 ), rest_sanitize_value_from_schema( array( 'a' => 1 ), $schema ) ); 191 $this->assertEquals( array( 'a' => 1 ), rest_sanitize_value_from_schema( array( 'a' => '1' ), $schema ) ); 192 $this->assertEquals( 193 array( 'a' => 1 ), rest_sanitize_value_from_schema( 194 array( 195 'a' => '1', 196 'b' => 1, 197 ), $schema 198 ) 199 ); 200 } 201 202 public function test_type_object_nested() { 164 203 $schema = array( 165 204 'type' => 'object', 166 205 'properties' => array( 167 206 'a' => array( 168 'type' => 'number', 169 ), 170 ), 171 'additionalProperties' => false, 172 ); 173 $this->assertEquals( array( 'a' => 1 ), rest_sanitize_value_from_schema( array( 'a' => 1 ), $schema ) ); 174 $this->assertEquals( array( 'a' => 1 ), rest_sanitize_value_from_schema( array( 'a' => '1' ), $schema ) ); 175 $this->assertEquals( array( 'a' => 1 ), rest_sanitize_value_from_schema( array( 'a' => '1', 'b' => 1 ), $schema ) ); 176 } 177 178 public function test_type_object_nested() { 179 $schema = array( 180 'type' => 'object', 181 'properties' => array( 182 'a' => array( 183 'type' => 'object', 207 'type' => 'object', 184 208 'properties' => array( 185 209 'b' => array( 'type' => 'number' ), 186 210 'c' => array( 'type' => 'number' ), 187 ) 188 ) 211 ), 212 ), 189 213 ), 190 214 ); … … 236 260 'properties' => array( 237 261 'a' => array( 238 'type' => 'number' 262 'type' => 'number', 239 263 ), 240 264 ),
Note: See TracChangeset
for help on using the changeset viewer.