Make WordPress Core

Changeset 52137


Ignore:
Timestamp:
11/11/2021 04:52:22 PM (3 years ago)
Author:
hellofromTonya
Message:

Build/Test Tools: Mock remote request for WP_REST_Block_Directory_Controller::get_items().

Instead of hitting the live API, this commit mocks the remote request.

Follow-up to [48242].

Props hellofromTonya, noisysocks, sergeybiryukov, TimothyBlynJacobs.
Fixes #54420.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-block-directory-controller.php

    r51563 r52137  
    7070    public function test_get_items() {
    7171        wp_set_current_user( self::$admin_id );
     72        add_filter(
     73            'pre_http_request',
     74            static function() {
     75                /*
     76                 * Mocks the request to:
     77                 * https://api.wordpress.org/plugins/info/1.2/?action=query_plugins&request%5Bblock%5D=foo&request%5Bper_page%5D=10&request%5Bpage%5D=1&request%5Blocale%5D=en_US&request%5Bwp_version%5D=5.9
     78                 */
     79                return array(
     80                    'headers'  => array(),
     81                    'response' => array(
     82                        'code'    => 200,
     83                        'message' => 'OK',
     84                    ),
     85                    'body'     => '{"info":{"page":1,"pages":0,"results":0},"plugins":[]}',
     86                    'cookies'  => array(),
     87                    'filename' => null,
     88                );
     89            }
     90        );
    7291
    7392        $request = new WP_REST_Request( 'GET', '/wp/v2/block-directory/search' );
Note: See TracChangeset for help on using the changeset viewer.