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

Sync some unit tests up with WPCOM versions. #6927

Merged
merged 18 commits into from Apr 21, 2017
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
58491fd
Shortcodes: update code style for `soundcloud` and add more unit test…
lancewillett Jan 9, 2016
7b53f3b
Shortcodes: fix minor problems in `soundcloud` shortcode reversal. Fi…
lancewillett Jan 9, 2016
4cfd623
Shortcodes: fix `flickr` reversal unit test.
lancewillett Jan 9, 2016
4db5541
Shortcodes: update `slideshare` to not use `extract` and ensure prope…
lancewillett Jan 5, 2016
35f81eb
Shortcodes: add unit tests for `slideshow`; see #7620.
lancewillett Jan 5, 2016
81c1ddf
Merge commit '35f81eb' into wpcom/sync-unit-tests
georgestephanis Apr 5, 2017
b2a7c53
Shortcodes: update `twitter-timeline` for better escaping and more un…
lancewillett Jan 6, 2016
acdf3c0
Merge commit 'b2a7c53' into wpcom/sync-unit-tests
georgestephanis Apr 5, 2017
e344690
Shortcodes: code style fixes for `vimeo` before making other code cha…
lancewillett Jan 7, 2016
2da9720
Shortcodes: update `vimeo` for proper attribute escaping and to remov…
lancewillett Jan 7, 2016
b248065
Merge commit '2da9720' into wpcom/sync-unit-tests
georgestephanis Apr 5, 2017
a6b0195
Add props and comments back in.
georgestephanis Apr 5, 2017
b1655f3
Don't switch to blog on Jetpack unit tests.
georgestephanis Apr 5, 2017
70b42b5
setUp must be public.
georgestephanis Apr 5, 2017
66b957a
Tweak some unit tests to match our new content.
georgestephanis Apr 20, 2017
795df85
Switch to our new constant instead of IS_WPCOM
georgestephanis Apr 20, 2017
3b1d303
Tidy up how create_object is called.
georgestephanis Apr 20, 2017
2a3207b
Tidy up and update some documentation.
georgestephanis Apr 21, 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
70 changes: 28 additions & 42 deletions tests/php/modules/shortcodes/test_class.flickr.php
Expand Up @@ -3,19 +3,12 @@
class WP_Test_Jetpack_Shortcodes_Flickr extends WP_UnitTestCase {

/**
* @author scotchfield
* @covers ::flickr_shortcode_handler
* @since 3.2
* [flickr] shortcode.
*/
public function test_shortcodes_flickr_exists() {
$this->assertEquals( shortcode_exists( 'flickr' ), true );
}

/**
* @author scotchfield
* @covers ::flickr_shortcode_handler
* @since 3.2
*/
public function test_shortcodes_flickr() {
$content = '[flickr]';

Expand All @@ -24,60 +17,40 @@ public function test_shortcodes_flickr() {
$this->assertNotEquals( $content, $shortcode_content );
}

/**
* @author scotchfield
* @covers ::flickr_shortcode_handler
* @since 3.2
*/
public function test_shortcodes_flickr_video_http() {
$user = 'chaddles';
$user = 'chaddles';
$video_id = '2402990826';
$content = '[flickr video=http://flickr.com/photos/' . $user . '/' . $video_id . '/]';
$content = '[flickr video=http://flickr.com/photos/' . $user . '/' . $video_id . '/]';

$shortcode_content = do_shortcode( $content );

$this->assertContains( $video_id, $shortcode_content );
}

/**
* @author scotchfield
* @covers ::flickr_shortcode_handler
* @since 3.2
*/
public function test_shortcodes_flickr_video_id() {
$video_id = '2402990826';
$content = '[flickr video=' . $video_id . ']';
$content = '[flickr video=' . $video_id . ']';

$shortcode_content = do_shortcode( $content );

$this->assertContains( $video_id, $shortcode_content );
}

/**
* @author scotchfield
* @covers ::flickr_shortcode_handler
* @since 3.2
*/
public function test_shortcodes_flickr_video_id_show_info() {
$video_id = '2402990826';
$content = '[flickr video=' . $video_id . ' show_info=no]';
$content = '[flickr video=' . $video_id . ' show_info=no]';

$shortcode_content = do_shortcode( $content );

$this->assertContains( $video_id, $shortcode_content );
$this->assertContains( 'flickr_show_info_box=false', $shortcode_content );
}

/**
* @author scotchfield
* @covers ::flickr_shortcode_handler
* @since 3.2
*/
public function test_shortcodes_flickr_video_id_width_height() {
$video_id = '2402990826';
$width = 200;
$height = 150;
$content = '[flickr video=' . $video_id . ' w=' . $width . ' h=' . $height . ']';
$width = 200;
$height = 150;
$content = '[flickr video=' . $video_id . ' w=' . $width . ' h=' . $height . ']';

$shortcode_content = do_shortcode( $content );

Expand All @@ -86,20 +59,33 @@ public function test_shortcodes_flickr_video_id_width_height() {
$this->assertContains( 'height="' . $height . '"', $shortcode_content );
}

/**
* @author scotchfield
* @covers ::flickr_shortcode_handler
* @since 3.2
*/
public function test_shortcodes_flickr_video_id_show_info_secret() {
$video_id = '2402990826';
$secret = '846d9c1be9';
$content = '[flickr video=' . $video_id . ' secret=' . $secret . ']';
$secret = '846d9c1be9';
$content = '[flickr video=' . $video_id . ' secret=' . $secret . ']';

$shortcode_content = do_shortcode( $content );

$this->assertContains( $video_id, $shortcode_content );
$this->assertContains( 'secret=' . $secret, $shortcode_content );
}

/**
* Shortcode reversals.
*/
public function test_shortcodes_flickr_reversal_iframe_to_link() {
$content = '<iframe src="http://www.flickr.com/photos/batmoo/5265478228/player/" height="500" width="375" frameborder="0" allowfullscreen webkitallowfullscreen mozallowfullscreen oallowfullscreen msallowfullscreen></iframe>';

$shortcode_content = wp_kses_post( $content );

$this->assertEquals( $shortcode_content, '<a href="http://www.flickr.com/photos/batmoo/5265478228/player/">http://www.flickr.com/photos/batmoo/5265478228/player/</a>' );
}

public function test_shortcodes_flickr_reversal_embed_to_shortcode() {
$content = '<object type="application/x-shockwave-flash" width="400" height="300" data="http://www.flickr.com/apps/video/stewart.swf?v=71377" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"> <param name="flashvars" value="intl_lang=en-us&photo_secret=846d9c1be9&photo_id=2345938910"></param> <param name="movie" value="http://www.flickr.com/apps/video/stewart.swf?v=71377"></param> <param name="bgcolor" value="#000000"></param> <param name="allowFullScreen" value="true"></param><embed type="application/x-shockwave-flash" src="http://www.flickr.com/apps/video/stewart.swf?v=71377" bgcolor="#000000" allowfullscreen="true" flashvars="intl_lang=en-us&photo_secret=846d9c1be9&photo_id=2345938910" height="300" width="400"></embed></object>';

$shortcode_content = wp_kses_post( $content );

$this->assertEquals( $shortcode_content, '[flickr video=2345938910 secret=846d9c1be9 w=400 h=300]' );
}
}
41 changes: 31 additions & 10 deletions tests/php/modules/shortcodes/test_class.slideshare.php
Expand Up @@ -2,20 +2,10 @@

class WP_Test_Jetpack_Shortcodes_Slideshare extends WP_UnitTestCase {

/**
* @author scotchfield
* @covers ::slideshare_shortcode
* @since 3.2
*/
public function test_shortcodes_slideshare_exists() {
$this->assertEquals( shortcode_exists( 'slideshare' ), true );
}

/**
* @author scotchfield
* @covers ::slideshare_shortcode
* @since 3.2
*/
public function test_shortcodes_slideshare() {
$content = '[slideshare]';

Expand All @@ -24,4 +14,35 @@ public function test_shortcodes_slideshare() {
$this->assertNotEquals( $content, $shortcode_content );
}

public function test_shortcodes_slideshare_id() {
$content = '[slideshare id=5342235]';

$shortcode_content = do_shortcode( $content );

$this->assertNotEquals( $content, $shortcode_content );
}

public function test_shortcodes_slideshare_id_content() {
$content = '[slideshare id=5342235]';

$shortcode_content = do_shortcode( $content );

$this->assertEquals( 0, strpos( $shortcode_content, "<iframe src='https://www.slideshare.net/slideshow/embed_code/5342235'" ) );
}

public function test_shortcodes_slideshare_fb_arg() {
$content = '[slideshare id=5342235&amp;fb=0&amp;mw=0&amp;mh=0&amp;sc=no]';

$shortcode_content = do_shortcode( $content );

$this->assertEquals( ! false, strpos( $shortcode_content, 'frameborder' ) );
}

public function test_shortcodes_slideshare_no_fb_arg() {
$content = '[slideshare id=5342235&amp;mw=0&amp;mh=0&amp;sc=no]';

$shortcode_content = do_shortcode( $content );

$this->assertEquals( false, strpos( $shortcode_content, 'frameborder' ) );
}
}
39 changes: 39 additions & 0 deletions tests/php/modules/shortcodes/test_class.slideshow.php
Expand Up @@ -24,4 +24,43 @@ public function test_shortcodes_slideshow() {
$this->assertNotEquals( $content, $shortcode_content );
}

public function test_shortcodes_slideshow_no_js() {
switch_to_blog( 104104364 ); // test.wordpress.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 can probably be abstracted into a protected function setUp() or setUpBeforeClass() and run only on wpcom environments. In Jetpack, we should probably do something like manually creating db media item entries to use, instead of relying on an existing blog id.

https://phpunit.de/manual/current/en/fixtures.html


$content = '[gallery type="slideshow" ids="161,162"]';

$shortcode_content = do_shortcode( $content );

$this->assertEquals( 0, strpos( $shortcode_content, '<p class="jetpack-slideshow-noscript robots-nocontent">This slideshow requires JavaScript.</p>' ) );
Copy link
Member Author

Choose a reason for hiding this comment

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

}

public function test_shortcodes_slideshow_html() {
switch_to_blog( 104104364 ); // test.wordpress.com

$content = '[gallery type="slideshow" ids="161,162"]';

$shortcode_content = do_shortcode( $content );

$this->assertEquals( ! false, strpos( $shortcode_content, 'class="slideshow-window jetpack-slideshow' ) );
Copy link
Member Author

Choose a reason for hiding this comment

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

}

public function test_shortcodes_slideshow_autostart_off() {
switch_to_blog( 104104364 ); // test.wordpress.com

$content = '[gallery type="slideshow" ids="161,162" autostart="false"]';

$shortcode_content = do_shortcode( $content );

$this->assertEquals( ! false, strpos( $shortcode_content, 'data-autostart="false"' ) );
Copy link
Member Author

Choose a reason for hiding this comment

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

Same assertion concern as above.

}

public function test_shortcodes_slideshow_autostart_on() {
switch_to_blog( 104104364 ); // test.wordpress.com

$content = '[gallery type="slideshow" ids="161,162" autostart="true"]';

$shortcode_content = do_shortcode( $content );

$this->assertEquals( ! false, strpos( $shortcode_content, 'data-autostart="true"' ) );
Copy link
Member Author

Choose a reason for hiding this comment

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

Same assertion concern as above.

}
}
41 changes: 33 additions & 8 deletions tests/php/modules/shortcodes/test_class.soundcloud.php
Expand Up @@ -3,19 +3,12 @@
class WP_Test_Jetpack_Shortcodes_Soundcloud extends WP_UnitTestCase {

/**
* @author scotchfield
* @covers ::soundcloud_shortcode
* @since 3.2
* Shortcode.
*/
public function test_shortcodes_soundcloud_exists() {
$this->assertEquals( shortcode_exists( 'soundcloud' ), true );
}

/**
* @author scotchfield
* @covers ::soundcloud_shortcode
* @since 3.2
*/
public function test_shortcodes_soundcloud() {
$content = '[soundcloud]';

Expand All @@ -24,4 +17,36 @@ public function test_shortcodes_soundcloud() {
$this->assertNotEquals( $content, $shortcode_content );
}

public function test_shortcodes_soundcloud_html() {
$content = '[soundcloud url="https://api.soundcloud.com/tracks/156661852" params="auto_play=false&amp;hide_related=false&amp;visual=true" width="100%" height="450" iframe="true" /]';

$shortcode_content = do_shortcode( $content );

$this->assertContains( '<iframe width="100%" height="450"', $shortcode_content );
Copy link
Member Author

Choose a reason for hiding this comment

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

Should this be assertStringStartsWith?

Copy link
Contributor

Choose a reason for hiding this comment

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

That is ok. I tested it with assertStringStartsWith and it works in the same way.

$this->assertContains( 'w.soundcloud.com/player/?url=https%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F156661852&visual=true&auto_play=false&hide_related=false', $shortcode_content );
}

/**
* Shortcode reversals.
*/
public function test_shortcodes_soundcloud_reversal_player() {
$content = '<iframe width="100%" height="450" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/playlists/4142297&amp;auto_play=false&amp;hide_related=false&amp;show_comments=true&amp;show_user=true&amp;show_reposts=false&amp;visual=true"></iframe>';

$shortcode_content = jetpack_soundcloud_embed_reversal( $content );
$shortcode_content = str_replace( "\n", '', $shortcode_content );

$this->assertEquals( $shortcode_content, '[soundcloud url="https://api.soundcloud.com/playlists/4142297" params="auto_play=false&amp;hide_related=false&amp;show_comments=true&amp;show_user=true&amp;show_reposts=false&amp;visual=true" width="100%" height="450" iframe="true" /]' );
}

public function test_shortcodes_soundcloud_reversal_embed() {
$content = '<object height="81" width="100%">
<param name="movie" value="https://player.soundcloud.com/player.swf?url=http://api.soundcloud.com/tracks/70198773" />
<param name="allowscriptaccess" value="always" />
<embed allowscriptaccess="always" height="81" src="https://player.soundcloud.com/player.swf?url=http://api.soundcloud.com/tracks/70198773" type="application/x-shockwave-flash" width="100%"></embed>
</object>';

$shortcode_content = wp_kses_post( $content );
Copy link
Member Author

Choose a reason for hiding this comment

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

Do we need to set something before/after the test runs to make sure unfiltered_html is disabled?


$this->assertEquals( $shortcode_content, '<a href="https://player.soundcloud.com/player.swf?url=http://api.soundcloud.com/tracks/70198773">https://player.soundcloud.com/player.swf?url=http://api.soundcloud.com/tracks/70198773</a>' );
}
}
63 changes: 53 additions & 10 deletions tests/php/modules/shortcodes/test_class.twitter-timeline.php
@@ -1,21 +1,23 @@
<?php

/**
* Shortcode for Twitter Timeline
*
* Example: [twitter-timeline id="297487559557251073" username="wordpressdotcom"]
*
* Expected shortcode output:
* <a class="twitter-timeline" width="450" height="282" href="https://twitter.com/wordpressdotcom/" data-widget-id="297487559557251073">Tweets by @wordpressdotcom</a>
*
* @param
*
* @return
Copy link
Contributor

Choose a reason for hiding this comment

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

This param and return shouldn't be there.

*/
class WP_Test_Jetpack_Shortcodes_TwitterTimeline extends WP_UnitTestCase {

/**
* @author scotchfield
* @covers ::twitter_timeline_shortcode
* @since 3.2
*/
public function test_shortcodes_twitter_timeline_exists() {
$this->assertEquals( shortcode_exists( 'twitter-timeline' ), true );
}

/**
* @author scotchfield
* @covers ::twitter_timeline_shortcode
* @since 3.2
*/
public function test_shortcodes_twitter_timeline() {
$content = '[twitter-timeline]';

Expand All @@ -36,4 +38,45 @@ public function test_shortcode_tweet_partner_id() {

$this->assertContains( 'data-partner="jetpack"', $shortcode_content );
}

public function test_shortcodes_twitter_timeline_missing_username() {
$content = '[twitter-timeline id="297487559557251073"]';

$shortcode_content = do_shortcode( $content );

$this->assertEquals( $shortcode_content, '<!-- Invalid Twitter Timeline username -->' );
}

public function test_shortcodes_twitter_timeline_missing_id() {
$content = '[twitter-timeline username="wordpressdotcom"]';

$shortcode_content = do_shortcode( $content );

$this->assertEquals( $shortcode_content, '<!-- Invalid Twitter Timeline id -->' );
}


public function test_shortcodes_twitter_timeline_html() {
$content = '[twitter-timeline id="297487559557251073" username="wordpressdotcom"]';

$shortcode_content = do_shortcode( $content );

$this->assertEquals( $shortcode_content, '<a class="twitter-timeline" width="450" height="282" href="https://twitter.com/wordpressdotcom/" data-widget-id="297487559557251073">Tweets by @wordpressdotcom</a>' );
}

public function test_shortcodes_twitter_timeline_username() {
$content = '[twitter-timeline id="297487559557251073" username="wordpressdotcom"]';

$shortcode_content = do_shortcode( $content );

$this->assertEquals( $shortcode_content, '<a class="twitter-timeline" width="450" height="282" href="https://twitter.com/wordpressdotcom/" data-widget-id="297487559557251073">Tweets by @wordpressdotcom</a>' );
}

public function test_shortcodes_twitter_timeline_height_width() {
$content = '[twitter-timeline id="297487559557251073" username="wordpressdotcom" height="100" width="100"]';

$shortcode_content = do_shortcode( $content );

$this->assertEquals( $shortcode_content, '<a class="twitter-timeline" width="100" height="100" href="https://twitter.com/wordpressdotcom/" data-widget-id="297487559557251073">Tweets by @wordpressdotcom</a>' );
}
}