Skip to content

Commit

Permalink
Issue #841: Remove dependence on test files.
Browse files Browse the repository at this point in the history
Before, test_shortcode() used test files from Core.
But these did not exist in 4.7, and caused a failure.
So create new mock files to test.
  • Loading branch information
Ryan Kienstra committed Feb 11, 2018
1 parent 00a3f08 commit 8140a40
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions tests/test-class-amp-playlist-embed-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,38 @@ public function test_unregister_embed() {
/**
* Test shortcode.
*
* Logic for creating the upload object copied from Tests_Media.
* Logic for creating the videos copied from Tests_Media.
*
* @covers AMP_Playlist_Embed_Handler::shortcode()
*/
public function test_shortcode() {
$id_mp4 = $this->factory->attachment->create_upload_object( DIR_TESTDATA . '/uploads/small-video.mp4' );
$id_mkv = $this->factory->attachment->create_upload_object( DIR_TESTDATA . '/uploads/small-video.mkv' );
$ids = array(
$id_mp4,
$id_mkv,
$file_1 = 'example-video-1.mp4';
$file_2 = 'example-video-2.mkv';
$files = array(
$file_1,
$file_2,
);

$ids = array();
foreach ( $files as $file ) {
$ids[] = $this->factory()->attachment->create_object(
$file,
0,
array(
'post_mime_type' => 'video/mp4',
'post_type' => 'attachment',
)
);
}
$attr = array(
'ids' => implode( ',', $ids ),
'type' => 'video',
);
$playlist = $this->instance->shortcode( $attr );
$this->assertContains( '<amp-video', $playlist );
$this->assertContains( '<amp-state', $playlist );
$this->assertContains( 'small-video', $playlist );
$this->assertContains( $file_1, $playlist );
$this->assertContains( $file_2, $playlist );
$this->assertContains( '[src]="playlist0[playlist0.currentVideo].videoUrl"', $playlist );
$this->assertContains( 'on="tap:AMP.setState({playlist0: {currentVideo: 0}})"', $playlist );
}
Expand Down

0 comments on commit 8140a40

Please sign in to comment.