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

Conversation

westonruter
Copy link
Member

Fixes #806.

'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.

@kienstra kienstra self-assigned this Dec 12, 2017
@kienstra
Copy link
Contributor

In Development

Hi @westonruter,
Thanks a lot for starting this. I'm working on this now if that's alright.

@westonruter
Copy link
Member Author

Go for it!

@westonruter
Copy link
Member Author

As time allows, we'll also want to do something similar for Gutenberg blocks.

Ryan Kienstra added 4 commits December 12, 2017 19:49
Use Weston's wp-cli script to create a test post.
Add media items to the post content.
And add several embeds.
Several embeds are still not rendering,
Even on a standard, non-AMP page.
Before, the equals sign alignment caused a PHPCS warning.
Fix this, to enable the Travis build to succeed.
create-embed-test-post.php needs to test all post content.
As Weston mentioned, embedded posts are part of this.
@kienstra
Copy link
Contributor

kienstra commented Dec 13, 2017

Request For Review
(For Issue #806)

Hi @ThierryA or @westonruter,
Could you please review my commits here, building on @westonruter's wp-cli file create-embed-test-post.php? To run it, simply cd to plugin's root, and run wp eval-file bin/create-embed-test-post.php.

This adds most of the allowed embeds to the post content. It also tests for other media types, as listed in Issue #806.

Also, @ThierryA's comment in #806 lists whether these newly-added embeds render properly in the AMP page.

There are some embeds that don't even render in the standard WordPress page, like Scribd and Photobucket.

If you'd like, I could work on Gutenberg block support tomorrow (Wednesday).

@kienstra kienstra assigned ThierryA and unassigned kienstra Dec 13, 2017
@kienstra kienstra changed the title [WIP] Add skeleton for create-embed-test-post script Add skeleton for create-embed-test-post script Dec 13, 2017
@kienstra kienstra changed the title Add skeleton for create-embed-test-post script Issue 806 : Add skeleton for create-embed-test-post script Dec 13, 2017
Copy link
Collaborator

@ThierryA ThierryA left a comment

Choose a reason for hiding this comment

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

Thanks @kienstra and @westonruter, great work! I pushed this commit which does the following:

  • simplify code
  • remove PHP5.2 Travis exclude as it is no longer needed
  • add errors handling

Ready for your review and adjustments if need.

PS: this PR is approved from my perspective.

@@ -35,10 +209,63 @@ function amp_test_prepare_image_attachments( $data ) {
) );
$data['ids'] = wp_list_pluck( $attachments, 'ID' );

// @todo Add some attachments if count( $data['ids'] ) < 5.
$image_count_needed = 5;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I can't think of a case where this would be needed as a fallback rather than directly getting the images like we do for the other shortcodes (please advise if I am missing something). This commit simplifies this.

@ThierryA
Copy link
Collaborator

ThierryA commented Dec 13, 2017

@kienstra @westonruter I think it would be great to document this script and steps to run it somewhere, whether it is in the contributing.md file and/or open an other issue (ex. "Support vanilla embeds") for the actual work AMP support work and refer to it in this PR description. Thoughs?

…oud shortcode

* Hook into oEmbed filters for rewriting SoundCloud embeds as AMP components.
* Ensure Jetpack is active while unit tests are run.
* Explicitly install and activate Jetpack during unit tests.
* Fix error message in create-embed-test-post.php
* Fix phpcs for Soundcloud code.
@amedina amedina changed the title Issue 806 : Add skeleton for create-embed-test-post script Add skeleton for create-embed-test-post script Dec 14, 2017
* Use noscript response from oEmbed as default content.
* Include WPCOM_AMP_Polldaddy_Embed by default even when not on WordPress.com; deprecate wpcom/shortcodes.php.
* Fix DailyMotion and FunnyOrDie test URLs.
* Clean phpcs for class-amp-polldaddy-embed.php
@westonruter westonruter changed the title Add skeleton for create-embed-test-post script Add create-embed-test-post script and fix support for various embeds Dec 14, 2017
*/
public function filter_embed_oembed_html( $cache, $url, $attr ) {
$parsed_url = wp_parse_url( $url );
if ( $url && false === strpos( $parsed_url['host'], 'polldaddy.com' ) ) {
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 may need to include looking at poll.fm, but I've never seen any PollDaddy URLs look like that: https://github.com/WordPress/wordpress-develop/blob/c6326694380722ccbdd78e21a2bd0d079383291c/src/wp-includes/class-oembed.php#L69

Copy link
Collaborator

Choose a reason for hiding this comment

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

While the risk is minimal, this could throw a PHP warning if the url passed doesn't have an host.

@kienstra
Copy link
Contributor

kienstra commented Dec 14, 2017

Documenting wp-cli Script In contributing.md

Hi @ThierryA,

I think it would be great to document this script and steps to run it somewhere, whether it is in the contributing.md file and/or open an other issue...

That's a good idea. If it's alright, I'll add steps to use the wp-cli script in contributing.md.

Also, I need to add the oEmbed URLs that @westonruter requested.

'Please make sure at least %1$s "%2$s" attachments are accessible and run this script again.',
$image_count,
$type,
$posts_count
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be removed now that the message changed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, I will restore it. I also realized we should use $query->found_posts and $query->post_count here.

@@ -9,22 +9,49 @@
* Class AMP_SoundCloud_Embed_Handler
*/
class AMP_SoundCloud_Embed_Handler extends AMP_Base_Embed_Handler {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Adding the @since tag for new code and changes would be helpful.

private function render_embed_fallback( $url ) {
return AMP_HTML_Utils::build_tag( 'a',
array(
'href' => esc_url( $url ),
Copy link
Collaborator

@ThierryA ThierryA Dec 14, 2017

Choose a reason for hiding this comment

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

I am not 100% sure why we excluded this rule. It is now inconsistent throughout the project which doesn't really make sense since we require the variable operators to be aligned.

PS: this is indeed not a blocker but I think it would be better to keep the code style as consistent as possible.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I agree. I'll remove the WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotAligned suppression.

* So on WP<4.9 we set a post global to ensure oEmbeds get processed.
*/
if ( version_compare( strtok( get_bloginfo( 'version' ), '-' ), '4.9', '<' ) ) {
$post = get_post( $this->factory()->post->create() );
Copy link
Collaborator

Choose a reason for hiding this comment

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

Tips: get_post( $this->factory()->post->create() ) can be replaced with $this->factory()->post->create_and_get().

*/
public function filter_embed_oembed_html( $cache, $url ) {
$parsed_url = wp_parse_url( $url );
if ( $url && false === strpos( $parsed_url['host'], 'soundcloud.com' ) ) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

While the risk is minimal, this could throw a PHP warning if the url passed doesn't have an host.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't believe this can ever happen.

*/
public function filter_embed_oembed_html( $cache, $url, $attr ) {
$parsed_url = wp_parse_url( $url );
if ( $url && false === strpos( $parsed_url['host'], 'polldaddy.com' ) ) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

While the risk is minimal, this could throw a PHP warning if the url passed doesn't have an host.

@ThierryA
Copy link
Collaborator

ThierryA commented Dec 14, 2017

That's a good idea. If it's alright, I'll make add steps to use the wp-cli script in contributing.md.

@kienstra sounds good to me.
@westonruter I added a round of CR, nothing major.

Ryan Kienstra added 2 commits December 14, 2017 11:43
Add steps to contributing.md to use create-embed-test-post.php.
Include a step that this should be inside an environment like VVV.
@westonruter
Copy link
Member Author

I noticed that the iframe for Funny Or Die is getting stripped out, leaving behind just:

I Still Haven't Found the Droids I'm Looking For – watch more funny videos

We need to figure out why the AMP_Iframe_Sanitizer isn't applying here as expected.

Ryan Kienstra and others added 10 commits December 14, 2017 12:34
Add these URLs to test oEmbed.
Use the Amazon testing URLs in:
https://core.trac.wordpress.org/ticket/38181
Props @jsepia for these URLs.
* Add missing since tag
* Update filter_embed_oembed_html calls since $url is required
* Add DEFAULT_BASE_BRANCH=develop
* Use create_and_get in test
Thanks to ohthenoes for the Photobucket link in:
https://core.trac.wordpress.org/ticket/13754
And thanks to @wonderboymusic for the Scribd URL from:
https://core.trac.wordpress.org/ticket/28379.
The only conflict was from array alignment.
It was a whitespace-only edit.
Add a Screencast embed, thanks to designsimply's URL in:
https://core.trac.wordpress.org/ticket/24660
Because Vine isn't supported anymore, remove its test URL.
@see wordpress-develop/src/wp-includes/class-oembed.php
Both the full URL, and the short URL ending with the TLD .ly.
They both render well in AMP.
@kienstra
Copy link
Contributor

Tests For All oEmbed Providers

Hi @westonruter,
Thanks for your patience. There are now tests for all WordPress oEmbed providers in create-embed-test-post.php.

Still, some of them aren't rendering properly, even on a non-AMP page. Including Imgur, Photobucket, and Screencast. I'm working on those now.

Ryan Kienstra added 3 commits December 14, 2017 16:33
Change the URLs for most of these.
And remove the soundcloud shortcode.
This isn't supported natively.
Use mrdenn1s's image from his Trac ticket:
https://core.trac.wordpress.org/ticket/28345
It looks like Imgur oEmbeds no longer work in WordPress.
@see https://core.trac.wordpress.org/ticket/42247
@kienstra
Copy link
Contributor

Tests For Almost All oEmbeds

Hi @westonruter,
This now has tests for almost all oEmbeds. Except for Imgur, which seems to not be supported.

@westonruter westonruter added this to the v0.6 milestone Dec 14, 2017
@westonruter westonruter merged commit 78c60fa into develop Dec 14, 2017
@westonruter westonruter deleted the add/806-add-script-for-testing-content branch February 3, 2018 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants