2017-01-16 16:19:19 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* FrontControllerTest class.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Alltube\Test;
|
|
|
|
|
|
|
|
use Alltube\Config;
|
2017-01-16 16:31:20 +00:00
|
|
|
use Alltube\Controller\FrontController;
|
2017-05-30 22:07:34 +00:00
|
|
|
use Alltube\LocaleManager;
|
2017-04-25 22:50:19 +00:00
|
|
|
use Alltube\ViewFactory;
|
2018-02-05 15:48:58 +00:00
|
|
|
use Exception;
|
2017-01-16 16:19:19 +00:00
|
|
|
use Slim\Container;
|
|
|
|
use Slim\Http\Environment;
|
|
|
|
use Slim\Http\Request;
|
|
|
|
use Slim\Http\Response;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unit tests for the FrontController class.
|
|
|
|
*/
|
2019-04-21 16:30:02 +00:00
|
|
|
class FrontControllerTest extends BaseTest
|
2017-01-16 16:19:19 +00:00
|
|
|
{
|
2017-01-16 17:47:49 +00:00
|
|
|
/**
|
2017-01-16 17:54:03 +00:00
|
|
|
* Slim dependency container.
|
|
|
|
*
|
2017-01-16 17:47:49 +00:00
|
|
|
* @var Container
|
|
|
|
*/
|
|
|
|
private $container;
|
|
|
|
|
|
|
|
/**
|
2017-01-16 17:54:03 +00:00
|
|
|
* Mock HTTP request.
|
|
|
|
*
|
2017-01-16 17:47:49 +00:00
|
|
|
* @var Request
|
|
|
|
*/
|
|
|
|
private $request;
|
|
|
|
|
|
|
|
/**
|
2017-01-16 17:54:03 +00:00
|
|
|
* Mock HTTP response.
|
|
|
|
*
|
2017-01-16 17:47:49 +00:00
|
|
|
* @var Response
|
|
|
|
*/
|
|
|
|
private $response;
|
|
|
|
|
|
|
|
/**
|
2017-01-16 17:54:03 +00:00
|
|
|
* FrontController instance used in tests.
|
|
|
|
*
|
2017-01-16 17:47:49 +00:00
|
|
|
* @var FrontController
|
|
|
|
*/
|
|
|
|
private $controller;
|
|
|
|
|
2017-01-16 16:19:19 +00:00
|
|
|
/**
|
|
|
|
* Prepare tests.
|
|
|
|
*/
|
|
|
|
protected function setUp()
|
|
|
|
{
|
2019-04-21 16:30:02 +00:00
|
|
|
parent::setUp();
|
|
|
|
|
2017-01-16 16:19:19 +00:00
|
|
|
$this->container = new Container();
|
|
|
|
$this->request = Request::createFromEnvironment(Environment::mock());
|
|
|
|
$this->response = new Response();
|
2017-04-25 22:50:19 +00:00
|
|
|
$this->container['view'] = ViewFactory::create($this->container, $this->request);
|
2017-05-30 22:07:34 +00:00
|
|
|
$this->container['locale'] = new LocaleManager();
|
2017-11-11 12:58:55 +00:00
|
|
|
|
2019-04-21 16:30:02 +00:00
|
|
|
$this->controller = new FrontController($this->container);
|
2017-11-11 12:58:55 +00:00
|
|
|
|
2017-01-16 16:19:19 +00:00
|
|
|
$this->container['router']->map(['GET'], '/', [$this->controller, 'index'])
|
|
|
|
->setName('index');
|
|
|
|
$this->container['router']->map(['GET'], '/video', [$this->controller, 'video'])
|
|
|
|
->setName('video');
|
|
|
|
$this->container['router']->map(['GET'], '/extractors', [$this->controller, 'extractors'])
|
|
|
|
->setName('extractors');
|
|
|
|
$this->container['router']->map(['GET'], '/redirect', [$this->controller, 'redirect'])
|
|
|
|
->setName('redirect');
|
2017-05-30 22:07:34 +00:00
|
|
|
$this->container['router']->map(['GET'], '/locale', [$this->controller, 'locale'])
|
|
|
|
->setName('locale');
|
2017-01-16 16:19:19 +00:00
|
|
|
}
|
|
|
|
|
2017-04-25 21:49:13 +00:00
|
|
|
/**
|
2017-04-25 22:10:00 +00:00
|
|
|
* Run controller function with custom query parameters and return the result.
|
2017-04-25 21:49:13 +00:00
|
|
|
*
|
|
|
|
* @param string $request Controller function to call
|
|
|
|
* @param array $params Query parameters
|
|
|
|
*
|
|
|
|
* @return Response HTTP response
|
|
|
|
*/
|
2019-04-21 16:30:02 +00:00
|
|
|
private function getRequestResult($request, array $params)
|
2017-04-25 21:49:13 +00:00
|
|
|
{
|
2019-04-21 16:30:02 +00:00
|
|
|
return $this->controller->$request(
|
2017-04-25 21:49:13 +00:00
|
|
|
$this->request->withQueryParams($params),
|
|
|
|
$this->response
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-04-25 22:10:00 +00:00
|
|
|
* Assert that calling controller function with these parameters returns a 200 HTTP response.
|
2017-04-25 21:49:13 +00:00
|
|
|
*
|
|
|
|
* @param string $request Controller function to call
|
|
|
|
* @param array $params Query parameters
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-04-21 16:30:02 +00:00
|
|
|
private function assertRequestIsOk($request, array $params = [])
|
2017-04-25 21:49:13 +00:00
|
|
|
{
|
2019-04-21 16:30:02 +00:00
|
|
|
$this->assertTrue($this->getRequestResult($request, $params)->isOk());
|
2017-04-25 21:49:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-04-25 22:10:00 +00:00
|
|
|
* Assert that calling controller function with these parameters returns an HTTP redirect.
|
2017-04-25 21:49:13 +00:00
|
|
|
*
|
|
|
|
* @param string $request Controller function to call
|
|
|
|
* @param array $params Query parameters
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-04-21 16:30:02 +00:00
|
|
|
private function assertRequestIsRedirect($request, array $params = [])
|
2017-04-25 21:49:13 +00:00
|
|
|
{
|
2019-04-21 16:30:02 +00:00
|
|
|
$this->assertTrue($this->getRequestResult($request, $params)->isRedirect());
|
2017-04-25 21:49:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-03-20 11:02:21 +00:00
|
|
|
* Assert that calling controller function with these parameters returns an HTTP 500 error.
|
2017-04-25 21:49:13 +00:00
|
|
|
*
|
|
|
|
* @param string $request Controller function to call
|
|
|
|
* @param array $params Query parameters
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-04-21 16:30:02 +00:00
|
|
|
private function assertRequestIsServerError($request, array $params = [])
|
2017-04-25 21:49:13 +00:00
|
|
|
{
|
2019-04-21 16:30:02 +00:00
|
|
|
$this->assertTrue($this->getRequestResult($request, $params)->isServerError());
|
2017-04-25 21:49:13 +00:00
|
|
|
}
|
|
|
|
|
2018-03-20 11:02:21 +00:00
|
|
|
/**
|
|
|
|
* Assert that calling controller function with these parameters returns an HTTP 400 error.
|
|
|
|
*
|
|
|
|
* @param string $request Controller function to call
|
|
|
|
* @param array $params Query parameters
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-04-21 16:30:02 +00:00
|
|
|
private function assertRequestIsClientError($request, array $params = [])
|
2018-03-20 11:02:21 +00:00
|
|
|
{
|
2019-04-21 16:30:02 +00:00
|
|
|
$this->assertTrue($this->getRequestResult($request, $params)->isClientError());
|
2018-03-20 11:02:21 +00:00
|
|
|
}
|
|
|
|
|
2017-04-24 16:07:59 +00:00
|
|
|
/**
|
|
|
|
* Test the constructor.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testConstructor()
|
2017-11-11 12:58:55 +00:00
|
|
|
{
|
2019-04-21 16:30:02 +00:00
|
|
|
$this->assertInstanceOf(FrontController::class, new FrontController($this->container));
|
2017-04-24 16:07:59 +00:00
|
|
|
}
|
|
|
|
|
2017-01-16 16:19:19 +00:00
|
|
|
/**
|
2017-01-16 16:31:20 +00:00
|
|
|
* Test the constructor with streams enabled.
|
|
|
|
*
|
2017-01-16 16:19:19 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testConstructorWithStream()
|
|
|
|
{
|
2019-04-21 16:30:02 +00:00
|
|
|
Config::setOptions(['stream' => true]);
|
|
|
|
$this->assertInstanceOf(FrontController::class, new FrontController($this->container));
|
2017-01-16 16:19:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-16 16:31:20 +00:00
|
|
|
* Test the index() function.
|
|
|
|
*
|
2017-01-16 16:19:19 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testIndex()
|
|
|
|
{
|
2017-04-25 21:49:13 +00:00
|
|
|
$this->assertRequestIsOk('index');
|
2017-01-16 16:19:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-16 16:31:20 +00:00
|
|
|
* Test the index() function with a custom URI.
|
|
|
|
*
|
2017-01-16 16:19:19 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testIndexWithCustomUri()
|
|
|
|
{
|
|
|
|
$result = $this->controller->index(
|
|
|
|
Request::createFromEnvironment(
|
2017-10-29 22:21:13 +00:00
|
|
|
Environment::mock(['REQUEST_URI' => '/foo', 'QUERY_STRING' => 'foo=bar'])
|
2017-01-16 16:19:19 +00:00
|
|
|
),
|
|
|
|
$this->response
|
|
|
|
);
|
|
|
|
$this->assertTrue($result->isOk());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-16 16:31:20 +00:00
|
|
|
* Test the extractors() function.
|
|
|
|
*
|
2017-01-16 16:19:19 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testExtractors()
|
|
|
|
{
|
2017-04-25 21:49:13 +00:00
|
|
|
$this->assertRequestIsOk('extractors');
|
2017-01-16 16:19:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-16 16:31:20 +00:00
|
|
|
* Test the password() function.
|
|
|
|
*
|
2017-01-16 16:19:19 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testPassword()
|
|
|
|
{
|
2017-04-25 21:49:13 +00:00
|
|
|
$this->assertRequestIsOk('password');
|
2017-01-16 16:19:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-16 16:31:20 +00:00
|
|
|
* Test the video() function without the url parameter.
|
|
|
|
*
|
2017-01-16 16:19:19 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testVideoWithoutUrl()
|
|
|
|
{
|
2017-04-25 21:49:13 +00:00
|
|
|
$this->assertRequestIsRedirect('video');
|
2017-01-16 16:19:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-16 16:31:20 +00:00
|
|
|
* Test the video() function.
|
|
|
|
*
|
2017-01-16 16:19:19 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testVideo()
|
|
|
|
{
|
2017-10-29 22:21:13 +00:00
|
|
|
$this->assertRequestIsOk('video', ['url' => 'https://www.youtube.com/watch?v=M7IpKCZ47pU']);
|
2017-01-16 16:19:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-16 16:31:20 +00:00
|
|
|
* Test the video() function with audio conversion.
|
|
|
|
*
|
2017-01-16 16:19:19 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testVideoWithAudio()
|
|
|
|
{
|
2017-10-29 22:21:13 +00:00
|
|
|
$this->assertRequestIsOk('video', ['url' => 'https://www.youtube.com/watch?v=M7IpKCZ47pU', 'audio' => true]);
|
2017-01-16 16:19:19 +00:00
|
|
|
}
|
|
|
|
|
2018-05-01 14:43:22 +00:00
|
|
|
/**
|
|
|
|
* Test the video() function with audio conversion from a Vimeo video.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testVideoWithVimeoAudio()
|
|
|
|
{
|
2019-04-19 21:26:03 +00:00
|
|
|
if (getenv('CI')) {
|
|
|
|
$this->markTestSkipped('Travis is blacklisted by Vimeo.');
|
|
|
|
}
|
2018-05-01 14:43:22 +00:00
|
|
|
// So we can test the fallback to default format
|
|
|
|
$this->assertRequestIsOk('video', ['url' => 'https://vimeo.com/251997032', 'audio' => true]);
|
|
|
|
}
|
|
|
|
|
2017-01-16 16:19:19 +00:00
|
|
|
/**
|
2017-01-16 16:31:20 +00:00
|
|
|
* Test the video() function with audio enabled and an URL that doesn't need to be converted.
|
|
|
|
*
|
2017-01-16 16:19:19 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testVideoWithUnconvertedAudio()
|
|
|
|
{
|
2017-04-25 21:49:13 +00:00
|
|
|
$this->assertRequestIsRedirect(
|
|
|
|
'video',
|
2017-11-10 11:19:04 +00:00
|
|
|
[
|
|
|
|
'url' => 'https://2080.bandcamp.com/track/cygnus-x-the-orange-theme-2080-faulty-chip-cover',
|
|
|
|
'audio' => true,
|
|
|
|
]
|
2017-01-16 16:19:19 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-16 16:31:20 +00:00
|
|
|
* Test the video() function with a password.
|
|
|
|
*
|
2017-01-16 16:19:19 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testVideoWithPassword()
|
|
|
|
{
|
2019-04-19 21:26:03 +00:00
|
|
|
if (getenv('CI')) {
|
|
|
|
$this->markTestSkipped('Travis is blacklisted by Vimeo.');
|
|
|
|
}
|
2017-01-16 16:19:19 +00:00
|
|
|
$result = $this->controller->video(
|
2017-10-29 22:21:13 +00:00
|
|
|
$this->request->withQueryParams(['url' => 'http://vimeo.com/68375962'])
|
|
|
|
->withParsedBody(['password' => 'youtube-dl']),
|
2017-01-16 16:19:19 +00:00
|
|
|
$this->response
|
|
|
|
);
|
|
|
|
$this->assertTrue($result->isOk());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-16 16:31:20 +00:00
|
|
|
* Test the video() function with a missing password.
|
|
|
|
*
|
2017-01-16 16:19:19 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testVideoWithMissingPassword()
|
|
|
|
{
|
2019-04-19 21:26:03 +00:00
|
|
|
if (getenv('CI')) {
|
|
|
|
$this->markTestSkipped('Travis is blacklisted by Vimeo.');
|
|
|
|
}
|
2017-10-29 22:21:13 +00:00
|
|
|
$this->assertRequestIsOk('video', ['url' => 'http://vimeo.com/68375962']);
|
|
|
|
$this->assertRequestIsOk('video', ['url' => 'http://vimeo.com/68375962', 'audio' => true]);
|
2017-01-16 16:19:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-16 16:31:20 +00:00
|
|
|
* Test the video() function with streams enabled.
|
|
|
|
*
|
2017-01-16 16:19:19 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testVideoWithStream()
|
|
|
|
{
|
2019-04-21 16:30:02 +00:00
|
|
|
Config::setOptions(['stream' => true]);
|
|
|
|
|
|
|
|
$this->assertRequestIsOk('video', ['url' => 'https://www.youtube.com/watch?v=M7IpKCZ47pU']);
|
2017-04-25 21:49:13 +00:00
|
|
|
$this->assertRequestIsOk(
|
|
|
|
'video',
|
2019-04-21 16:30:02 +00:00
|
|
|
['url' => 'https://www.youtube.com/watch?v=M7IpKCZ47pU', 'audio' => true]
|
2017-01-16 16:19:19 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-04-24 23:53:38 +00:00
|
|
|
/**
|
|
|
|
* Test the video() function with a playlist.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testVideoWithPlaylist()
|
|
|
|
{
|
2017-04-25 21:49:13 +00:00
|
|
|
$this->assertRequestIsOk(
|
|
|
|
'video',
|
2017-10-29 22:21:13 +00:00
|
|
|
['url' => 'https://www.youtube.com/playlist?list=PLgdySZU6KUXL_8Jq5aUkyNV7wCa-4wZsC']
|
2017-04-24 23:53:38 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-01-16 16:19:19 +00:00
|
|
|
/**
|
2017-01-16 16:31:20 +00:00
|
|
|
* Test the error() function.
|
|
|
|
*
|
2017-01-16 16:19:19 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testError()
|
|
|
|
{
|
2018-02-05 15:48:58 +00:00
|
|
|
$result = $this->controller->error($this->request, $this->response, new Exception('foo'));
|
2017-01-16 16:19:19 +00:00
|
|
|
$this->assertTrue($result->isServerError());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-16 16:31:20 +00:00
|
|
|
* Test the redirect() function without the URL parameter.
|
|
|
|
*
|
2017-01-16 16:19:19 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testRedirectWithoutUrl()
|
|
|
|
{
|
2017-04-25 21:49:13 +00:00
|
|
|
$this->assertRequestIsRedirect('redirect');
|
2017-01-16 16:19:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-16 16:31:20 +00:00
|
|
|
* Test the redirect() function.
|
|
|
|
*
|
2017-01-16 16:19:19 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testRedirect()
|
|
|
|
{
|
2017-10-29 22:21:13 +00:00
|
|
|
$this->assertRequestIsRedirect('redirect', ['url' => 'https://www.youtube.com/watch?v=M7IpKCZ47pU']);
|
2017-01-16 16:19:19 +00:00
|
|
|
}
|
|
|
|
|
2017-03-19 11:27:08 +00:00
|
|
|
/**
|
|
|
|
* Test the redirect() function with a specific format.
|
2017-03-19 11:28:54 +00:00
|
|
|
*
|
2017-03-19 11:27:08 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testRedirectWithFormat()
|
|
|
|
{
|
2017-04-25 21:49:13 +00:00
|
|
|
$this->assertRequestIsRedirect(
|
|
|
|
'redirect',
|
2017-10-29 22:21:13 +00:00
|
|
|
['url' => 'https://www.youtube.com/watch?v=M7IpKCZ47pU', 'format' => 'worst']
|
2017-03-19 11:27:08 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-01-16 16:19:19 +00:00
|
|
|
/**
|
2017-01-16 16:31:20 +00:00
|
|
|
* Test the redirect() function with streams enabled.
|
|
|
|
*
|
2017-01-16 16:19:19 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testRedirectWithStream()
|
|
|
|
{
|
2019-04-21 16:30:02 +00:00
|
|
|
Config::setOptions(['stream' => true]);
|
|
|
|
|
2017-04-25 21:49:13 +00:00
|
|
|
$this->assertRequestIsOk(
|
|
|
|
'redirect',
|
2019-04-21 16:30:02 +00:00
|
|
|
['url' => 'https://www.youtube.com/watch?v=M7IpKCZ47pU']
|
2017-01-16 16:19:19 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-16 16:31:20 +00:00
|
|
|
* Test the redirect() function with an M3U stream.
|
|
|
|
*
|
2017-01-16 16:19:19 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testRedirectWithM3uStream()
|
|
|
|
{
|
2019-04-20 10:23:18 +00:00
|
|
|
if (getenv('CI')) {
|
|
|
|
$this->markTestSkipped('Twitter returns a 429 error when the test is ran too many times.');
|
|
|
|
}
|
2019-04-21 16:30:02 +00:00
|
|
|
|
|
|
|
Config::setOptions(['stream' => true]);
|
|
|
|
|
2017-04-25 21:49:13 +00:00
|
|
|
$this->assertRequestIsOk(
|
|
|
|
'redirect',
|
2017-12-23 15:05:14 +00:00
|
|
|
[
|
|
|
|
'url' => 'https://twitter.com/verge/status/813055465324056576/video/1',
|
|
|
|
'format' => 'hls-2176',
|
2019-04-21 16:30:02 +00:00
|
|
|
]
|
2017-01-16 16:19:19 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-04-24 16:31:14 +00:00
|
|
|
/**
|
|
|
|
* Test the redirect() function with an RTMP stream.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testRedirectWithRtmpStream()
|
|
|
|
{
|
2019-01-15 10:25:49 +00:00
|
|
|
$this->markTestIncomplete('We need to find another RTMP video.');
|
|
|
|
|
2019-04-21 16:30:02 +00:00
|
|
|
Config::setOptions(['stream' => true]);
|
|
|
|
|
2017-04-25 21:49:13 +00:00
|
|
|
$this->assertRequestIsOk(
|
|
|
|
'redirect',
|
2019-04-21 16:30:02 +00:00
|
|
|
['url' => 'http://www.rtvnh.nl/video/131946', 'format' => 'rtmp-264']
|
2017-04-24 16:31:14 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-04-24 22:40:24 +00:00
|
|
|
/**
|
|
|
|
* Test the redirect() function with a remuxed video.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testRedirectWithRemux()
|
|
|
|
{
|
2019-04-21 16:30:02 +00:00
|
|
|
Config::setOptions(['remux' => true]);
|
|
|
|
|
2017-04-25 21:49:13 +00:00
|
|
|
$this->assertRequestIsOk(
|
|
|
|
'redirect',
|
|
|
|
[
|
2017-10-29 22:21:13 +00:00
|
|
|
'url' => 'https://www.youtube.com/watch?v=M7IpKCZ47pU',
|
|
|
|
'format' => 'bestvideo+bestaudio',
|
2019-04-21 16:30:02 +00:00
|
|
|
]
|
2017-04-24 22:40:24 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the redirect() function with a remuxed video but remux disabled.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testRedirectWithRemuxDisabled()
|
|
|
|
{
|
2017-04-25 21:49:13 +00:00
|
|
|
$this->assertRequestIsServerError(
|
|
|
|
'redirect',
|
|
|
|
[
|
2017-10-29 22:21:13 +00:00
|
|
|
'url' => 'https://www.youtube.com/watch?v=M7IpKCZ47pU',
|
|
|
|
'format' => 'bestvideo+bestaudio',
|
2017-04-25 21:49:13 +00:00
|
|
|
]
|
2017-04-24 22:40:24 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-01-16 16:19:19 +00:00
|
|
|
/**
|
2017-01-16 16:31:20 +00:00
|
|
|
* Test the redirect() function with a missing password.
|
|
|
|
*
|
2017-01-16 16:19:19 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testRedirectWithMissingPassword()
|
|
|
|
{
|
2019-04-19 21:26:03 +00:00
|
|
|
if (getenv('CI')) {
|
|
|
|
$this->markTestSkipped('Travis is blacklisted by Vimeo.');
|
|
|
|
}
|
2017-10-29 22:21:13 +00:00
|
|
|
$this->assertRequestIsRedirect('redirect', ['url' => 'http://vimeo.com/68375962']);
|
2017-01-16 16:19:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-16 16:31:20 +00:00
|
|
|
* Test the redirect() function with an error.
|
|
|
|
*
|
2017-01-16 16:19:19 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testRedirectWithError()
|
|
|
|
{
|
2017-10-29 22:21:13 +00:00
|
|
|
$this->assertRequestIsServerError('redirect', ['url' => 'http://example.com/foo']);
|
2017-01-16 16:19:19 +00:00
|
|
|
}
|
2017-05-02 15:04:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the redirect() function with an video that returns an empty URL.
|
|
|
|
* This can be caused by trying to redirect to a playlist.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testRedirectWithEmptyUrl()
|
|
|
|
{
|
2017-05-19 12:30:59 +00:00
|
|
|
$this->assertRequestIsServerError(
|
|
|
|
'redirect',
|
2017-10-29 22:21:13 +00:00
|
|
|
['url' => 'https://www.youtube.com/playlist?list=PLgdySZU6KUXL_8Jq5aUkyNV7wCa-4wZsC']
|
2017-05-19 12:30:59 +00:00
|
|
|
);
|
2017-05-02 15:04:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the redirect() function with a playlist stream.
|
|
|
|
*
|
|
|
|
* @return void
|
2017-11-11 12:58:55 +00:00
|
|
|
* @requires OS Linux
|
2017-05-02 15:04:55 +00:00
|
|
|
*/
|
|
|
|
public function testRedirectWithPlaylist()
|
|
|
|
{
|
2019-04-21 16:30:02 +00:00
|
|
|
Config::setOptions(['stream' => true]);
|
|
|
|
|
2017-05-02 15:04:55 +00:00
|
|
|
$this->assertRequestIsOk(
|
|
|
|
'redirect',
|
2019-04-21 16:30:02 +00:00
|
|
|
['url' => 'https://www.youtube.com/playlist?list=PLgdySZU6KUXL_8Jq5aUkyNV7wCa-4wZsC']
|
2017-05-02 15:04:55 +00:00
|
|
|
);
|
|
|
|
}
|
2017-05-30 22:48:50 +00:00
|
|
|
|
2018-01-24 22:30:24 +00:00
|
|
|
/**
|
|
|
|
* Test the redirect() function with an advanced conversion.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testRedirectWithAdvancedConversion()
|
|
|
|
{
|
2019-04-21 16:30:02 +00:00
|
|
|
Config::setOptions(['convertAdvanced' => true]);
|
|
|
|
|
2018-01-24 22:30:24 +00:00
|
|
|
$this->assertRequestIsOk(
|
|
|
|
'redirect',
|
|
|
|
[
|
|
|
|
'url' => 'https://www.youtube.com/watch?v=M7IpKCZ47pU',
|
|
|
|
'format' => 'best',
|
|
|
|
'customConvert' => 'on',
|
|
|
|
'customBitrate' => 32,
|
|
|
|
'customFormat' => 'flv',
|
2019-04-21 16:30:02 +00:00
|
|
|
]
|
2018-01-24 22:30:24 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-03-20 11:02:21 +00:00
|
|
|
/**
|
|
|
|
* Test the json() function without the URL parameter.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testJsonWithoutUrl()
|
|
|
|
{
|
|
|
|
$this->assertRequestIsClientError('json');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the json() function.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testJson()
|
|
|
|
{
|
|
|
|
$this->assertRequestIsOk('json', ['url' => 'https://www.youtube.com/watch?v=M7IpKCZ47pU']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the json() function with an error.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testJsonWithError()
|
|
|
|
{
|
|
|
|
$this->assertRequestIsServerError('json', ['url' => 'http://example.com/foo']);
|
|
|
|
}
|
|
|
|
|
2017-05-30 22:48:50 +00:00
|
|
|
/**
|
|
|
|
* Test the locale() function.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testLocale()
|
|
|
|
{
|
|
|
|
$this->assertTrue(
|
|
|
|
$this->controller->locale(
|
|
|
|
$this->request,
|
|
|
|
$this->response,
|
2017-10-29 22:21:13 +00:00
|
|
|
['locale' => 'fr_FR']
|
2017-05-30 22:48:50 +00:00
|
|
|
)->isRedirect()
|
|
|
|
);
|
|
|
|
}
|
2017-01-16 16:19:19 +00:00
|
|
|
}
|