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
Changes from 11 commits
58491fd
7b53f3b
4cfd623
4db5541
35f81eb
81c1ddf
b2a7c53
acdf3c0
e344690
2da9720
b248065
a6b0195
b1655f3
70b42b5
66b957a
795df85
3b1d303
2a3207b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
$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>' ) ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably should use |
||
} | ||
|
||
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' ) ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
https://phpunit.de/manual/current/en/appendixes.assertions.html#appendixes.assertions.assertContains |
||
} | ||
|
||
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"' ) ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"' ) ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same assertion concern as above. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]'; | ||
|
||
|
@@ -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&hide_related=false&visual=true" width="100%" height="450" iframe="true" /]'; | ||
|
||
$shortcode_content = do_shortcode( $content ); | ||
|
||
$this->assertContains( '<iframe width="100%" height="450"', $shortcode_content ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is ok. I tested it with |
||
$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&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false&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&hide_related=false&show_comments=true&show_user=true&show_reposts=false&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 ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
$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>' ); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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]'; | ||
|
||
|
@@ -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>' ); | ||
} | ||
} |
There was a problem hiding this comment.
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()
orsetUpBeforeClass()
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