2015-10-22 14:51:01 -04:00
|
|
|
<?php
|
|
|
|
class configurationTest extends PHPUnit_Framework_TestCase
|
|
|
|
{
|
2016-07-11 08:15:20 -04:00
|
|
|
private $_options;
|
2015-10-22 14:51:01 -04:00
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
/* Setup Routine */
|
|
|
|
helper::confBackup();
|
2016-07-11 08:15:20 -04:00
|
|
|
$this->_options = configuration::getDefaults();
|
|
|
|
$this->_options['model_options']['dir'] = PATH . $this->_options['model_options']['dir'];
|
|
|
|
$this->_options['traffic']['dir'] = PATH . $this->_options['traffic']['dir'];
|
2015-10-22 14:51:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function tearDown()
|
|
|
|
{
|
|
|
|
/* Tear Down Routine */
|
|
|
|
helper::confRestore();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDefaultConfigFile()
|
|
|
|
{
|
|
|
|
$this->assertTrue(copy(CONF . '.bak', CONF), 'copy default configuration file');
|
|
|
|
$conf = new configuration;
|
|
|
|
$this->assertEquals($this->_options, $conf->get(), 'default configuration is correct');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testHandleFreshConfigFile()
|
|
|
|
{
|
|
|
|
helper::createIniFile(CONF, $this->_options);
|
|
|
|
$conf = new configuration;
|
|
|
|
$this->assertEquals($this->_options, $conf->get(), 'newly generated configuration is correct');
|
|
|
|
}
|
|
|
|
|
2015-10-22 15:13:15 -04:00
|
|
|
public function testHandleMissingConfigFile()
|
|
|
|
{
|
|
|
|
@unlink(CONF);
|
|
|
|
$conf = new configuration;
|
|
|
|
$this->assertEquals($this->_options, $conf->get(), 'returns correct defaults on missing file');
|
|
|
|
}
|
|
|
|
|
2015-10-22 14:51:01 -04:00
|
|
|
/**
|
|
|
|
* @expectedException Exception
|
|
|
|
* @expectedExceptionCode 2
|
|
|
|
*/
|
|
|
|
public function testHandleBlankConfigFile()
|
|
|
|
{
|
|
|
|
file_put_contents(CONF, '');
|
2016-07-04 14:46:45 -04:00
|
|
|
new configuration;
|
2015-10-22 14:51:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testHandleMinimalConfigFile()
|
|
|
|
{
|
|
|
|
file_put_contents(CONF, '[main]' . PHP_EOL . '[model]');
|
|
|
|
$conf = new configuration;
|
|
|
|
$this->assertEquals($this->_options, $conf->get(), 'returns correct defaults on empty file');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException Exception
|
|
|
|
* @expectedExceptionCode 3
|
|
|
|
*/
|
|
|
|
public function testHandleInvalidSection()
|
|
|
|
{
|
|
|
|
file_put_contents(CONF, '[main]' . PHP_EOL . '[model]');
|
|
|
|
$conf = new configuration;
|
|
|
|
$conf->getKey('foo', 'bar');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException Exception
|
|
|
|
* @expectedExceptionCode 4
|
|
|
|
*/
|
|
|
|
public function testHandleInvalidKey()
|
|
|
|
{
|
|
|
|
file_put_contents(CONF, '[main]' . PHP_EOL . '[model]');
|
|
|
|
$conf = new configuration;
|
|
|
|
$conf->getKey('foo');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testHandleGetKey()
|
|
|
|
{
|
|
|
|
file_put_contents(CONF, '[main]' . PHP_EOL . '[model]');
|
|
|
|
$conf = new configuration;
|
|
|
|
$this->assertEquals($this->_options['main']['sizelimit'], $conf->getKey('sizelimit'), 'get default size');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testHandleWrongTypes()
|
|
|
|
{
|
2015-10-24 02:44:17 -04:00
|
|
|
$original_options = $this->_options;
|
|
|
|
$original_options['main']['syntaxhighlightingtheme'] = 'foo';
|
|
|
|
$options = $original_options;
|
2015-10-22 14:51:01 -04:00
|
|
|
$options['main']['discussion'] = 'true';
|
|
|
|
$options['main']['opendiscussion'] = 0;
|
|
|
|
$options['main']['password'] = -1; // evaluates to TRUE
|
|
|
|
$options['main']['fileupload'] = 'false';
|
|
|
|
$options['expire_options']['foo'] = 'bar';
|
|
|
|
$options['formatter_options'][] = 'foo';
|
|
|
|
helper::createIniFile(CONF, $options);
|
|
|
|
$conf = new configuration;
|
2015-10-24 02:44:17 -04:00
|
|
|
$original_options['expire_options']['foo'] = intval('bar');
|
|
|
|
$original_options['formatter_options'][0] = 'foo';
|
|
|
|
$this->assertEquals($original_options, $conf->get(), 'incorrect types are corrected');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testHandleMissingSubKeys()
|
|
|
|
{
|
|
|
|
$options = $this->_options;
|
|
|
|
unset($options['expire_options']['1week']);
|
|
|
|
unset($options['expire_options']['1year']);
|
|
|
|
unset($options['expire_options']['never']);
|
|
|
|
helper::createIniFile(CONF, $options);
|
|
|
|
$conf = new configuration;
|
|
|
|
$options['expire']['default'] = '5min';
|
|
|
|
$this->assertEquals($options, $conf->get(), 'not overriding "missing" subkeys');
|
2015-10-22 14:51:01 -04:00
|
|
|
}
|
2015-10-24 02:44:17 -04:00
|
|
|
|
2015-10-22 14:51:01 -04:00
|
|
|
}
|