From 95fd958f1986c47e7475901e3457d4c9f1e1a63c Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Sat, 30 Jun 2018 20:52:08 -0700 Subject: [PATCH] Let template_availability return supported when no templates match but all supported * Fix remaining unit tests * Mock external HTTP requests [ci skip] --- includes/class-amp-theme-support.php | 17 +++++++++++++---- tests/test-class-amp-hulu-embed-handler.php | 15 +++++++++++++++ tests/test-class-amp-imgur-embed-handler.php | 15 +++++++++++++++ tests/test-class-amp-meta-box.php | 1 + tests/test-class-amp-options-manager.php | 9 ++++++++- tests/test-class-amp-options-menu.php | 2 +- tests/test-class-amp-post-type-support.php | 4 +++- tests/test-class-amp-theme-support.php | 12 +++++++++--- tests/test-class-amp-widget-archives.php | 1 + tests/test-class-amp-widget-categories.php | 1 + 10 files changed, 67 insertions(+), 10 deletions(-) diff --git a/includes/class-amp-theme-support.php b/includes/class-amp-theme-support.php index 207da9c5572..da72c07a10c 100644 --- a/includes/class-amp-theme-support.php +++ b/includes/class-amp-theme-support.php @@ -478,10 +478,19 @@ public static function get_template_availability( $query = null ) { // If there aren't any matching templates left that are supported, then we consider it to not be available. if ( ! $matching_template ) { - return array_merge( - $default_response, - array( 'errors' => array( 'no_matching_template' ) ) - ); + if ( AMP_Options_Manager::get_option( 'all_templates_supported' ) ) { + return array_merge( + $default_response, + array( + 'supported' => true, + ) + ); + } else { + return array_merge( + $default_response, + array( 'errors' => array( 'no_matching_template' ) ) + ); + } } $matching_template = array_merge( $default_response, $matching_template ); diff --git a/tests/test-class-amp-hulu-embed-handler.php b/tests/test-class-amp-hulu-embed-handler.php index e002fa3443b..dbf178ab0ee 100644 --- a/tests/test-class-amp-hulu-embed-handler.php +++ b/tests/test-class-amp-hulu-embed-handler.php @@ -19,6 +19,21 @@ public function setUp() { global $post; parent::setUp(); + // Mock the HTTP request. + add_filter( 'pre_http_request', function( $pre, $r, $url ) { + unset( $r ); + if ( false === strpos( $url, '771496' ) ) { + return $pre; + } + return array( + 'body' => '{"title":"Out of the Box / Run Down Race Car (Doc McStuffins)","author_name":"Disney Junior","type":"video","provider_name":"Hulu","air_date":"Fri Mar 23 00:00:00 UTC 2012","embed_url":"//www.hulu.com/embed.html?eid=_hHzwnAcj3RrXMJFDDvkuw","thumbnail_url":"http://ib.huluim.com/video/60528019?size=240x180&caller=h1o&img=i","width":500,"thumbnail_width":500,"provider_url":"//www.hulu.com/","thumbnail_height":375,"cache_age":3600,"version":"1.0","large_thumbnail_url":"http://ib.huluim.com/video/60528019?size=512x288&caller=h1o&img=i","height":289,"large_thumbnail_width":512,"html":"","duration":1446.25,"large_thumbnail_height":288}', + '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: diff --git a/tests/test-class-amp-imgur-embed-handler.php b/tests/test-class-amp-imgur-embed-handler.php index 38f749e5d8a..8def972a598 100644 --- a/tests/test-class-amp-imgur-embed-handler.php +++ b/tests/test-class-amp-imgur-embed-handler.php @@ -19,6 +19,21 @@ public function setUp() { global $post; parent::setUp(); + // Mock the HTTP request. + add_filter( 'pre_http_request', function( $pre, $r, $url ) { + unset( $r ); + if ( false === strpos( $url, 'f462IUj' ) ) { + return $pre; + } + return array( + 'body' => '{"version":"1.0","type":"rich","provider_name":"Imgur","provider_url":"https:\\/\\/imgur.com","width":500,"height":750,"html":"
Getting that beach body ready<\\/a><\\/blockquote>