Skip to content

Commit

Permalink
Merge pull request #6927 from Automattic/wpcom/sync-unit-tests
Browse files Browse the repository at this point in the history
Sync some unit tests up with WPCOM versions.
  • Loading branch information
George Stephanis committed Apr 21, 2017
2 parents 6ccf44e + 2a3207b commit 229a5c5
Show file tree
Hide file tree
Showing 7 changed files with 299 additions and 21 deletions.
9 changes: 9 additions & 0 deletions tests/php/bootstrap.php
Expand Up @@ -7,6 +7,15 @@
* @package wordpress-plugin-tests
*/

/**
* For tests that should be skipped in Jetpack but run in WPCOM (or vice versa), test against this constant.
*
* if ( defined( 'TESTING_IN_JETPACK' ) && TESTING_IN_JETPACK ) {
* self::markTestSkipped( 'This test only runs on WPCOM' );
* }
*/
define( 'TESTING_IN_JETPACK', true );

// Support for:
// 1. `WP_DEVELOP_DIR` environment variable
// 2. Plugin installed inside of WordPress.org developer checkout
Expand Down
39 changes: 30 additions & 9 deletions tests/php/modules/shortcodes/test_class.flickr.php
Expand Up @@ -30,9 +30,9 @@ public function test_shortcodes_flickr() {
* @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 );

Expand All @@ -46,7 +46,7 @@ public function test_shortcodes_flickr_video_http() {
*/
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 );

Expand All @@ -60,7 +60,7 @@ public function test_shortcodes_flickr_video_id() {
*/
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 );

Expand All @@ -75,9 +75,9 @@ public function test_shortcodes_flickr_video_id_show_info() {
*/
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 @@ -93,13 +93,34 @@ public function test_shortcodes_flickr_video_id_width_height() {
*/
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() {
if ( defined( 'TESTING_IN_JETPACK' ) && TESTING_IN_JETPACK ) {
self::markTestSkipped( 'This test only runs on WPCOM' );
}
$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]' );
}
}
31 changes: 31 additions & 0 deletions tests/php/modules/shortcodes/test_class.slideshare.php
Expand Up @@ -24,4 +24,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' ) );
}
}
54 changes: 54 additions & 0 deletions tests/php/modules/shortcodes/test_class.slideshow.php
Expand Up @@ -2,6 +2,29 @@

class WP_Test_Jetpack_Shortcodes_Slideshow extends WP_UnitTestCase {

public function setUp() {
if ( ! defined( 'TESTING_IN_JETPACK' ) || ! TESTING_IN_JETPACK ) {
switch_to_blog( 104104364 ); // test.wordpress.com
$this->IDs = '161,162';
return;
}

// Otherwise, create the two images we're going to be using ourselves!
$a1 = self::factory()->attachment->create_object( 'image1.jpg', 0, array(
'file' => 'image1.jpg',
'post_mime_type' => 'image/jpeg',
'post_type' => 'attachment',
) );

$a2 = self::factory()->attachment->create_object( 'image1.jpg', 0, array(
'file' => 'image2.jpg',
'post_mime_type' => 'image/jpeg',
'post_type' => 'attachment',
) );

$this->IDs = "{$a1},{$a2}";
}

/**
* @author scotchfield
* @covers Jetpack_Slideshow_Shortcode::shortcode_callback
Expand All @@ -24,4 +47,35 @@ public function test_shortcodes_slideshow() {
$this->assertNotEquals( $content, $shortcode_content );
}

public function test_shortcodes_slideshow_no_js() {
$content = '[gallery type="slideshow" ids="' . $this->IDs . '"]';

$shortcode_content = do_shortcode( $content );

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

public function test_shortcodes_slideshow_html() {
$content = '[gallery type="slideshow" ids="' . $this->IDs . '"]';

$shortcode_content = do_shortcode( $content );

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

public function test_shortcodes_slideshow_autostart_off() {
$content = '[gallery type="slideshow" ids="' . $this->IDs . '" autostart="false"]';

$shortcode_content = do_shortcode( $content );

$this->assertEquals( ! false, strpos( $shortcode_content, 'data-autostart="false"' ) );
}

public function test_shortcodes_slideshow_autostart_on() {
$content = '[gallery type="slideshow" ids="' . $this->IDs . '" autostart="true"]';

$shortcode_content = do_shortcode( $content );

$this->assertEquals( ! false, strpos( $shortcode_content, 'data-autostart="true"' ) );
}
}
32 changes: 32 additions & 0 deletions tests/php/modules/shortcodes/test_class.soundcloud.php
Expand Up @@ -24,4 +24,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 );
$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 );

$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>' );
}
}
49 changes: 49 additions & 0 deletions tests/php/modules/shortcodes/test_class.twitter-timeline.php
@@ -1,5 +1,13 @@
<?php

/**
* Shortcode for Twitter Timeline
*
* Example: [twitter-timeline id="297487559557251073" username="wordpressdotcom"]
*
* Expected shortcode output:
* <a class="twitter-timeline" data-partner="jetpack" data-width="100" data-height="100" data-widget-id="297487559557251073" href="https://twitter.com/wordpressdotcom">Tweets by @wordpressdotcom</a>
*/
class WP_Test_Jetpack_Shortcodes_TwitterTimeline extends WP_UnitTestCase {

/**
Expand Down Expand Up @@ -36,4 +44,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( '<a class="twitter-timeline" data-partner="jetpack" data-width="450" data-height="282" data-widget-id="297487559557251073">Tweets by @</a>', $shortcode_content );
}

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

$shortcode_content = do_shortcode( $content );

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


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

$shortcode_content = do_shortcode( $content );

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

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

$shortcode_content = do_shortcode( $content );

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

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( '<a class="twitter-timeline" data-partner="jetpack" data-width="100" data-height="100" data-widget-id="297487559557251073" href="https://twitter.com/wordpressdotcom">Tweets by @wordpressdotcom</a>', $shortcode_content );
}
}

0 comments on commit 229a5c5

Please sign in to comment.