Make WordPress Core


Ignore:
Timestamp:
11/09/2021 01:57:48 AM (3 years ago)
Author:
TimothyBlynJacobs
Message:

REST API: Add batch support for posts and terms controllers.

This also exposes the value of allow_batch in OPTIONS requests to a route.

A future commit will add batch support to more resources.

Props spacedmonkey, chrisvanpatten.
See #53063.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-server.php

    r51960 r52068  
    369369        $sent_headers = $result->get_headers();
    370370        $this->assertSame( $sent_headers['Allow'], 'POST' );
     371    }
     372
     373    /**
     374     * @ticket 53063
     375     */
     376    public function test_batched_options() {
     377        register_rest_route(
     378            'test-ns',
     379            '/test',
     380            array(
     381                array(
     382                    'methods'             => array( 'GET' ),
     383                    'callback'            => '__return_null',
     384                    'permission_callback' => '__return_true',
     385                ),
     386                array(
     387                    'methods'             => array( 'POST' ),
     388                    'callback'            => '__return_null',
     389                    'permission_callback' => '__return_null',
     390                    'allow_batch'         => false,
     391                ),
     392                'allow_batch' => array( 'v1' => true ),
     393            )
     394        );
     395
     396        $request  = new WP_REST_Request( 'OPTIONS', '/test-ns/test' );
     397        $response = rest_get_server()->dispatch( $request );
     398
     399        $data = $response->get_data();
     400
     401        $this->assertSame( array( 'v1' => true ), $data['endpoints'][0]['allow_batch'] );
     402        $this->assertArrayNotHasKey( 'allow_batch', $data['endpoints'][1] );
    371403    }
    372404
Note: See TracChangeset for help on using the changeset viewer.