WordPress.org

Make WordPress Core

Changeset 52138


Ignore:
Timestamp:
11/11/2021 04:58:27 PM (2 months ago)
Author:
hellofromTonya
Message:

Build/Test Tools: Mock remote request for unknown plugin in WP_REST_Plugins_Controller::create_item().

Instead of hitting the live API, this commit mocks the remote request when testing creating an item that's an unknown plugin.

Follow-up to [48242].

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

File:
1 edited

Legend:

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

    r51568 r52138  
    547547    public function test_create_item_unknown_plugin() {
    548548        wp_set_current_user( self::$super_admin );
    549 
    550         // This will hit the live API.
     549        add_filter(
     550            'pre_http_request',
     551            static function() {
     552                /*
     553                 * Mocks the request to:
     554                 * https://api.wordpress.org/plugins/info/1.2/?action=plugin_information&request%5Bslug%5D=alex-says-this-block-definitely-doesnt-exist&request%5Bfields%5D%5Bsections%5D=0&request%5Bfields%5D%5Blanguage_packs%5D=1&request%5Blocale%5D=en_US&request%5Bwp_version%5D=5.9
     555                 */
     556                return array(
     557                    'headers'  => array(),
     558                    'response' => array(
     559                        'code'    => 404,
     560                        'message' => 'Not Found',
     561                    ),
     562                    'body'     => '{"error":"Plugin not found."}',
     563                    'cookies'  => array(),
     564                    'filename' => null,
     565                );
     566            }
     567        );
     568
    551569        $request = new WP_REST_Request( 'POST', self::BASE );
    552570        $request->set_body_params( array( 'slug' => 'alex-says-this-block-definitely-doesnt-exist' ) );
Note: See TracChangeset for help on using the changeset viewer.