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
|
|
|
/**
|
|
|
|
* JsonControllerTest class.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Alltube\Test;
|
|
|
|
|
|
|
|
use Alltube\Controller\JsonController;
|
2020-06-20 23:44:20 +00:00
|
|
|
use Alltube\Exception\ConfigException;
|
2020-07-15 21:23:14 +00:00
|
|
|
use Alltube\Exception\DependencyException;
|
2020-06-20 23:44:20 +00:00
|
|
|
use Alltube\Library\Exception\YoutubedlException;
|
|
|
|
use SmartyException;
|
2019-04-22 14:05:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Unit tests for the FrontController class.
|
|
|
|
*/
|
|
|
|
class JsonControllerTest extends ControllerTest
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Prepare tests.
|
2020-07-15 21:23:14 +00:00
|
|
|
* @throws ConfigException|SmartyException|DependencyException
|
2019-04-22 14:05:58 +00:00
|
|
|
*/
|
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 JsonController($this->container);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the json() function.
|
|
|
|
*
|
|
|
|
* @return void
|
2019-10-26 14:13:08 +00:00
|
|
|
* @requires download
|
2019-04-22 14:05:58 +00:00
|
|
|
*/
|
|
|
|
public function testJson()
|
|
|
|
{
|
|
|
|
$this->assertRequestIsOk('json', ['url' => 'https://www.youtube.com/watch?v=M7IpKCZ47pU']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the json() function with an error.
|
|
|
|
*
|
|
|
|
* @return void
|
2019-10-26 14:13:08 +00:00
|
|
|
* @requires download
|
2019-04-22 14:05:58 +00:00
|
|
|
*/
|
|
|
|
public function testJsonWithError()
|
|
|
|
{
|
2020-06-20 23:44:20 +00:00
|
|
|
$this->expectException(YoutubedlException::class);
|
|
|
|
$this->getRequestResult('json', ['url' => 'http://example.com/foo']);
|
2019-04-22 14:05:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the json() function without the URL parameter.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testJsonWithoutUrl()
|
|
|
|
{
|
|
|
|
$this->assertRequestIsClientError('json');
|
|
|
|
}
|
|
|
|
}
|