WordPress.org

Make WordPress Core

Ticket #39933: 39933.5.diff

File 39933.5.diff, 2.3 KB (added by jnylen0, 4 years ago)

Unify previous patch files; further tests cleanup

  • src/wp-includes/rest-api/class-wp-rest-request.php

    diff --git a/src/wp-includes/rest-api/class-wp-rest-request.php b/src/wp-includes/rest-api/class-wp-rest-request.php
    index 4dd0dc2..74a81c9 100644
    a b class WP_REST_Request implements ArrayAccess { 
    364364                        $this->parse_body_params();
    365365                }
    366366
    367                 $accepts_body_data = array( 'POST', 'PUT', 'PATCH' );
     367                $accepts_body_data = array( 'POST', 'PUT', 'PATCH', 'DELETE' );
    368368                if ( in_array( $this->method, $accepts_body_data ) ) {
    369369                        $order[] = 'POST';
    370370                }
  • tests/phpunit/tests/rest-api/rest-request.php

    diff --git a/tests/phpunit/tests/rest-api/rest-request.php b/tests/phpunit/tests/rest-api/rest-request.php
    index 7953f65..caf6071 100644
    a b class Tests_REST_Request extends WP_UnitTestCase { 
    203203                $this->assertEmpty( $this->request->get_param( 'has_json_params' ) );
    204204        }
    205205
     206        public function non_post_http_methods_with_request_body_provider() {
     207                return array(
     208                        array( 'PUT' ),
     209                        array( 'PATCH' ),
     210                        array( 'DELETE' ),
     211                );
     212        }
     213
    206214        /**
    207          * PUT requests don't get $_POST automatically parsed, so ensure that
    208          * WP_REST_Request does it for us.
     215         * Tests that methods supporting request bodies have access to the
     216         * request's body.  For POST this is straightforward via `$_POST`; for
     217         * other methods `WP_REST_Request` needs to parse the body for us.
     218         *
     219         * @dataProvider non_post_http_methods_with_request_body_provider
    209220         */
    210         public function test_parameters_for_put() {
     221        public function test_non_post_body_parameters( $request_method ) {
    211222                $data = array(
    212                         'foo' => 'bar',
     223                        'foo'  => 'bar',
    213224                        'alot' => array(
    214225                                'of' => 'parameters',
    215226                        ),
    class Tests_REST_Request extends WP_UnitTestCase { 
    219230                                'stuff',
    220231                        ),
    221232                );
    222 
    223                 $this->request->set_method( 'PUT' );
     233                $this->request->set_method( $request_method );
    224234                $this->request->set_body_params( array() );
    225235                $this->request->set_body( http_build_query( $data ) );
    226 
    227236                foreach ( $data as $key => $expected_value ) {
    228                         $this->assertEquals( $expected_value, $this->request->get_param( $key ) );
     237                        $this->assertEquals(
     238                                $expected_value,
     239                                $this->request->get_param( $key ),
     240                                "Body parameters for $request_method"
     241                        );
    229242                }
    230243        }
    231244