-
Notifications
You must be signed in to change notification settings - Fork 796
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Instagram: update embed to support new TV URLs (#11329)
#### Changes proposed in this Pull Request: This updates our custom embed provider to support Instagram TV URLs, just like Core will soon: https://core.trac.wordpress.org/changeset/44486 I also took the opportunity to add some Unit Tests for Instagram, we did not have any before. #### Testing instructions: * Try adding the following URLs to a brand new post, and see that they all get transformed into embeds on publish: ``` A classic IG embed https://www.instagram.com/p/BnMOk_FFsxg/ A TV IG embed https://www.instagram.com/tv/BkQjCfsBIzi/ A profile alternative picture IG embed https://www.instagram.com/jeherve/p/BnMO9vRleEx/ A profile alternative video IG embed https://www.instagram.com/instagram/tv/BkQjCfsBIzi/ An Instagram shortcode [instagram url="http://instagram.com/p/BnMO9vRleEx/"] ``` * I would recommend testing this with the Classic Editor, because Instagram Embeds are currently broken in the block editor (see #9331) #### Proposed changelog entry for your changes: * Instagram: update embed to support Instagram TV URLs Co-authored-by: David Biňovec <david.binovec@gmail.com>
- Loading branch information
1 parent
7c49646
commit 2171105
Showing
2 changed files
with
182 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?php | ||
|
||
class WP_Test_Jetpack_Shortcodes_Instagram extends WP_UnitTestCase { | ||
/** | ||
* @covers ::jetpack_shortcode_instagram | ||
*/ | ||
public function test_shortcode_instagram() { | ||
$instagram_url = 'https://www.instagram.com/p/BnMO9vRleEx/'; | ||
$content = '[instagram url="' . $instagram_url . '"]'; | ||
|
||
$shortcode_content = do_shortcode( $content ); | ||
|
||
$this->assertContains( | ||
'<blockquote class="instagram-media" data-instgrm-captioned data-instgrm-permalink="' . $instagram_url, | ||
$shortcode_content | ||
); | ||
} | ||
|
||
/** | ||
* @covers ::jetpack_instagram_handler | ||
*/ | ||
public function test_instagram_replace_image_url_with_embed() { | ||
global $post; | ||
|
||
$instagram_url = 'https://www.instagram.com/p/BnMO9vRleEx/'; | ||
$post = $this->factory->post->create_and_get( array( 'post_content' => $instagram_url ) ); | ||
|
||
do_action( 'init' ); | ||
setup_postdata( $post ); | ||
ob_start(); | ||
the_content(); | ||
$actual = ob_get_clean(); | ||
wp_reset_postdata(); | ||
|
||
$this->assertContains( | ||
'<blockquote class="instagram-media" data-instgrm-captioned data-instgrm-permalink="' . $instagram_url, | ||
$actual | ||
); | ||
} | ||
|
||
/** | ||
* @covers ::jetpack_instagram_handler | ||
*/ | ||
public function test_instagram_replace_video_url_with_embed() { | ||
global $post; | ||
|
||
$instagram_url = 'https://www.instagram.com/tv/BkQjCfsBIzi/'; | ||
$post = $this->factory->post->create_and_get( array( 'post_content' => $instagram_url ) ); | ||
|
||
do_action( 'init' ); | ||
setup_postdata( $post ); | ||
ob_start(); | ||
the_content(); | ||
$actual = ob_get_clean(); | ||
wp_reset_postdata(); | ||
|
||
$this->assertContains( | ||
'<blockquote class="instagram-media" data-instgrm-captioned data-instgrm-permalink="' . $instagram_url, | ||
$actual | ||
); | ||
} | ||
|
||
/** | ||
* @covers ::jetpack_instagram_handler | ||
*/ | ||
public function test_instagram_replace_profile_image_url_with_embed() { | ||
global $post; | ||
|
||
$instagram_username = 'jeherve'; | ||
$instagram_id = 'BnMO9vRleEx'; | ||
$instagram_original_url = 'https://www.instagram.com/' . $instagram_username . '/p/' . $instagram_id . '/'; | ||
$instagram_canonical_url = 'https://www.instagram.com/p/' . $instagram_id . '/'; | ||
$post = $this->factory->post->create_and_get( array( 'post_content' => $instagram_original_url ) ); | ||
|
||
do_action( 'init' ); | ||
setup_postdata( $post ); | ||
ob_start(); | ||
the_content(); | ||
$actual = ob_get_clean(); | ||
wp_reset_postdata(); | ||
|
||
$this->assertContains( | ||
'<blockquote class="instagram-media" data-instgrm-captioned data-instgrm-permalink="' . $instagram_canonical_url, | ||
$actual | ||
); | ||
} | ||
|
||
/** | ||
* @covers ::jetpack_instagram_handler | ||
*/ | ||
public function test_instagram_replace_profile_video_url_with_embed() { | ||
global $post; | ||
|
||
$instagram_username = 'instagram'; | ||
$instagram_id = 'BkQjCfsBIzi'; | ||
$instagram_original_url = 'https://www.instagram.com/' . $instagram_username . '/tv/' . $instagram_id . '/'; | ||
$instagram_canonical_url = 'https://www.instagram.com/tv/' . $instagram_id . '/'; | ||
$post = $this->factory->post->create_and_get( array( 'post_content' => $instagram_original_url ) ); | ||
|
||
do_action( 'init' ); | ||
setup_postdata( $post ); | ||
ob_start(); | ||
the_content(); | ||
$actual = ob_get_clean(); | ||
wp_reset_postdata(); | ||
|
||
$this->assertContains( | ||
'<blockquote class="instagram-media" data-instgrm-captioned data-instgrm-permalink="' . $instagram_canonical_url, | ||
$actual | ||
); | ||
} | ||
} |