Make WordPress Core

Ticket #39933: 0003-use-a-data-provider-to-make-rest-unit-test-code-a-bi.patch

File 0003-use-a-data-provider-to-make-rest-unit-test-code-a-bi.patch, 2.0 KB (added by mnelson4, 8 years ago)

Use a data provider for rest request unit test

  • tests/phpunit/tests/rest-api/rest-request.php

    From e3232dda5c1d1831c8d635e24de3ddf429805093 Mon Sep 17 00:00:00 2001
    From: Mike Nelson <michael@eventespresso.com>
    Date: Wed, 22 Feb 2017 20:56:34 -0800
    Subject: [PATCH 3/3] use a data provider to make rest unit test code a bit
     more precise
    
    ---
     tests/phpunit/tests/rest-api/rest-request.php | 34 +++++++--------------------
     1 file changed, 9 insertions(+), 25 deletions(-)
    
    diff --git a/tests/phpunit/tests/rest-api/rest-request.php b/tests/phpunit/tests/rest-api/rest-request.php
    index f4364e3..41441eb 100644
    a b class Tests_REST_Request extends WP_UnitTestCase { 
    203203                $this->assertEmpty( $this->request->get_param( 'has_json_params' ) );
    204204        }
    205205
    206         /**
    207          * PUT requests don't get $_POST automatically parsed, so ensure that
    208          * WP_REST_Request does it for us.
    209          */
    210         public function test_parameters_for_put() {
    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' );
     206        public function other_methods_with_request_body(){
     207                return array(
     208                        array( 'PUT' ),
     209                        array( 'PATCH' ),
     210                        array( 'DELETE' )
     211                );
    228212        }
    229213
    230214        /**
    231          * Test logic shared between various test methods
    232          *
     215         * Tests that PUT, PATCH, DELETE have access to the request's body
     216         * @dataProvider other_methods_with_request_body
    233217         * @param string $request_method
    234218         */
    235         protected function _test_parameters_request_method( $request_method = 'POST' ) {
     219        public function test_body_parameters( $request_method = 'PUT' ) {
    236220                $data = array(
    237221                        'foo'  => 'bar',
    238222                        'alot' => array(