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 1 commit
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .dev-lib
@@ -1,2 +1,6 @@
SYNC_README_MD=0
PATH_EXCLUDES_PATTERN=includes/lib/*

if [[ ${TRAVIS_PHP_VERSION:0:3} == "5.2" ]]; then
PATH_EXCLUDES_PATTERN="$PATH_EXCLUDES_PATTERN,bin/create-embed-test-post.php"
fi
77 changes: 77 additions & 0 deletions bin/create-embed-test-post.php
@@ -0,0 +1,77 @@
<?php
/**
* Create embed test post.
*
* @package AMP
*/

if ( ! defined( 'WP_CLI' ) ) {
echo "Must be run in WP-CLI via: wp eval-file bin/create-embed-test-post.php\n";
exit( 1 );
}

$data_entries = array(
array(
'prepare' => 'amp_test_prepare_image_attachments',
'heading' => 'Media Gallery',
'content' => function( $data ) {
return sprintf( '[gallery ids="%s"]', implode( ',', $data['ids'] ) );
},
),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs now to be fleshed out with all that can be thrown at content in a vanilla WordPress install.

);

/**
* Prepare test by ensuring attachments exist.
*
* @param array $data Entry data.
* @return array Data.
*/
function amp_test_prepare_image_attachments( $data ) {
$attachments = get_children( array(
'post_parent' => 0,
'post_status' => 'inherit',
'post_type' => 'attachment',
'post_mime_type' => 'image',
) );
$data['ids'] = wp_list_pluck( $attachments, 'ID' );

// @todo Add some attachments if count( $data['ids'] ) < 5.
return $data;
}

// Run the script.
$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',
) );
}

$content = '';
foreach ( $data_entries as $data_entry ) {
if ( isset( $data_entry['prepare'] ) ) {
$data_entry = array_merge(
$data_entry,
call_user_func( $data_entry['prepare'], $data_entry )
);
}

$content .= sprintf( "<h1>%s</h1>\n", $data_entry['heading'] );
if ( is_callable( $data_entry['content'] ) ) {
$content .= call_user_func( $data_entry['content'], $data_entry );
} else {
$content .= $data_entry['content'];
}
$content .= "\n\n";
}

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

WP_CLI::success( sprintf( 'Please take a look at: %s', get_permalink( $page_id ) ) );