From d331e0d4f8a86c794c07478a64a66808f4fe359e Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Wed, 2 Dec 2015 16:11:38 +0100 Subject: [PATCH] Replace OC_Config in tests with IConfig calls --- tests/lib/helperstorage.php | 19 ++++++++++--------- tests/lib/installer.php | 7 ++++--- tests/lib/l10n.php | 6 ++++-- tests/lib/log/owncloud.php | 23 +++++++++++++---------- tests/lib/util.php | 25 ++++++++++++++----------- 5 files changed, 45 insertions(+), 35 deletions(-) diff --git a/tests/lib/helperstorage.php b/tests/lib/helperstorage.php index d41bc68a7b..cf022109c2 100644 --- a/tests/lib/helperstorage.php +++ b/tests/lib/helperstorage.php @@ -120,19 +120,19 @@ class Test_Helper_Storage extends \Test\TestCase { \OC\Files\Filesystem::mount($extStorage, array(), '/' . $this->user . '/files/ext'); - $oldConfig = \OC_Config::getValue('quota_include_external_storage', false); - \OC_Config::setValue('quota_include_external_storage', 'true'); - $config = \OC::$server->getConfig(); - $userQuota = $config->setUserValue($this->user, 'files', 'quota', '25'); + $oldConfig = $config->getSystemValue('quota_include_external_storage', false); + $config->setSystemValue('quota_include_external_storage', 'true'); + + $config->setUserValue($this->user, 'files', 'quota', '25'); $storageInfo = \OC_Helper::getStorageInfo(''); $this->assertEquals(3, $storageInfo['free']); $this->assertEquals(22, $storageInfo['used']); $this->assertEquals(25, $storageInfo['total']); - \OC_Config::setValue('quota_include_external_storage', $oldConfig); - $userQuota = $config->setUserValue($this->user, 'files', 'quota', 'default'); + $config->setSystemValue('quota_include_external_storage', $oldConfig); + $config->setUserValue($this->user, 'files', 'quota', 'default'); } /** @@ -151,15 +151,16 @@ class Test_Helper_Storage extends \Test\TestCase { \OC\Files\Filesystem::mount($extStorage, array(), '/' . $this->user . '/files/ext'); - $oldConfig = \OC_Config::getValue('quota_include_external_storage', false); - \OC_Config::setValue('quota_include_external_storage', 'true'); + $config = \OC::$server->getConfig(); + $oldConfig = $config->getSystemValue('quota_include_external_storage', false); + $config->setSystemValue('quota_include_external_storage', 'true'); $storageInfo = \OC_Helper::getStorageInfo(''); $this->assertEquals(12, $storageInfo['free']); $this->assertEquals(5, $storageInfo['used']); $this->assertEquals(17, $storageInfo['total']); - \OC_Config::setValue('quota_include_external_storage', $oldConfig); + $config->setSystemValue('quota_include_external_storage', $oldConfig); } diff --git a/tests/lib/installer.php b/tests/lib/installer.php index b58a71b5a0..c3c2f8a275 100644 --- a/tests/lib/installer.php +++ b/tests/lib/installer.php @@ -14,14 +14,15 @@ class Test_Installer extends \Test\TestCase { protected function setUp() { parent::setUp(); - $this->appstore = OC_Config::getValue('appstoreenabled', true); - OC_Config::setValue('appstoreenabled', true); + $config = \OC::$server->getConfig(); + $this->appstore = $config->setSystemValue('appstoreenabled', true); + $config->setSystemValue('appstoreenabled', true); OC_Installer::removeApp(self::$appid); } protected function tearDown() { OC_Installer::removeApp(self::$appid); - OC_Config::setValue('appstoreenabled', $this->appstore); + \OC::$server->getConfig()->setSystemValue('appstoreenabled', $this->appstore); parent::tearDown(); } diff --git a/tests/lib/l10n.php b/tests/lib/l10n.php index cb2f4179c4..631432caea 100644 --- a/tests/lib/l10n.php +++ b/tests/lib/l10n.php @@ -118,10 +118,12 @@ class Test_L10n extends \Test\TestCase { */ public function testFindLanguage($default, $preference, $expected) { OC_User::setUserId(null); + + $config = \OC::$server->getConfig(); if (is_null($default)) { - OC_Config::deleteKey('default_language'); + $config->deleteSystemValue('default_language'); } else { - OC_Config::setValue('default_language', $default); + $config->setSystemValue('default_language', $default); } $_SERVER['HTTP_ACCEPT_LANGUAGE'] = $preference; diff --git a/tests/lib/log/owncloud.php b/tests/lib/log/owncloud.php index 8cc6aa9d57..adecc49768 100644 --- a/tests/lib/log/owncloud.php +++ b/tests/lib/log/owncloud.php @@ -27,37 +27,40 @@ class Test_Log_Owncloud extends Test\TestCase protected function setUp() { parent::setUp(); - $this->restore_logfile = OC_Config::getValue("logfile"); - $this->restore_logdateformat = OC_Config::getValue('logdateformat'); + $config = \OC::$server->getConfig(); + $this->restore_logfile = $config->getSystemValue("logfile"); + $this->restore_logdateformat = $config->getSystemValue('logdateformat'); - OC_Config::setValue("logfile", OC_Config::getValue('datadirectory') . "/logtest"); + $config->setSystemValue("logfile", $config->getSystemValue('datadirectory') . "/logtest"); OC_Log_Owncloud::init(); } protected function tearDown() { + $config = \OC::$server->getConfig(); if (isset($this->restore_logfile)) { - OC_Config::setValue("logfile", $this->restore_logfile); + $config->getSystemValue("logfile", $this->restore_logfile); } else { - OC_Config::deleteKey("logfile"); + $config->deleteSystemValue("logfile"); } if (isset($this->restore_logdateformat)) { - OC_Config::setValue("logdateformat", $this->restore_logdateformat); + $config->getSystemValue("logdateformat", $this->restore_logdateformat); } else { - OC_Config::deleteKey("restore_logdateformat"); + $config->deleteSystemValue("restore_logdateformat"); } OC_Log_Owncloud::init(); parent::tearDown(); } public function testMicrosecondsLogTimestamp() { + $config = \OC::$server->getConfig(); # delete old logfile - unlink(OC_Config::getValue('logfile')); + unlink($config->getSystemValue('logfile')); # set format & write log line - OC_Config::setValue('logdateformat', 'u'); + $config->setSystemValue('logdateformat', 'u'); OC_Log_Owncloud::write('test', 'message', \OCP\Util::ERROR); # read log line - $handle = @fopen(OC_Config::getValue('logfile'), 'r'); + $handle = @fopen($config->getSystemValue('logfile'), 'r'); $line = fread($handle, 1000); fclose($handle); diff --git a/tests/lib/util.php b/tests/lib/util.php index 032ede74a8..a6ec06aa41 100644 --- a/tests/lib/util.php +++ b/tests/lib/util.php @@ -143,23 +143,25 @@ class Test_Util extends \Test\TestCase { } function testGetDefaultEmailAddressFromConfig() { - OC_Config::setValue('mail_domain', 'example.com'); + $config = \OC::$server->getConfig(); + $config->setSystemValue('mail_domain', 'example.com'); $email = \OCP\Util::getDefaultEmailAddress("no-reply"); $this->assertEquals('no-reply@example.com', $email); - OC_Config::deleteKey('mail_domain'); + $config->deleteSystemValue('mail_domain'); } function testGetConfiguredEmailAddressFromConfig() { - OC_Config::setValue('mail_domain', 'example.com'); - OC_Config::setValue('mail_from_address', 'owncloud'); + $config = \OC::$server->getConfig(); + $config->setSystemValue('mail_domain', 'example.com'); + $config->setSystemValue('mail_from_address', 'owncloud'); $email = \OCP\Util::getDefaultEmailAddress("no-reply"); $this->assertEquals('owncloud@example.com', $email); - OC_Config::deleteKey('mail_domain'); - OC_Config::deleteKey('mail_from_address'); + $config->deleteSystemValue('mail_domain'); + $config->deleteSystemValue('mail_from_address'); } function testGetInstanceIdGeneratesValidId() { - OC_Config::deleteKey('instanceid'); + \OC::$server->getConfig()->deleteSystemValue('instanceid'); $instanceId = OC_Util::getInstanceId(); $this->assertStringStartsWith('oc', $instanceId); $matchesRegex = preg_match('/^[a-z0-9]+$/', $instanceId); @@ -362,19 +364,20 @@ class Test_Util extends \Test\TestCase { * Test needUpgrade() when the core version is increased */ public function testNeedUpgradeCore() { - $oldConfigVersion = OC_Config::getValue('version', '0.0.0'); + $config = \OC::$server->getConfig(); + $oldConfigVersion = $config->getSystemValue('version', '0.0.0'); $oldSessionVersion = \OC::$server->getSession()->get('OC_Version'); $this->assertFalse(\OCP\Util::needUpgrade()); - OC_Config::setValue('version', '7.0.0.0'); + $config->setSystemValue('version', '7.0.0.0'); \OC::$server->getSession()->set('OC_Version', array(7, 0, 0, 1)); self::invokePrivate(new \OCP\Util, 'needUpgradeCache', array(null)); $this->assertTrue(\OCP\Util::needUpgrade()); - OC_Config::setValue('version', $oldConfigVersion); - $oldSessionVersion = \OC::$server->getSession()->set('OC_Version', $oldSessionVersion); + $config->setSystemValue('version', $oldConfigVersion); + \OC::$server->getSession()->set('OC_Version', $oldSessionVersion); self::invokePrivate(new \OCP\Util, 'needUpgradeCache', array(null)); $this->assertFalse(\OCP\Util::needUpgrade());