Skip to content

Commit

Permalink
Mock the gfycat requests during unit tests
Browse files Browse the repository at this point in the history
[ci skip]
  • Loading branch information
westonruter committed Jun 30, 2018
1 parent 1adad3e commit fafb94e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions tests/test-class-amp-gfycat-embed-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ public function setUp() {
global $post;
parent::setUp();

// Mock the HTTP request.
add_filter( 'pre_http_request', function( $pre, $r, $url ) {
if ( false === strpos( $url, 'tautwhoppingcougar' ) ) {
return $pre;
}
return array(
'body' => '{"version":"1.0","type":"video","provider_name":"https://gfycat.com","width":500,"height":281,"title":"Melanie Raccoon riding bike-side angle (reddit)","html":"<iframe src=\'https://gfycat.com/ifr/tautwhoppingcougar\' frameborder=\'0\' scrolling=\'no\' width=\'500\' height=\'281.25\' allowfullscreen></iframe>"}',
'response' => array(
'code' => 200,
'message' => 'OK',
),
);
}, 10, 3 );

/*
* As #34115 in 4.9 a post is not needed for context to run oEmbeds. Prior ot 4.9, the WP_Embed::shortcode()
* method would short-circuit when this is the case:
Expand Down
2 changes: 1 addition & 1 deletion tests/test-class-amp-meta-box.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function test_render_status() {
ob_start();
$this->instance->render_status( $post );
$output = ob_get_clean();
$this->assertContains( 'no supported templates to display this in AMP.', strip_tags( $output ) );
$this->assertContains( 'no supported templates to display this in AMP.', wp_strip_all_tags( $output ) );
$this->assertNotContains( $checkbox_enabled, $output );

// User doesn't have the capability to display the metabox.
Expand Down

0 comments on commit fafb94e

Please sign in to comment.