alltube/tests/VideoDownloadTest.php

165 lines
4 KiB
PHP
Raw Normal View History

2015-08-29 19:46:57 +00:00
<?php
/**
* VideoDownloadTest class
*
* PHP Version 5.3.10
*
* @category Youtube-dl
* @package Youtubedl
* @author Pierre Rudloff <contact@rudloff.pro>
* @license GNU General Public License http://www.gnu.org/licenses/gpl.html
* @link http://rudloff.pro
* */
2015-10-29 19:43:43 +00:00
use Alltube\VideoDownload;
2015-08-29 19:46:57 +00:00
/**
* Unit tests for the VideoDownload class
*
* PHP Version 5.3.10
*
* @category Youtube-dl
* @package Youtubedl
* @author Pierre Rudloff <contact@rudloff.pro>
* @license GNU General Public License http://www.gnu.org/licenses/gpl.html
* @link http://rudloff.pro
* */
class VideoDownloadTest extends PHPUnit_Framework_TestCase
{
/**
* Test getUA function
2015-10-29 17:40:22 +00:00
*
2015-08-29 19:46:57 +00:00
* @return void
*/
public function testGetUA()
{
$this->assertStringStartsWith('Mozilla/', VideoDownload::getUA());
}
/**
* Test listExtractors funtion
2015-10-29 17:40:22 +00:00
*
2015-08-29 19:46:57 +00:00
* @return void
*/
public function testListExtractors()
{
$extractors = VideoDownload::listExtractors();
$this->assertContains('youtube', $extractors);
2015-08-29 19:46:57 +00:00
}
/**
* Test getURL function
2015-10-29 17:40:22 +00:00
*
* @param string $url URL
* @param string $format Format
2015-10-29 17:40:22 +00:00
*
2015-10-29 20:23:02 +00:00
* @return void
2015-10-29 17:40:22 +00:00
* @dataProvider urlProvider
*/
public function testGetURL($url, $format)
{
$videoURL = VideoDownload::getURL($url, $format);
$this->assertArrayHasKey('success', $videoURL);
$this->assertArrayHasKey('url', $videoURL);
}
/**
* Test getURL function errors
2015-10-29 17:40:22 +00:00
*
* @param string $url URL
2015-10-29 17:40:22 +00:00
*
2015-10-29 20:23:02 +00:00
* @return void
* @expectedException Exception
2015-10-29 20:23:02 +00:00
* @dataProvider ErrorUrlProvider
*/
public function testGetURLError($url)
{
$videoURL = VideoDownload::getURL($url);
}
/**
* Provides URLs for tests
2015-10-29 17:40:22 +00:00
*
2015-10-31 10:23:58 +00:00
* @return array
*/
2015-10-29 17:40:22 +00:00
public function urlProvider()
{
return array(
array(
'https://www.youtube.com/watch?v=M7IpKCZ47pU', null,
"It's Not Me, It's You - Hearts Under Fire-M7IpKCZ47pU.mp4"
),
array(
'https://www.youtube.com/watch?v=RJJ6FCAXvKg', 22,
"'Heart Attack' - Demi Lovato ".
"(Sam Tsui & Against The Current)-RJJ6FCAXvKg.mp4"
),
array(
'https://vimeo.com/24195442', null,
"Carving the Mountains-24195442.mp4"
),
);
}
/**
* Provides incorrect URLs for tests
2015-10-29 17:40:22 +00:00
*
2015-10-31 10:23:58 +00:00
* @return array
*/
2015-10-29 17:40:22 +00:00
public function errorUrlProvider()
{
return array(
array('http://example.com/video')
);
}
/**
* Test getFilename function
2015-10-29 17:40:22 +00:00
*
* @param string $url URL
* @param string $format Format
* @param string $result Expected filename
2015-10-29 17:40:22 +00:00
*
2015-10-29 20:23:02 +00:00
* @return void
* @dataProvider URLProvider
*/
public function testGetFilename($url, $format, $result)
{
$filename = VideoDownload::getFilename($url, $format);
$this->assertEquals($filename, $result);
}
/**
* Test getJSON function
2015-10-29 17:40:22 +00:00
*
* @param string $url URL
* @param string $format Format
2015-10-29 17:40:22 +00:00
*
2015-10-29 20:23:02 +00:00
* @return void
* @dataProvider URLProvider
*/
public function testGetJSON($url, $format)
{
$info = VideoDownload::getJSON($url, $format);
$this->assertObjectHasAttribute('webpage_url', $info);
$this->assertObjectHasAttribute('url', $info);
$this->assertObjectHasAttribute('ext', $info);
$this->assertObjectHasAttribute('title', $info);
$this->assertObjectHasAttribute('formats', $info);
$this->assertObjectHasAttribute('_filename', $info);
}
/**
* Test getJSON function errors
2015-10-29 17:40:22 +00:00
*
* @param string $url URL
2015-10-29 17:40:22 +00:00
*
2015-10-29 20:23:02 +00:00
* @return void
* @expectedException Exception
2015-10-29 20:23:02 +00:00
* @dataProvider ErrorURLProvider
2015-08-29 19:46:57 +00:00
*/
public function testGetJSONError($url)
2015-08-29 19:46:57 +00:00
{
$videoURL = VideoDownload::getJSON($url);
2015-08-29 19:46:57 +00:00
}
}