Skip to content

Commit

Permalink
Issue #841: Empty string return in audio_playlist().
Browse files Browse the repository at this point in the history
Inside a conditional, return an empty string.
As Weston mentioned, the PHP DocBlock
indicates a string return value.
Also, add an assertion for this.
And correct the documentation of 'content_width.'
  • Loading branch information
Ryan Kienstra committed Feb 15, 2018
1 parent ccc066d commit aba8cf1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 3 additions & 3 deletions includes/embeds/class-amp-playlist-embed-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ public function shortcode( $attr ) {
/**
* Gets an AMP-compliant audio playlist.
*
* @return string Playlist shortcode markup.
* @return string Playlist shortcode markup, or an empty string.
*/
public function audio_playlist() {
if ( ! isset( $this->data['tracks'] ) ) {
return;
return '';
}
$container_id = 'ampPlaylistCarousel' . self::$playlist_id;
$selected_slide = $container_id . '.selectedSlide';
Expand Down Expand Up @@ -164,7 +164,7 @@ public function audio_playlist() {
* This uses similar markup to the native playlist shortcode output.
* So the styles from wp-mediaelement.min.css will apply to it.
*
* @global content_width.
* @global int content_width.
* @return string $video_playlist Markup for the video playlist.
*/
public function video_playlist() {
Expand Down
5 changes: 4 additions & 1 deletion tests/test-class-amp-playlist-embed-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,12 @@ public function test_get_thumb_dimensions() {
*/
public function test_audio_playlist() {
$attr = $this->get_attributes( 'audio' );
$this->instance->data = $this->instance->get_data( $attr );
$this->instance->data = array();
$playlist = $this->instance->audio_playlist();
$this->assertEquals( '', $playlist );

$this->instance->data = $this->instance->get_data( $attr );
$playlist = $this->instance->audio_playlist();
$this->assertContains( '<amp-carousel', $playlist );
$this->assertContains( '<amp-audio', $playlist );
$this->assertContains( $this->file_1, $playlist );
Expand Down

0 comments on commit aba8cf1

Please sign in to comment.