Changeset 55562 for trunk/tests/phpunit/tests/rest-api/rest-request.php
- Timestamp:
- 03/19/2023 12:03:30 PM (21 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-request.php
r55457 r55562 58 58 } 59 59 60 public static function header_provider() { 60 /** 61 * @dataProvider data_header_canonicalization 62 * @param string $original Original header key. 63 * @param string $expected Expected canonicalized version. 64 */ 65 public function test_header_canonicalization( $original, $expected ) { 66 $this->assertSame( $expected, $this->request->canonicalize_header_name( $original ) ); 67 } 68 69 public static function data_header_canonicalization() { 61 70 return array( 62 71 array( 'Test', 'test' ), … … 70 79 71 80 /** 72 * @dataProvider header_provider 73 * @param string $original Original header key. 74 * @param string $expected Expected canonicalized version. 75 */ 76 public function test_header_canonicalization( $original, $expected ) { 77 $this->assertSame( $expected, $this->request->canonicalize_header_name( $original ) ); 78 } 79 80 public static function content_type_provider() { 81 return array( 82 // Check basic parsing. 83 array( 'application/x-wp-example', 'application/x-wp-example', 'application', 'x-wp-example', '' ), 84 array( 'application/x-wp-example; charset=utf-8', 'application/x-wp-example', 'application', 'x-wp-example', 'charset=utf-8' ), 85 86 // Check case insensitivity. 87 array( 'APPLICATION/x-WP-Example', 'application/x-wp-example', 'application', 'x-wp-example', '' ), 88 ); 89 } 90 91 /** 92 * @dataProvider content_type_provider 81 * @dataProvider data_content_type_parsing 93 82 * 94 83 * @param string $header Header value. … … 111 100 } 112 101 102 public static function data_content_type_parsing() { 103 return array( 104 // Check basic parsing. 105 array( 'application/x-wp-example', 'application/x-wp-example', 'application', 'x-wp-example', '' ), 106 array( 'application/x-wp-example; charset=utf-8', 'application/x-wp-example', 'application', 'x-wp-example', 'charset=utf-8' ), 107 108 // Check case insensitivity. 109 array( 'APPLICATION/x-WP-Example', 'application/x-wp-example', 'application', 'x-wp-example', '' ), 110 ); 111 } 112 113 113 protected function request_with_parameters() { 114 114 $this->request->set_url_params( … … 187 187 } 188 188 189 public static function alternate_json_content_type_provider() { 189 /** 190 * @ticket 49404 191 * @dataProvider data_alternate_json_content_type 192 * 193 * @param string $content_type The Content-Type header. 194 * @param string $source The source value. 195 * @param bool $accept_json The accept_json value. 196 */ 197 public function test_alternate_json_content_type( $content_type, $source, $accept_json ) { 198 $this->request_with_parameters(); 199 200 $this->request->set_method( 'POST' ); 201 $this->request->set_header( 'Content-Type', $content_type ); 202 $this->request->set_attributes( array( 'accept_json' => true ) ); 203 204 // Check that JSON takes precedence. 205 $this->assertSame( $source, $this->request->get_param( 'source' ) ); 206 $this->assertEquals( $accept_json, $this->request->get_param( 'has_json_params' ) ); 207 } 208 209 public static function data_alternate_json_content_type() { 190 210 return array( 191 211 array( 'application/ld+json', 'json', true ), … … 200 220 /** 201 221 * @ticket 49404 202 * @dataProvider alternate_json_content_type_provider222 * @dataProvider data_is_json_content_type 203 223 * 204 224 * @param string $content_type The Content-Type header. 205 * @param string $source The source value. 206 * @param bool $accept_json The accept_json value. 207 */ 208 public function test_alternate_json_content_type( $content_type, $source, $accept_json ) { 225 * @param bool $is_json The is_json value. 226 */ 227 public function test_is_json_content_type( $content_type, $is_json ) { 209 228 $this->request_with_parameters(); 210 229 211 $this->request->set_method( 'POST' );212 230 $this->request->set_header( 'Content-Type', $content_type ); 213 $this->request->set_attributes( array( 'accept_json' => true ) ); 214 215 // Check that JSON takes precedence. 216 $this->assertSame( $source, $this->request->get_param( 'source' ) ); 217 $this->assertEquals( $accept_json, $this->request->get_param( 'has_json_params' ) ); 218 } 219 220 public static function is_json_content_type_provider() { 231 232 // Check for JSON Content-Type. 233 $this->assertSame( $is_json, $this->request->is_json_content_type() ); 234 } 235 236 public static function data_is_json_content_type() { 221 237 return array( 222 238 array( 'application/ld+json', true ), … … 231 247 /** 232 248 * @ticket 49404 233 * @dataProvider is_json_content_type_provider234 *235 * @param string $content_type The Content-Type header.236 * @param bool $is_json The is_json value.237 */238 public function test_is_json_content_type( $content_type, $is_json ) {239 $this->request_with_parameters();240 241 $this->request->set_header( 'Content-Type', $content_type );242 243 // Check for JSON Content-Type.244 $this->assertSame( $is_json, $this->request->is_json_content_type() );245 }246 247 /**248 * @ticket 49404249 249 */ 250 250 public function test_content_type_cache() { … … 311 311 } 312 312 313 public function non_post_http_methods_with_request_body_provider() {314 return array(315 array( 'PUT' ),316 array( 'PATCH' ),317 array( 'DELETE' ),318 );319 }320 321 313 /** 322 314 * Tests that methods supporting request bodies have access to the … … 324 316 * other methods `WP_REST_Request` needs to parse the body for us. 325 317 * 326 * @dataProvider non_post_http_methods_with_request_body_provider318 * @dataProvider data_non_post_body_parameters 327 319 */ 328 320 public function test_non_post_body_parameters( $request_method ) { … … 346 338 } 347 339 340 public function data_non_post_body_parameters() { 341 return array( 342 array( 'PUT' ), 343 array( 'PATCH' ), 344 array( 'DELETE' ), 345 ); 346 } 347 348 348 public function test_parameters_for_json_put() { 349 349 $data = array(
Note: See TracChangeset
for help on using the changeset viewer.