2015-10-31 14:42:25 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* ConfigTest class.
|
2016-08-01 11:29:13 +00:00
|
|
|
*/
|
2016-12-05 12:12:27 +00:00
|
|
|
|
2016-03-29 23:49:08 +00:00
|
|
|
namespace Alltube\Test;
|
|
|
|
|
2015-10-31 14:42:25 +00:00
|
|
|
use Alltube\Config;
|
|
|
|
|
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* Unit tests for the Config class.
|
2016-08-01 11:29:13 +00:00
|
|
|
*/
|
2019-04-21 16:30:02 +00:00
|
|
|
class ConfigTest extends BaseTest
|
2015-10-31 14:42:25 +00:00
|
|
|
{
|
2016-09-05 22:36:47 +00:00
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* Config class instance.
|
|
|
|
*
|
2016-09-05 22:36:47 +00:00
|
|
|
* @var Config
|
|
|
|
*/
|
2016-08-18 23:07:51 +00:00
|
|
|
private $config;
|
|
|
|
|
2016-09-05 22:36:47 +00:00
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* Prepare tests.
|
2016-09-05 22:36:47 +00:00
|
|
|
*/
|
2016-08-18 23:07:51 +00:00
|
|
|
protected function setUp()
|
|
|
|
{
|
2019-04-21 16:56:02 +00:00
|
|
|
parent::setUp();
|
|
|
|
|
2019-04-21 16:30:02 +00:00
|
|
|
$this->config = Config::getInstance();
|
2016-12-26 13:04:18 +00:00
|
|
|
}
|
|
|
|
|
2015-10-31 14:50:32 +00:00
|
|
|
/**
|
2016-09-07 22:28:28 +00:00
|
|
|
* Test the getInstance function.
|
2016-02-28 22:04:53 +00:00
|
|
|
*
|
2015-10-31 14:50:32 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2015-10-31 14:42:25 +00:00
|
|
|
public function testGetInstance()
|
2016-08-18 23:07:51 +00:00
|
|
|
{
|
|
|
|
$this->assertEquals($this->config->convert, false);
|
2017-11-10 10:47:23 +00:00
|
|
|
$this->assertConfig($this->config);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assert that a Config object is correctly instantiated.
|
|
|
|
*
|
2017-11-10 11:19:04 +00:00
|
|
|
* @param Config $config Config class instance.
|
2017-11-10 10:47:23 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
private function assertConfig(Config $config)
|
|
|
|
{
|
|
|
|
$this->assertInternalType('array', $config->params);
|
|
|
|
$this->assertInternalType('string', $config->youtubedl);
|
|
|
|
$this->assertInternalType('string', $config->python);
|
|
|
|
$this->assertInternalType('string', $config->avconv);
|
|
|
|
$this->assertInternalType('bool', $config->convert);
|
|
|
|
$this->assertInternalType('bool', $config->uglyUrls);
|
|
|
|
$this->assertInternalType('bool', $config->stream);
|
|
|
|
$this->assertInternalType('bool', $config->remux);
|
2017-11-10 22:50:17 +00:00
|
|
|
$this->assertInternalType('int', $config->audioBitrate);
|
2016-08-18 23:07:51 +00:00
|
|
|
}
|
|
|
|
|
2016-10-18 08:45:16 +00:00
|
|
|
/**
|
2019-04-21 16:30:02 +00:00
|
|
|
* Test the setFile function.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSetFile()
|
|
|
|
{
|
2019-04-21 17:14:23 +00:00
|
|
|
$this->assertNull(Config::setFile($this->getConfigFile()));
|
2019-04-21 16:30:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the setFile function with a missing config file.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
* @expectedException Exception
|
|
|
|
*/
|
|
|
|
public function testSetFileWithMissingFile()
|
|
|
|
{
|
|
|
|
Config::setFile('foo');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the setOptions function.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSetOptions()
|
|
|
|
{
|
|
|
|
Config::setOptions(['appName' => 'foo']);
|
|
|
|
$config = Config::getInstance();
|
|
|
|
$this->assertEquals($config->appName, 'foo');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the setOptions function.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSetOptionsWithoutUpdate()
|
|
|
|
{
|
|
|
|
Config::setOptions(['appName' => 'foo'], false);
|
|
|
|
$config = Config::getInstance();
|
|
|
|
$this->assertEquals($config->appName, 'foo');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the setOptions function.
|
2016-10-18 08:45:16 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
* @expectedException Exception
|
|
|
|
*/
|
2019-04-21 16:30:02 +00:00
|
|
|
public function testSetOptionsWithBadYoutubedl()
|
2016-10-18 08:45:16 +00:00
|
|
|
{
|
2019-04-21 16:30:02 +00:00
|
|
|
Config::setOptions(['youtubedl' => 'foo']);
|
2016-10-18 08:45:16 +00:00
|
|
|
}
|
|
|
|
|
2017-04-24 15:56:07 +00:00
|
|
|
/**
|
2019-04-21 16:30:02 +00:00
|
|
|
* Test the setOptions function.
|
2017-04-24 15:56:07 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2019-04-21 16:30:02 +00:00
|
|
|
* @expectedException Exception
|
2017-04-24 15:56:07 +00:00
|
|
|
*/
|
2019-04-21 16:30:02 +00:00
|
|
|
public function testSetOptionsWithBadPython()
|
2017-04-24 15:56:07 +00:00
|
|
|
{
|
2019-04-21 16:30:02 +00:00
|
|
|
Config::setOptions(['python' => 'foo']);
|
2017-04-24 15:56:07 +00:00
|
|
|
}
|
|
|
|
|
2016-09-05 22:36:47 +00:00
|
|
|
/**
|
2016-12-26 13:04:18 +00:00
|
|
|
* Test the getInstance function with the CONVERT and PYTHON environment variables.
|
2016-09-07 22:28:28 +00:00
|
|
|
*
|
2016-09-05 22:36:47 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2016-08-18 23:07:51 +00:00
|
|
|
public function testGetInstanceWithEnv()
|
2015-10-31 14:42:25 +00:00
|
|
|
{
|
2016-08-18 23:07:51 +00:00
|
|
|
Config::destroyInstance();
|
2016-12-26 13:04:18 +00:00
|
|
|
putenv('CONVERT=1');
|
2019-04-21 17:14:23 +00:00
|
|
|
Config::setFile($this->getConfigFile());
|
2019-04-21 16:30:02 +00:00
|
|
|
$config = Config::getInstance();
|
2015-10-31 14:42:25 +00:00
|
|
|
$this->assertEquals($config->convert, true);
|
2016-12-26 13:04:18 +00:00
|
|
|
putenv('CONVERT');
|
2015-10-31 14:42:25 +00:00
|
|
|
}
|
|
|
|
}
|