From 12976fb2e1f6a4d6a054ba2b620f0e7707ce2c69 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Thu, 27 Jun 2013 22:50:28 +0200 Subject: [PATCH] Set debugMode after reading the config file --- lib/config.php | 9 ++++++-- lib/legacy/config.php | 2 +- tests/lib/config.php | 50 +++++++++++++++++++------------------------ 3 files changed, 30 insertions(+), 31 deletions(-) diff --git a/lib/config.php b/lib/config.php index adf70ac841..afd74c56b4 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 635f0af66f..f68d7c31b2 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 e22bf3fd7d..8f52cf4ae7 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 = '"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(<<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(<<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(<<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(<<setValue('foo', 'bar'); } catch (\OC\HintException $e) {