public function TranscoderAbstractionFactoryZencoderTestCase::testExtractFrames in Video 7.2
File
- tests/
TranscoderAbstractionFactoryZencoder.test, line 107 - Tests for the TranscoderAbstractionFactoryZencoder class
Class
- TranscoderAbstractionFactoryZencoderTestCase
- Tests for TranscoderAbstractionFactoryZencoder
Code
public function testExtractFrames() {
$this->transcoder
->setInput(array(
'fid' => 1,
'uri' => 'public://test.mp4',
'filename' => 'test.mp4',
));
// No job, should return FALSE
$out = $this->transcoder
->extractFrames('public', 'png');
$this
->assertFalse($out);
// Set state of job
db_update('video_queue')
->fields(array(
'status' => VIDEO_RENDERING_COMPLETE,
))
->condition('vid', 1)
->execute();
// No files, should return FALSE
// A watchdog message is expected at this point
$out = $this->transcoder
->extractFrames('public', 'png');
$this
->assertFalse($out);
// Make some files
variable_set('video_zencoder_base_url', 'public://incoming');
variable_set('video_thumbnail_count', 5);
$dir = 'public://incoming/videos/thumbnails/1/';
file_prepare_directory($dir, FILE_CREATE_DIRECTORY);
for ($i = 0; $i < 5; $i++) {
file_put_contents($dir . 'thumbnail-1_000' . $i . '.png', $i . '');
}
// Test generation of items array
$out = $this->transcoder
->extractFrames('public', 'png');
$this
->assertTrue(is_array($out), 'extractFrames should return array');
$this
->assertEqual(5, count($out), '5 items should be returned');
// Test whether the original files have been deleted
for ($i = 0; $i < 5; $i++) {
$filename = 'thumbnail-1_000' . $i . '.png';
$this
->assertEqual($filename, $out[$i]->filename);
$this
->assertEqual('image/png', $out[$i]->filemime);
$this
->assertEqual(0, $out[$i]->status);
$this
->assertFalse(file_exists($dir . $filename), 'Thumbnail ' . $i . ' should be deleted from original directory');
$this
->assertTrue(file_exists('public://videos/thumbnails/1/' . $filename), 'Thumbnail ' . $i . ' should exist in target directory');
}
// Calling the method again should return same files
$out = $this->transcoder
->extractFrames('public', 'png');
$this
->assertTrue(is_array($out), 'extractFrames should return array');
$this
->assertEqual(5, count($out), '5 items should be returned');
}