Set debugMode after reading the config file
This commit is contained in:
parent
194b61b4c5
commit
12976fb2e1
|
@ -49,12 +49,17 @@ class Config {
|
||||||
|
|
||||||
protected $debugMode;
|
protected $debugMode;
|
||||||
|
|
||||||
public function __construct($configDir, $debugMode) {
|
public function __construct($configDir) {
|
||||||
$this->configDir = $configDir;
|
$this->configDir = $configDir;
|
||||||
$this->debugMode = $debugMode;
|
|
||||||
$this->configFilename = $this->configDir.'config.php';
|
$this->configFilename = $this->configDir.'config.php';
|
||||||
$this->readData();
|
$this->readData();
|
||||||
|
$this->setDebugMode(defined('DEBUG') && DEBUG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setDebugMode($enable) {
|
||||||
|
$this->debugMode = $enable;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Lists all available config keys
|
* @brief Lists all available config keys
|
||||||
* @return array with key names
|
* @return array with key names
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
* This class is responsible for reading and writing config.php, the very basic
|
* This class is responsible for reading and writing config.php, the very basic
|
||||||
* configuration file of ownCloud.
|
* configuration file of ownCloud.
|
||||||
*/
|
*/
|
||||||
OC_Config::$object = new \OC\Config(OC::$SERVERROOT.'/config/', defined('DEBUG') && DEBUG);
|
OC_Config::$object = new \OC\Config(OC::$SERVERROOT.'/config/');
|
||||||
class OC_Config {
|
class OC_Config {
|
||||||
|
|
||||||
public static $object;
|
public static $object;
|
||||||
|
|
|
@ -11,38 +11,35 @@ class Test_Config extends PHPUnit_Framework_TestCase {
|
||||||
const CONFIG_DIR = 'static://';
|
const CONFIG_DIR = 'static://';
|
||||||
const TESTCONTENT = '<?php $CONFIG=array("foo"=>"bar");';
|
const TESTCONTENT = '<?php $CONFIG=array("foo"=>"bar");';
|
||||||
|
|
||||||
|
function setUp() {
|
||||||
|
file_put_contents(self::CONFIG_FILE, self::TESTCONTENT);
|
||||||
|
$this->config = new OC\Config(self::CONFIG_DIR);
|
||||||
|
}
|
||||||
|
|
||||||
public function testReadData()
|
public function testReadData()
|
||||||
{
|
{
|
||||||
$config = new OC\Config(self::CONFIG_DIR, false);
|
$config = new OC\Config('/non-existing');
|
||||||
$this->assertAttributeEquals(array(), 'cache', $config);
|
$this->assertAttributeEquals(array(), 'cache', $config);
|
||||||
|
|
||||||
file_put_contents(self::CONFIG_FILE, self::TESTCONTENT);
|
$this->assertAttributeEquals(array('foo'=>'bar'), 'cache', $this->config);
|
||||||
$config = new OC\Config(self::CONFIG_DIR, false);
|
|
||||||
$this->assertAttributeEquals(array('foo'=>'bar'), 'cache', $config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetKeys()
|
public function testGetKeys()
|
||||||
{
|
{
|
||||||
file_put_contents(self::CONFIG_FILE, self::TESTCONTENT);
|
$this->assertEquals(array('foo'), $this->config->getKeys());
|
||||||
$config = new OC\Config(self::CONFIG_DIR, false);
|
|
||||||
$this->assertEquals(array('foo'), $config->getKeys());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetValue()
|
public function testGetValue()
|
||||||
{
|
{
|
||||||
file_put_contents(self::CONFIG_FILE, self::TESTCONTENT);
|
$this->assertEquals('bar', $this->config->getValue('foo'));
|
||||||
$config = new OC\Config(self::CONFIG_DIR, false);
|
$this->assertEquals(null, $this->config->getValue('bar'));
|
||||||
$this->assertEquals('bar', $config->getValue('foo'));
|
$this->assertEquals('moo', $this->config->getValue('bar', 'moo'));
|
||||||
$this->assertEquals(null, $config->getValue('bar'));
|
|
||||||
$this->assertEquals('moo', $config->getValue('bar', 'moo'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetValue()
|
public function testSetValue()
|
||||||
{
|
{
|
||||||
file_put_contents(self::CONFIG_FILE, self::TESTCONTENT);
|
$this->config->setValue('foo', 'moo');
|
||||||
$config = new OC\Config(self::CONFIG_DIR, false);
|
$this->assertAttributeEquals(array('foo'=>'moo'), 'cache', $this->config);
|
||||||
$config->setValue('foo', 'moo');
|
|
||||||
$this->assertAttributeEquals(array('foo'=>'moo'), 'cache', $config);
|
|
||||||
$content = file_get_contents(self::CONFIG_FILE);
|
$content = file_get_contents(self::CONFIG_FILE);
|
||||||
$this->assertEquals(<<<EOL
|
$this->assertEquals(<<<EOL
|
||||||
<?php
|
<?php
|
||||||
|
@ -52,8 +49,8 @@ class Test_Config extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
EOL
|
EOL
|
||||||
, $content);
|
, $content);
|
||||||
$config->setValue('bar', 'red');
|
$this->config->setValue('bar', 'red');
|
||||||
$this->assertAttributeEquals(array('foo'=>'moo', 'bar'=>'red'), 'cache', $config);
|
$this->assertAttributeEquals(array('foo'=>'moo', 'bar'=>'red'), 'cache', $this->config);
|
||||||
$content = file_get_contents(self::CONFIG_FILE);
|
$content = file_get_contents(self::CONFIG_FILE);
|
||||||
$this->assertEquals(<<<EOL
|
$this->assertEquals(<<<EOL
|
||||||
<?php
|
<?php
|
||||||
|
@ -68,10 +65,8 @@ EOL
|
||||||
|
|
||||||
public function testDeleteKey()
|
public function testDeleteKey()
|
||||||
{
|
{
|
||||||
file_put_contents(self::CONFIG_FILE, self::TESTCONTENT);
|
$this->config->deleteKey('foo');
|
||||||
$config = new OC\Config(self::CONFIG_DIR, false);
|
$this->assertAttributeEquals(array(), 'cache', $this->config);
|
||||||
$config->deleteKey('foo');
|
|
||||||
$this->assertAttributeEquals(array(), 'cache', $config);
|
|
||||||
$content = file_get_contents(self::CONFIG_FILE);
|
$content = file_get_contents(self::CONFIG_FILE);
|
||||||
$this->assertEquals(<<<EOL
|
$this->assertEquals(<<<EOL
|
||||||
<?php
|
<?php
|
||||||
|
@ -84,11 +79,10 @@ EOL
|
||||||
|
|
||||||
public function testSavingDebugMode()
|
public function testSavingDebugMode()
|
||||||
{
|
{
|
||||||
file_put_contents(self::CONFIG_FILE, self::TESTCONTENT);
|
$this->config->setDebugMode(true);
|
||||||
$config = new OC\Config(self::CONFIG_DIR, true);
|
$this->config->deleteKey('foo'); // change something so we save to the config file
|
||||||
$config->deleteKey('foo'); // change something so we save to the config file
|
$this->assertAttributeEquals(array(), 'cache', $this->config);
|
||||||
$this->assertAttributeEquals(array(), 'cache', $config);
|
$this->assertAttributeEquals(true, 'debugMode', $this->config);
|
||||||
$this->assertAttributeEquals(true, 'debug_mode', $config);
|
|
||||||
$content = file_get_contents(self::CONFIG_FILE);
|
$content = file_get_contents(self::CONFIG_FILE);
|
||||||
$this->assertEquals(<<<EOL
|
$this->assertEquals(<<<EOL
|
||||||
<?php
|
<?php
|
||||||
|
@ -102,7 +96,7 @@ EOL
|
||||||
|
|
||||||
public function testWriteData()
|
public function testWriteData()
|
||||||
{
|
{
|
||||||
$config = new OC\Config('/non-writable', false);
|
$config = new OC\Config('/non-writable');
|
||||||
try {
|
try {
|
||||||
$config->setValue('foo', 'bar');
|
$config->setValue('foo', 'bar');
|
||||||
} catch (\OC\HintException $e) {
|
} catch (\OC\HintException $e) {
|
||||||
|
|
Loading…
Reference in New Issue