Merge pull request #20902 from owncloud/drop-OC_Config-from-tests
Replace OC_Config in tests with IConfig calls
This commit is contained in:
commit
c6bda8d6ca
5 changed files with 45 additions and 35 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Reference in a new issue