2019-04-22 14:05:58 +00:00
|
|
|
<?php
|
2019-10-03 19:24:12 +00:00
|
|
|
|
2019-04-22 14:05:58 +00:00
|
|
|
/**
|
|
|
|
* DownloadControllerTest class.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Alltube\Test;
|
|
|
|
|
|
|
|
use Alltube\Config;
|
|
|
|
use Alltube\Controller\DownloadController;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unit tests for the FrontController class.
|
2019-10-26 14:13:08 +00:00
|
|
|
* @requires download
|
2019-04-22 14:05:58 +00:00
|
|
|
*/
|
|
|
|
class DownloadControllerTest extends ControllerTest
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Prepare tests.
|
|
|
|
*/
|
2019-11-30 13:08:18 +00:00
|
|
|
protected function setUp(): void
|
2019-04-22 14:05:58 +00:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->controller = new DownloadController($this->container);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the download() function without the URL parameter.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testDownloadWithoutUrl()
|
|
|
|
{
|
|
|
|
$this->assertRequestIsRedirect('download');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the download() function.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testDownload()
|
|
|
|
{
|
|
|
|
$this->assertRequestIsRedirect('download', ['url' => 'https://www.youtube.com/watch?v=M7IpKCZ47pU']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the download() function with a specific format.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testDownloadWithFormat()
|
|
|
|
{
|
|
|
|
$this->assertRequestIsRedirect(
|
|
|
|
'download',
|
|
|
|
['url' => 'https://www.youtube.com/watch?v=M7IpKCZ47pU', 'format' => 'worst']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the download() function with streams enabled.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testDownloadWithStream()
|
|
|
|
{
|
|
|
|
Config::setOptions(['stream' => true]);
|
|
|
|
|
|
|
|
$this->assertRequestIsOk(
|
|
|
|
'download',
|
2019-04-27 22:25:03 +00:00
|
|
|
['url' => 'https://www.youtube.com/watch?v=M7IpKCZ47pU', 'stream' => true]
|
2019-04-22 14:05:58 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the download() function with an M3U stream.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testDownloadWithM3uStream()
|
|
|
|
{
|
|
|
|
Config::setOptions(['stream' => true]);
|
|
|
|
|
|
|
|
$this->assertRequestIsOk(
|
|
|
|
'download',
|
|
|
|
[
|
|
|
|
'url' => 'https://twitter.com/verge/status/813055465324056576/video/1',
|
|
|
|
'format' => 'hls-2176',
|
2019-04-27 22:25:03 +00:00
|
|
|
'stream' => true,
|
2019-04-22 14:05:58 +00:00
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the download() function with an RTMP stream.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testDownloadWithRtmpStream()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete('We need to find another RTMP video.');
|
|
|
|
|
|
|
|
Config::setOptions(['stream' => true]);
|
|
|
|
|
|
|
|
$this->assertRequestIsOk(
|
|
|
|
'download',
|
|
|
|
['url' => 'http://www.rtvnh.nl/video/131946', 'format' => 'rtmp-264']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the download() function with a remuxed video.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testDownloadWithRemux()
|
|
|
|
{
|
|
|
|
Config::setOptions(['remux' => true]);
|
|
|
|
|
|
|
|
$this->assertRequestIsOk(
|
|
|
|
'download',
|
|
|
|
[
|
|
|
|
'url' => 'https://www.youtube.com/watch?v=M7IpKCZ47pU',
|
|
|
|
'format' => 'bestvideo+bestaudio',
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the download() function with a remuxed video but remux disabled.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testDownloadWithRemuxDisabled()
|
|
|
|
{
|
|
|
|
$this->assertRequestIsServerError(
|
|
|
|
'download',
|
|
|
|
[
|
|
|
|
'url' => 'https://www.youtube.com/watch?v=M7IpKCZ47pU',
|
|
|
|
'format' => 'bestvideo+bestaudio',
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the download() function with a missing password.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testDownloadWithMissingPassword()
|
|
|
|
{
|
|
|
|
$this->assertRequestIsRedirect('download', ['url' => 'http://vimeo.com/68375962']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the download() function with an error.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testDownloadWithError()
|
|
|
|
{
|
|
|
|
$this->assertRequestIsServerError('download', ['url' => 'http://example.com/foo']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the download() function with an video that returns an empty URL.
|
|
|
|
* This can be caused by trying to redirect to a playlist.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testDownloadWithEmptyUrl()
|
|
|
|
{
|
|
|
|
$this->assertRequestIsServerError(
|
|
|
|
'download',
|
|
|
|
['url' => 'https://www.youtube.com/playlist?list=PLgdySZU6KUXL_8Jq5aUkyNV7wCa-4wZsC']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the download() function with a playlist stream.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
* @requires OS Linux
|
|
|
|
*/
|
|
|
|
public function testDownloadWithPlaylist()
|
|
|
|
{
|
|
|
|
Config::setOptions(['stream' => true]);
|
|
|
|
|
|
|
|
$this->assertRequestIsOk(
|
|
|
|
'download',
|
|
|
|
['url' => 'https://www.youtube.com/playlist?list=PLgdySZU6KUXL_8Jq5aUkyNV7wCa-4wZsC']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the download() function with an advanced conversion.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testDownloadWithAdvancedConversion()
|
|
|
|
{
|
|
|
|
Config::setOptions(['convertAdvanced' => true]);
|
|
|
|
|
|
|
|
$this->assertRequestIsOk(
|
|
|
|
'download',
|
|
|
|
[
|
|
|
|
'url' => 'https://www.youtube.com/watch?v=M7IpKCZ47pU',
|
|
|
|
'format' => 'best',
|
|
|
|
'customConvert' => 'on',
|
|
|
|
'customBitrate' => 32,
|
|
|
|
'customFormat' => 'flv',
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|