| 211 | | $this->_test_parameters_request_method('PUT'); |
| 212 | | } |
| 213 | | |
| 214 | | /** |
| 215 | | * PATCH requests don't get $_POST automatically parsed, so ensure that |
| 216 | | * WP_REST_Request does it for us. |
| 217 | | */ |
| 218 | | public function test_parameters_for_patch() { |
| 219 | | $this->_test_parameters_request_method('PATCH'); |
| 220 | | } |
| 221 | | |
| 222 | | /** |
| 223 | | * DELETE requests don't get $_POST automatically parsed, so ensure that |
| 224 | | * WP_REST_Request does it for us. |
| 225 | | */ |
| 226 | | public function test_parameters_for_delete() { |
| 227 | | $this->_test_parameters_request_method('DELETE'); |
| 228 | | } |
| 229 | | |
| 230 | | /** |
| 231 | | * Test logic shared between various test methods |
| 232 | | * @param string $request_method |
| 233 | | */ |
| 234 | | protected function _test_parameters_request_method( $request_method = 'POST' ){ |
| 235 | | $data = array( |
| 236 | | 'foo' => 'bar', |
| 237 | | 'alot' => array( |
| 238 | | 'of' => 'parameters', |
| 239 | | ), |
| 240 | | 'list' => array( |
| 241 | | 'of', |
| 242 | | 'cool', |
| 243 | | 'stuff', |
| 244 | | ), |
| 245 | | ); |
| 246 | | |
| 247 | | $this->request->set_method( $request_method ); |
| 248 | | $this->request->set_body_params( array() ); |
| 249 | | $this->request->set_body( http_build_query( $data ) ); |
| 250 | | |
| 251 | | foreach ( $data as $key => $expected_value ) { |
| 252 | | $this->assertEquals( $expected_value, $this->request->get_param( $key ), 'Using request method ' . $request_method ); |
| 253 | | } |
| 254 | | } |
| | 211 | $this->_test_parameters_request_method( 'PUT' ); |
| | 212 | } |
| | 213 | |
| | 214 | /** |
| | 215 | * PATCH requests don't get $_POST automatically parsed, so ensure that |
| | 216 | * WP_REST_Request does it for us. |
| | 217 | */ |
| | 218 | public function test_parameters_for_patch() { |
| | 219 | $this->_test_parameters_request_method( 'PATCH' ); |
| | 220 | } |
| | 221 | |
| | 222 | /** |
| | 223 | * DELETE requests don't get $_POST automatically parsed, so ensure that |
| | 224 | * WP_REST_Request does it for us. |
| | 225 | */ |
| | 226 | public function test_parameters_for_delete() { |
| | 227 | $this->_test_parameters_request_method( 'DELETE' ); |
| | 228 | } |
| | 229 | |
| | 230 | /** |
| | 231 | * Test logic shared between various test methods |
| | 232 | * |
| | 233 | * @param string $request_method |
| | 234 | */ |
| | 235 | protected function _test_parameters_request_method( $request_method = 'POST' ) { |
| | 236 | $data = array( |
| | 237 | 'foo' => 'bar', |
| | 238 | 'alot' => array( |
| | 239 | 'of' => 'parameters', |
| | 240 | ), |
| | 241 | 'list' => array( |
| | 242 | 'of', |
| | 243 | 'cool', |
| | 244 | 'stuff', |
| | 245 | ), |
| | 246 | ); |
| | 247 | $this->request->set_method( $request_method ); |
| | 248 | $this->request->set_body_params( array() ); |
| | 249 | $this->request->set_body( http_build_query( $data ) ); |
| | 250 | foreach ( $data as $key => $expected_value ) { |
| | 251 | $this->assertEquals( $expected_value, $this->request->get_param( $key ), |
| | 252 | 'Using request method ' . $request_method ); |
| | 253 | } |
| | 254 | } |