- Timestamp:
- 11/12/2021 01:45:05 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-block-directory-controller.php
r52137 r52146 70 70 public function test_get_items() { 71 71 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 } 72 $this->mock_remote_request( 73 array( 74 'body' => '{"info":{"page":1,"pages":0,"results":0},"plugins":[]}', 75 ) 90 76 ); 91 77 … … 129 115 public function test_get_items_no_results() { 130 116 wp_set_current_user( self::$admin_id ); 117 $this->mock_remote_request( 118 array( 119 'body' => '{"info":{"page":1,"pages":0,"results":0},"plugins":[]}', 120 ) 121 ); 131 122 132 123 $request = new WP_REST_Request( 'GET', '/wp/v2/block-directory/search' ); … … 307 298 ); 308 299 } 300 301 /** 302 * Mocks the remote request via `'pre_http_request'` filter by 303 * returning the expected response. 304 * 305 * @since 5.9.0 306 * 307 * @param array $expected Expected response, which is merged with the default response. 308 */ 309 private function mock_remote_request( array $expected ) { 310 add_filter( 311 'pre_http_request', 312 static function() use ( $expected ) { 313 $default = array( 314 'headers' => array(), 315 'response' => array( 316 'code' => 200, 317 'message' => 'OK', 318 ), 319 'body' => '', 320 'cookies' => array(), 321 'filename' => null, 322 ); 323 return array_merge( $default, $expected ); 324 } 325 ); 326 } 309 327 }
Note: See TracChangeset
for help on using the changeset viewer.