Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add create-embed-test-post script and fix support for various embeds #829

Merged
merged 25 commits into from
Dec 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a6fda64
Add skeleton for create-embed-test-post script
westonruter Dec 12, 2017
6ef9768
Fix syntax of PATH_EXCLUDES_PATTERN and add PHPCS exclude-pattern
westonruter Dec 12, 2017
550ed65
Issue 806 : Add media and embeds to test page.
Dec 13, 2017
369696b
Merge branch 'add/806-add-script-for-testing-content' of https://gith…
Dec 13, 2017
7c77752
Issue 806 : Align equals signs vertically.
Dec 13, 2017
128836c
Issue 804 : Test WordPress post embeds.
Dec 13, 2017
b8ba836
Issue 806 : code improvement
ThierryA Dec 13, 2017
0b729b1
Fix rendering of SoundCloud embeds and correct parameters for soundcl…
westonruter Dec 14, 2017
938be72
Fix phpunit tests in WP<4.9 due to oEmbeds formerly requiring post co…
westonruter Dec 14, 2017
45c538c
Fix handling of polldaddy oEmbeds in AMP
westonruter Dec 14, 2017
52b306b
Issue 806 : Add instructions for using the wp-cli test page script.
Dec 14, 2017
13132ed
Merge branch 'add/806-add-script-for-testing-content' of https://gith…
Dec 14, 2017
eaf5157
Issue 804 : Add Amazon, Animoto, and Speakerdeck URLs
Dec 14, 2017
8e34745
Issue 804 : Update the Scribd URL.
Dec 14, 2017
b22e12a
Restore required attachment count in create-embed-test-post; refactor…
westonruter Dec 14, 2017
f1ee3de
Remove DoubleArrowNotAligned PHPCS suppression
westonruter Dec 14, 2017
a91d7ad
Fix order of sanitizers to ensure whitelist applies at end, after ifr…
westonruter Dec 14, 2017
499e580
Issue 806 : Update the Photobucket and Scribd URLs.
Dec 14, 2017
6309f41
Issue 806 : Merge in feature branch, resolve conflicts.
Dec 14, 2017
d2dd032
Issue 806 : Remove Vine embed, add Screencast embed.
Dec 14, 2017
8732936
Issue 806 : Add tests for Someecards.
Dec 14, 2017
5bce94f
Fix phpcs issues in class-amp-rule-spec.php
westonruter Dec 14, 2017
e885b7a
Issue 806 : Correct embeds, including Imgur, Polldaddy, Screencast.
Dec 14, 2017
a485be1
Merge branch 'add/806-add-script-for-testing-content' of https://gith…
Dec 14, 2017
ed6088d
Issue 806 : Update Photobucket, Tumblr, remove Imgur.
Dec 14, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .dev-lib
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
SYNC_README_MD=0
PATH_EXCLUDES_PATTERN=includes/lib/*
PATH_EXCLUDES_PATTERN=includes/lib/
DEFAULT_BASE_BRANCH=develop

function after_wp_install {
echo "Installing REST API..."
svn export -q https://plugins.svn.wordpress.org/jetpack/trunk/ "$WP_CORE_DIR/src/wp-content/plugins/jetpack"
}
304 changes: 304 additions & 0 deletions bin/create-embed-test-post.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,304 @@
<?php
/**
* Create embed test post.
*
* @package AMP
*/

/**
* Get test data entries.
*
* @throws Exception When there is not enough data in DB.
* @return array Data entries.
*/
function amp_get_test_data_entries() {
return array(
array(
'heading' => 'Media Gallery',
'content' => sprintf( '[gallery ids="%s"]', amp_get_media_items_ids( 'image' ) ),
),
array(
'heading' => 'Media Image',
'content' => wp_get_attachment_image( amp_get_media_items_ids( 'image', 1 ) ),
),
array(
'heading' => 'Media Caption',
'content' => sprintf( '[caption width=150]%sExample image caption[/caption]', wp_get_attachment_image( amp_get_media_items_ids( 'image', 1 ) ) ),
),
array(
'heading' => 'Media Video',
'content' => '[video src=https://videos.files.wordpress.com/DK5mLrbr/video-ca6dc0ab4a_hd.mp4]',
),
array(
'heading' => 'Media Audio',
'content' => '[audio src=https://wptavern.com/wp-content/uploads/2017/11/EPISODE-296-Gutenberg-Telemetry-Calypso-and-More-With-Matt-Mullenweg.mp3]',
),
array(
'heading' => 'Video Playlist',
'content' => sprintf( '[playlist type="video" ids="%s"]', amp_get_media_items_ids( 'video' ) ),
),
array(
'heading' => 'Audio Playlist',
'content' => sprintf( '[playlist ids="%s"]', amp_get_media_items_ids( 'audio' ) ),
),
array(
'heading' => 'WordPress Post Embed',
'content' => 'https://make.wordpress.org/core/2017/12/11/whats-new-in-gutenberg-11th-december/',
),
array(
'heading' => 'Amazon Com Smile Embed',
'content' => 'https://smile.amazon.com/dp/B00DPM7TIG',
),
array(
'heading' => 'Amazon Co Smile Embed',
'content' => 'https://smile.amazon.co.uk/dp/B00DPM7TIG',
),
array(
'heading' => 'Amazon Read CN Embed',
'content' => 'https://read.amazon.cn/kp/embed?asin=B00DPM7TIG',
),
array(
'heading' => 'Animoto Embed',
'content' => 'https://animoto.com/play/TDfViXkPqIwYj5EjamYjnw',
),
array(
'heading' => 'CloudUp Image Embed',
'content' => 'https://cloudup.com/iWn3EIpgjev',
),
array(
'heading' => 'CloudUp Video Embed',
'content' => 'https://cloudup.com/ioyW8a_Tjme',
),
array(
'heading' => 'CloudUp Gallery Embed',
'content' => 'https://cloudup.com/cQNdYtQLO5U',
),
array(
'heading' => 'CollegeHumor Embed',
'content' => 'http://www.collegehumor.com/video/40002823/how-to-actually-finish-something-for-once',
),
array(
'heading' => 'DailyMotion Embed',
'content' => 'http://www.dailymotion.com/video/x6bacgf',
),
array(
'heading' => 'Facebook Post Embed',
'content' => 'https://www.facebook.com/WordPress/posts/10155651799877911',
),
array(
'heading' => 'Facebook Video Embed',
'content' => 'https://www.facebook.com/WordPress/videos/10154702401472911/',
),
array(
'heading' => 'Flickr Image Embed',
'content' => 'https://www.flickr.com/photos/sylvainmessier/38089894895/in/explore-2017-12-11/',
),
array(
'heading' => 'Flickr Video Embed',
'content' => 'https://flic.kr/p/5TPDWa',
),
array(
'heading' => 'Funny Or Die Video Embed',
'content' => 'http://www.funnyordie.com/videos/2977012a20/i-still-haven-t-found-the-droids-i-m-looking-for',
),
array(
'heading' => 'Hulu Embed',
'content' => 'https://www.hulu.com/watch/807443',
),
array(
'heading' => 'Instagram Embed',
'content' => 'https://www.instagram.com/p/bNd86MSFv6/',
),
array(
'heading' => 'Issuu Embed',
'content' => 'https://issuu.com/ajcwfu/docs/seatatthetablefinal',
),
array(
'heading' => 'Kickstarter Embed',
'content' => 'https://www.kickstarter.com/projects/iananderson/save-froots-magazine',
),
array(
'heading' => 'Meetup Embed',
'content' => 'https://www.meetup.com/WordPress-Mexico',
),
array(
'heading' => 'Mixcloud Embed',
'content' => 'https://www.mixcloud.com/TheWireMagazine/adventures-in-sound-and-music-hosted-by-derek-walmsley-7-december-2017/',
),
array(
'heading' => 'Photobucket Embed',
'content' => 'http://i1259.photobucket.com/albums/ii543/iamnotpeterpan/EditPostlsaquoDennisDoesCricketmdashWordPress_zpsf72cc13d.png',
),
array(
'heading' => 'Polldaddy Poll Embed',
'content' => 'https://polldaddy.com/poll/7012505/',
),
array(
'heading' => 'Polldaddy Survey Embed',
'content' => 'https://rydk.polldaddy.com/s/test-survey',
),
array(
'heading' => 'Reddit Embed',
'content' => 'https://www.reddit.com/r/Android/comments/7jbkub/google_maps_will_soon_tell_you_when_its_time_to/?ref=share&ref_source=link',
),
array(
'heading' => 'Reverb Nation Embed',
'content' => 'https://www.reverbnation.com/fernandotorresleiva/song/28755694-breve-amor-new-version',
),
array(
'heading' => 'Screencast Embed',
'content' => 'http://www.screencast.com/t/nMCYr3N3uF',
),
array(
'heading' => 'Scribd Embed',
'content' => 'http://www.scribd.com/doc/110799637/Synthesis-of-Knowledge-Effects-of-Fire-and-Thinning-Treatments-on-Understory-Vegetation-in-Dry-U-S-Forests',
),
array(
'heading' => 'SlideShare Embed',
'content' => 'https://www.slideshare.net/slideshow/embed_code/key/u6WNbsR5worSzC',
),
array(
'heading' => 'SmugMug Embed',
'content' => 'https://stuckincustoms.smugmug.com/Portfolio/i-GnwtS8R/A',
),
array(
'heading' => 'Someecards Embed',
'content' => 'https://www.someecards.com/usercards/viewcard/mjaxmi1jmgy2y2exm2m2ngu2ntfi/?tagSlug=christmas',
),
array(
'heading' => 'Someecards Short URL Embed',
'content' => 'https://some.ly/V3RZUq/',
),
array(
'heading' => 'SoundCloud Embed',
'content' => 'https://soundcloud.com/jack-villano-villano/mozart-requiem-in-d-minor',
),
array(
'heading' => 'Speaker Deck Embed',
'content' => 'https://speakerdeck.com/wallat/why-backbone',
),
array(
'heading' => 'Spotify Embed',
'content' => 'https://open.spotify.com/track/2XULDEvijLgHttFgLzzpM5',
),
array(
'heading' => 'Ted Embed',
'content' => 'https://www.ted.com/talks/derek_sivers_how_to_start_a_movement',
),
array(
'heading' => 'Tumblr Post Embed',
'content' => 'http://ifpaintingscouldtext.tumblr.com/post/92003045635/grant-wood-american-gothic-1930',
),
array(
'heading' => 'Twitter Embed',
'content' => 'https://twitter.com/WordPress/status/936550699336437760',
),
array(
'heading' => 'VideoPress Embed',
'content' => 'https://videopress.com/v/kUJmAcSf',
),
array(
'heading' => 'Vimeo Embed',
'content' => 'https://vimeo.com/59172123',
),
array(
'heading' => 'WordPress Plugin Directory Embed',
'content' => 'https://wordpress.org/plugins/amp/',
),
array(
'heading' => 'WordPress TV Embed',
'content' => 'https://videopress.com/v/DK5mLrbr',
),
array(
'heading' => 'YouTube Embed',
'content' => 'https://www.youtube.com/watch?v=XOY3ZUO6P0k',
),
);
}

/**
* Get media item ids, using a \WP_Query.
*
* @throws Exception When there are not enough posts.
* @param integer $type The post_mime_type of the media item.
* @param integer $image_count The number of images for which to query.
* @return string|WP_CLI::error The media item ids separated by comma on success; error otherwise.
*/
function amp_get_media_items_ids( $type, $image_count = 3 ) {
$query = new \WP_Query( array(
'post_type' => 'attachment',
'post_mime_type' => $type,
'post_status' => 'inherit',
'posts_per_page' => $image_count,
'fields' => 'ids',
) );
if ( $query->post_count < $image_count ) {
throw new Exception( sprintf(
'Please make sure at least %1$s "%2$s" attachments are accessible and run this script again. There are currently only %3$s.',
$image_count,
$type,
$query->found_posts
) );
}
return implode( ',', $query->get_posts() );
}

/**
* Create embed test post (page).
*
* @param array $data_entries Data.
*
* @throws Exception But when database doesn't have enough attachments or in case of error.
* @return int Page ID.
*/
function amp_create_embed_test_post( $data_entries ) {
$page = get_page_by_path( '/amp-test-embeds/' );
if ( $page ) {
$page_id = $page->ID;
} else {
$page_id = wp_insert_post( array(
'post_name' => 'amp-test-embeds',
'post_title' => 'AMP Test Embeds',
'post_type' => 'page',
) );

if ( ! $page_id || is_wp_error( $page_id ) ) {
throw new Exception( 'The test page could not be added, please try again.' );
}
}

// Build and update content.
$content = '';
foreach ( $data_entries as $entry ) {
if ( isset( $entry['heading'], $entry['content'] ) ) {
$content .= sprintf(
"<h1>%s</h1>\n%s\n\n",
$entry['heading'],
$entry['content']
);
}
}

$update = wp_update_post( wp_slash( array(
'ID' => $page_id,
'post_content' => $content,
) ) );

if ( ! $update ) {
throw new Exception( 'The test page could not be updated, please try again.' );
}
return $update;
}

// Bootstrap.
if ( defined( 'WP_CLI' ) ) {
try {
$post_id = amp_create_embed_test_post( amp_get_test_data_entries() );
WP_CLI::success( sprintf( 'Please take a look at: %s', amp_get_permalink( $post_id ) ) );
} catch ( Exception $e ) {
WP_CLI::error( $e->getMessage() );
}
} else {
echo "Must be run in WP-CLI via: wp eval-file bin/create-embed-test-post.php\n";
exit( 1 );
}
9 changes: 9 additions & 0 deletions contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ To update that file:
2. run `bash bin/amphtml-update.sh`
That script is intended for a Linux environment like [VVV](https://github.com/Varying-Vagrant-Vagrants/VVV).

### Testing Media And Embed Support

The following script creates a post in order to test support for WordPress media and embeds.
To run it:
1. `ssh` into an environment like [VVV](https://github.com/Varying-Vagrant-Vagrants/VVV)
2. `cd` to the root of this plugin
3. run `wp eval-file bin/create-embed-test-post.php`
4. go to the URL that is output in the command line

### PHPUnit Testing

Please run these tests in an environment with WordPress unit tests installed, like [VVV](https://github.com/Varying-Vagrant-Vagrants/VVV).
Expand Down
Loading