Make WordPress Core


Ignore:
Timestamp:
02/16/2016 05:50:21 AM (9 years ago)
Author:
rmccue
Message:

REST API: Allow explicit HEAD callbacks.

HEAD callbacks can now be registered independently, with the GET
callback still used as a fallback.

Fixes #34841.

File:
1 edited

Legend:

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

    r36533 r36535  
    140140
    141141    /**
     142     * Plugins should be able to register explicit HEAD callbacks before the
     143     * GET callback.
     144     *
     145     * @depends test_head_request_handled_by_get
     146     */
     147    public function test_explicit_head_callback() {
     148        register_rest_route( 'head-request', '/test', array(
     149            array(
     150                'methods' => array( 'HEAD' ),
     151                'callback' => '__return_true',
     152            ),
     153            array(
     154                'methods' => array( 'GET' ),
     155                'callback' => '__return_false',
     156                'permission_callback' => array( $this, 'permission_denied' ),
     157            ),
     158        ));
     159        $request = new WP_REST_Request( 'HEAD', '/head-request/test' );
     160        $response = $this->server->dispatch( $request );
     161        $this->assertEquals( 200, $response->get_status() );
     162    }
     163
     164    /**
    142165     * Pass a capability which the user does not have, this should
    143166     * result in a 403 error.
Note: See TracChangeset for help on using the changeset viewer.