adding unit tests for the new confi file env variable
This commit is contained in:
parent
7d9ec9509b
commit
07a6e3094d
|
@ -4,24 +4,31 @@ use PrivateBin\Configuration;
|
||||||
|
|
||||||
class ConfigurationTest extends PHPUnit_Framework_TestCase
|
class ConfigurationTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
private $_minimalConfig;
|
||||||
|
|
||||||
private $_options;
|
private $_options;
|
||||||
|
|
||||||
private $_minimalConfig;
|
private $_path;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
/* Setup Routine */
|
/* Setup Routine */
|
||||||
Helper::confBackup();
|
Helper::confBackup();
|
||||||
|
$this->_minimalConfig = '[main]' . PHP_EOL . '[model]' . PHP_EOL . '[model_options]';
|
||||||
$this->_options = Configuration::getDefaults();
|
$this->_options = Configuration::getDefaults();
|
||||||
$this->_options['model_options']['dir'] = PATH . $this->_options['model_options']['dir'];
|
$this->_options['model_options']['dir'] = PATH . $this->_options['model_options']['dir'];
|
||||||
$this->_options['traffic']['dir'] = PATH . $this->_options['traffic']['dir'];
|
$this->_options['traffic']['dir'] = PATH . $this->_options['traffic']['dir'];
|
||||||
$this->_options['purge']['dir'] = PATH . $this->_options['purge']['dir'];
|
$this->_options['purge']['dir'] = PATH . $this->_options['purge']['dir'];
|
||||||
$this->_minimalConfig = '[main]' . PHP_EOL . '[model]' . PHP_EOL . '[model_options]';
|
$this->_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'privatebin_cfg';
|
||||||
|
if (!is_dir($this->_path)) {
|
||||||
|
mkdir($this->_path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown()
|
public function tearDown()
|
||||||
{
|
{
|
||||||
/* Tear Down Routine */
|
/* Tear Down Routine */
|
||||||
|
Helper::rmDir($this->_path);
|
||||||
if (is_file(CONF)) {
|
if (is_file(CONF)) {
|
||||||
unlink(CONF);
|
unlink(CONF);
|
||||||
}
|
}
|
||||||
|
@ -177,4 +184,49 @@ class ConfigurationTest extends PHPUnit_Framework_TestCase
|
||||||
$this->assertFileExists(CONF, 'old configuration file gets converted');
|
$this->assertFileExists(CONF, 'old configuration file gets converted');
|
||||||
$this->assertFileNotExists(PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini', 'old configuration file gets removed');
|
$this->assertFileNotExists(PATH . 'cfg' . DIRECTORY_SEPARATOR . 'conf.ini', 'old configuration file gets removed');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testConfigPath()
|
||||||
|
{
|
||||||
|
// setup
|
||||||
|
$configFile = $this->_path . DIRECTORY_SEPARATOR . 'conf.php';
|
||||||
|
$options = $this->_options;
|
||||||
|
$options['main']['name'] = 'OtherBin';
|
||||||
|
Helper::createIniFile($configFile, $options);
|
||||||
|
|
||||||
|
// test
|
||||||
|
putenv('CONFIG_PATH=' . $this->_path);
|
||||||
|
$conf = new Configuration;
|
||||||
|
$this->assertEquals('OtherBin', $conf->getKey('name'), 'changing config path is supported');
|
||||||
|
|
||||||
|
// cleanup environment
|
||||||
|
if (is_file($configFile)) {
|
||||||
|
unlink($configFile);
|
||||||
|
}
|
||||||
|
putenv('CONFIG_PATH');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testConfigPathIni()
|
||||||
|
{
|
||||||
|
// setup
|
||||||
|
$configFile = $this->_path . DIRECTORY_SEPARATOR . 'conf.ini';
|
||||||
|
$configMigrated = $this->_path . DIRECTORY_SEPARATOR . 'conf.php';
|
||||||
|
$options = $this->_options;
|
||||||
|
$options['main']['name'] = 'OtherBin';
|
||||||
|
Helper::createIniFile($configFile, $options);
|
||||||
|
$this->assertFileNotExists(CONF, 'configuration in the default location is non existing');
|
||||||
|
|
||||||
|
// test
|
||||||
|
putenv('CONFIG_PATH=' . $this->_path);
|
||||||
|
$conf = new Configuration;
|
||||||
|
$this->assertEquals('OtherBin', $conf->getKey('name'), 'changing config path is supported for ini files as well');
|
||||||
|
$this->assertFileExists($configMigrated, 'old configuration file gets converted');
|
||||||
|
$this->assertFileNotExists($configFile, 'old configuration file gets removed');
|
||||||
|
$this->assertFileNotExists(CONF, 'configuration is not created in the default location');
|
||||||
|
|
||||||
|
// cleanup environment
|
||||||
|
if (is_file($configFile)) {
|
||||||
|
unlink($configFile);
|
||||||
|
}
|
||||||
|
putenv('CONFIG_PATH');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue