aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBart Visscher <bartv@thisnet.nl>2013-06-27 22:50:28 +0200
committerBart Visscher <bartv@thisnet.nl>2013-06-27 22:50:28 +0200
commit12976fb2e1f6a4d6a054ba2b620f0e7707ce2c69 (patch)
treeab91be2d3550701b55a299e4f0867512f6b7ee63
parent194b61b4c507e58eab0750ab40ed6eb6f085c06a (diff)
downloadnextcloud-server-12976fb2e1f6a4d6a054ba2b620f0e7707ce2c69.tar.gz
nextcloud-server-12976fb2e1f6a4d6a054ba2b620f0e7707ce2c69.zip
Set debugMode after reading the config file
-rw-r--r--lib/config.php9
-rw-r--r--lib/legacy/config.php2
-rw-r--r--tests/lib/config.php50
3 files changed, 30 insertions, 31 deletions
diff --git a/lib/config.php b/lib/config.php
index adf70ac841a..afd74c56b40 100644
--- a/lib/config.php
+++ b/lib/config.php
@@ -49,12 +49,17 @@ class Config {
protected $debugMode;
- public function __construct($configDir, $debugMode) {
+ public function __construct($configDir) {
$this->configDir = $configDir;
- $this->debugMode = $debugMode;
$this->configFilename = $this->configDir.'config.php';
$this->readData();
+ $this->setDebugMode(defined('DEBUG') && DEBUG);
}
+
+ public function setDebugMode($enable) {
+ $this->debugMode = $enable;
+ }
+
/**
* @brief Lists all available config keys
* @return array with key names
diff --git a/lib/legacy/config.php b/lib/legacy/config.php
index 635f0af66f8..f68d7c31b25 100644
--- a/lib/legacy/config.php
+++ b/lib/legacy/config.php
@@ -38,7 +38,7 @@
* This class is responsible for reading and writing config.php, the very basic
* 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 {
public static $object;
diff --git a/tests/lib/config.php b/tests/lib/config.php
index e22bf3fd7de..8f52cf4ae76 100644
--- a/tests/lib/config.php
+++ b/tests/lib/config.php
@@ -11,38 +11,35 @@ class Test_Config extends PHPUnit_Framework_TestCase {
const CONFIG_DIR = 'static://';
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()
{
- $config = new OC\Config(self::CONFIG_DIR, false);
+ $config = new OC\Config('/non-existing');
$this->assertAttributeEquals(array(), 'cache', $config);
- file_put_contents(self::CONFIG_FILE, self::TESTCONTENT);
- $config = new OC\Config(self::CONFIG_DIR, false);
- $this->assertAttributeEquals(array('foo'=>'bar'), 'cache', $config);
+ $this->assertAttributeEquals(array('foo'=>'bar'), 'cache', $this->config);
}
public function testGetKeys()
{
- file_put_contents(self::CONFIG_FILE, self::TESTCONTENT);
- $config = new OC\Config(self::CONFIG_DIR, false);
- $this->assertEquals(array('foo'), $config->getKeys());
+ $this->assertEquals(array('foo'), $this->config->getKeys());
}
public function testGetValue()
{
- file_put_contents(self::CONFIG_FILE, self::TESTCONTENT);
- $config = new OC\Config(self::CONFIG_DIR, false);
- $this->assertEquals('bar', $config->getValue('foo'));
- $this->assertEquals(null, $config->getValue('bar'));
- $this->assertEquals('moo', $config->getValue('bar', 'moo'));
+ $this->assertEquals('bar', $this->config->getValue('foo'));
+ $this->assertEquals(null, $this->config->getValue('bar'));
+ $this->assertEquals('moo', $this->config->getValue('bar', 'moo'));
}
public function testSetValue()
{
- file_put_contents(self::CONFIG_FILE, self::TESTCONTENT);
- $config = new OC\Config(self::CONFIG_DIR, false);
- $config->setValue('foo', 'moo');
- $this->assertAttributeEquals(array('foo'=>'moo'), 'cache', $config);
+ $this->config->setValue('foo', 'moo');
+ $this->assertAttributeEquals(array('foo'=>'moo'), 'cache', $this->config);
$content = file_get_contents(self::CONFIG_FILE);
$this->assertEquals(<<<EOL
<?php
@@ -52,8 +49,8 @@ class Test_Config extends PHPUnit_Framework_TestCase {
EOL
, $content);
- $config->setValue('bar', 'red');
- $this->assertAttributeEquals(array('foo'=>'moo', 'bar'=>'red'), 'cache', $config);
+ $this->config->setValue('bar', 'red');
+ $this->assertAttributeEquals(array('foo'=>'moo', 'bar'=>'red'), 'cache', $this->config);
$content = file_get_contents(self::CONFIG_FILE);
$this->assertEquals(<<<EOL
<?php
@@ -68,10 +65,8 @@ EOL
public function testDeleteKey()
{
- file_put_contents(self::CONFIG_FILE, self::TESTCONTENT);
- $config = new OC\Config(self::CONFIG_DIR, false);
- $config->deleteKey('foo');
- $this->assertAttributeEquals(array(), 'cache', $config);
+ $this->config->deleteKey('foo');
+ $this->assertAttributeEquals(array(), 'cache', $this->config);
$content = file_get_contents(self::CONFIG_FILE);
$this->assertEquals(<<<EOL
<?php
@@ -84,11 +79,10 @@ EOL
public function testSavingDebugMode()
{
- file_put_contents(self::CONFIG_FILE, self::TESTCONTENT);
- $config = new OC\Config(self::CONFIG_DIR, true);
- $config->deleteKey('foo'); // change something so we save to the config file
- $this->assertAttributeEquals(array(), 'cache', $config);
- $this->assertAttributeEquals(true, 'debug_mode', $config);
+ $this->config->setDebugMode(true);
+ $this->config->deleteKey('foo'); // change something so we save to the config file
+ $this->assertAttributeEquals(array(), 'cache', $this->config);
+ $this->assertAttributeEquals(true, 'debugMode', $this->config);
$content = file_get_contents(self::CONFIG_FILE);
$this->assertEquals(<<<EOL
<?php
@@ -102,7 +96,7 @@ EOL
public function testWriteData()
{
- $config = new OC\Config('/non-writable', false);
+ $config = new OC\Config('/non-writable');
try {
$config->setValue('foo', 'bar');
} catch (\OC\HintException $e) {