Skip to content

Commit

Permalink
Don't need to mock http response
Browse files Browse the repository at this point in the history
  • Loading branch information
arthur791004 committed Aug 28, 2024
1 parent 0bc5247 commit 3f07377
Showing 1 changed file with 0 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,74 +16,6 @@
class WP_Test_Jetpack_Shortcodes_Vimeo extends WP_UnitTestCase {
use Automattic\Jetpack\Tests\HttpRequestCacheTrait;

/**
* Runs on every test.
*/
public function set_up() {
parent::set_up();

if ( in_array( 'external-http', $this->getGroups(), true ) ) {
// Used by WordPress.com - does nothing in Jetpack.
add_filter( 'tests_allow_http_request', '__return_true' );
} else {
/**
* We normally make an HTTP request to Instagram's oEmbed endpoint.
* This filter bypasses that HTTP request for these tests.
*/
add_filter( 'pre_http_request', array( $this, 'pre_http_request' ), 10, 3 );
}
}

public function pre_http_request( $response, $args, $url ) {
if ( ! str_starts_with( $url, 'https://vimeo.com/api/oembed.json?' ) ) {
return $response;
}

$oembed_query = wp_parse_url( $url, PHP_URL_QUERY );
$oembed_query_args = array();
wp_parse_str( $oembed_query, $oembed_query_args );
if ( ! isset( $oembed_query_args['url'] ) ) {
return new WP_Error( 'unexpected-http-request', 'Test is making an unexpected HTTP request.' );
}

$video_id = preg_match( '/video\/(\d+)/', $oembed_query_args['url'], $matches )
? (int) $matches[1]
: 0;

$body = <<<BODY
{
"type": "video",
"version": "1.0",
"provider_name": "Vimeo",
"provider_url": "https://vimeo.com/",
"title": "Eskmo 'We Got More' (Official Video)",
"author_name": "Ninja Tune",
"author_url": "https://vimeo.com/ninjatune",
"is_plus": "1",
"account_type": "plus",
"html": "<iframe src=\"{$oembed_query_args['url']}\" width=\"500\" height=\"281\" frameborder=\"0\" allow=\"autoplay; fullscreen; picture-in-picture; clipboard-write\" title=\"Eskmo 'We Got More' (Official Video)\"></iframe>",
"width": 500,
"height": 281,
"duration": 158,
"description": "Official video for 'We Got More', taken from the album 'Eskmo' on Ninja Tune.\n\nVideo directed by Cyriak Harris: http://www.cyriak.co.uk\nAdditional footage of Eskmo by http://trevortraynor.com &\nhttp://duganoneal.com\n\nDownload the video at http://www.eskmo.com/music/we-got-mor...\n\n'Eskmo' is available on 2LP/CD/Download from the Ninjashop: - http://ninjatune.net/release/eskmo/eskmo\n\nhttp://www.eskmo.com\nhttp://www.ninjatune.net",
"thumbnail_url": "https://i.vimeocdn.com/video/115901097-56d85d68b8073d91f0fb9c589e46eb281102c78b49e157dc889e9bac4c47bdcd-d_295x166",
"thumbnail_width": 295,
"thumbnail_height": 166,
"thumbnail_url_with_play_button": "https://i.vimeocdn.com/filter/overlay?src0=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F115901097-56d85d68b8073d91f0fb9c589e46eb281102c78b49e157dc889e9bac4c47bdcd-d_295x166&src1=http%3A%2F%2Ff.vimeocdn.com%2Fp%2Fimages%2Fcrawler_play.png",
"upload_date": "2011-01-04 09:55:31",
"video_id": $video_id,
"uri": "/videos/$video_id"
}
BODY;

return array(
'response' => array(
'code' => 200,
),
'body' => $body,
);
}

/**
* Tear down each test.
*
Expand Down

0 comments on commit 3f07377

Please sign in to comment.