mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-10 07:34:34 +00:00
REST API: Fix changing parameters with set_param() for some requests.
Prior to this commit, `WP_Rest_Request::get_param()` traversed through the parameter order but `WP_Rest_Request::set_param()` did not. For JSON requests (and likely other situations as well), this meant that changing a parameter with `set_param()` would have no effect on `get_param()`. Props TimothyBlynJacobs. Fixes #40344. git-svn-id: https://develop.svn.wordpress.org/trunk@40815 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -580,4 +580,31 @@ class Tests_REST_Request extends WP_UnitTestCase {
|
||||
$request = WP_REST_Request::from_url( $using_home );
|
||||
$this->assertFalse( $request );
|
||||
}
|
||||
|
||||
public function test_set_param() {
|
||||
$request = new WP_REST_Request();
|
||||
$request->set_param( 'param', 'value' );
|
||||
$this->assertEquals( 'value', $request->get_param( 'param' ) );
|
||||
}
|
||||
|
||||
public function test_set_param_follows_parameter_order() {
|
||||
$request = new WP_REST_Request();
|
||||
$request->add_header( 'content-type', 'application/json' );
|
||||
$request->set_method( 'POST' );
|
||||
$request->set_body( wp_json_encode( array(
|
||||
'param' => 'value'
|
||||
) ) );
|
||||
$this->assertEquals( 'value', $request->get_param( 'param' ) );
|
||||
$this->assertEquals(
|
||||
array( 'param' => 'value' ),
|
||||
$request->get_json_params()
|
||||
);
|
||||
|
||||
$request->set_param( 'param', 'new_value' );
|
||||
$this->assertEquals( 'new_value', $request->get_param( 'param' ) );
|
||||
$this->assertEquals(
|
||||
array( 'param' => 'new_value' ),
|
||||
$request->get_json_params()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user