alltube/tests/JsonControllerTest.php

65 lines
1.4 KiB
PHP
Raw Permalink Normal View History

<?php
/**
* JsonControllerTest class.
*/
namespace Alltube\Test;
use Alltube\Controller\JsonController;
use Alltube\Exception\ConfigException;
2020-10-21 23:07:12 +02:00
use Alltube\Exception\DependencyException;
use Alltube\Library\Exception\YoutubedlException;
use SmartyException;
/**
* Unit tests for the FrontController class.
*/
class JsonControllerTest extends ControllerTest
{
/**
* Prepare tests.
2020-10-20 23:29:50 +02:00
* @throws ConfigException|SmartyException
2020-10-21 23:07:12 +02:00
* @throws DependencyException
*/
2019-11-30 14:08:18 +01:00
protected function setUp(): void
{
parent::setUp();
$this->controller = new JsonController($this->container);
}
/**
* Test the json() function.
*
* @return void
* @requires download
*/
public function testJson()
{
$this->assertRequestIsOk('json', ['url' => 'https://www.youtube.com/watch?v=M7IpKCZ47pU']);
}
/**
* Test the json() function with an error.
*
* @return void
* @requires download
*/
public function testJsonWithError()
{
$this->expectException(YoutubedlException::class);
2022-02-27 23:44:36 +01:00
$this->getRequestResult('json', ['url' => 'https://example.com/foo']);
}
/**
* Test the json() function without the URL parameter.
*
* @return void
*/
public function testJsonWithoutUrl()
{
$this->assertRequestIsClientError('json');
}
}