Changeset 40815
- Timestamp:
- 05/22/2017 04:15:25 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/class-wp-rest-request.php
r40577 r40815 355 355 protected function get_parameter_order() { 356 356 $order = array(); 357 $order[] = 'JSON'; 357 358 $content_type = $this->get_content_type(); 359 if ( $content_type['value'] === 'application/json' ) { 360 $order[] = 'JSON'; 361 } 358 362 359 363 $this->parse_json_params(); … … 425 429 */ 426 430 public function set_param( $key, $value ) { 427 switch ( $this->method ) { 428 case 'POST': 429 $this->params['POST'][ $key ] = $value; 430 break; 431 432 default: 433 $this->params['GET'][ $key ] = $value; 434 break; 435 } 431 $order = $this->get_parameter_order(); 432 $this->params[ $order[0] ][ $key ] = $value; 436 433 } 437 434 -
trunk/tests/phpunit/tests/rest-api/rest-request.php
r40577 r40815 581 581 $this->assertFalse( $request ); 582 582 } 583 584 public function test_set_param() { 585 $request = new WP_REST_Request(); 586 $request->set_param( 'param', 'value' ); 587 $this->assertEquals( 'value', $request->get_param( 'param' ) ); 588 } 589 590 public function test_set_param_follows_parameter_order() { 591 $request = new WP_REST_Request(); 592 $request->add_header( 'content-type', 'application/json' ); 593 $request->set_method( 'POST' ); 594 $request->set_body( wp_json_encode( array( 595 'param' => 'value' 596 ) ) ); 597 $this->assertEquals( 'value', $request->get_param( 'param' ) ); 598 $this->assertEquals( 599 array( 'param' => 'value' ), 600 $request->get_json_params() 601 ); 602 603 $request->set_param( 'param', 'new_value' ); 604 $this->assertEquals( 'new_value', $request->get_param( 'param' ) ); 605 $this->assertEquals( 606 array( 'param' => 'new_value' ), 607 $request->get_json_params() 608 ); 609 } 583 610 }
Note: See TracChangeset
for help on using the changeset viewer.