From 240d1ae6b9aa506de4c21e93258a17b23052ac5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Mon, 7 Apr 2014 20:56:43 +0200 Subject: [PATCH 1/3] unit test testSetAppValueIfSetToNull() added --- tests/lib/public/config.php | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests/lib/public/config.php diff --git a/tests/lib/public/config.php b/tests/lib/public/config.php new file mode 100644 index 00000000000..68367034e9a --- /dev/null +++ b/tests/lib/public/config.php @@ -0,0 +1,37 @@ +. + */ + +class Test_Config extends PHPUnit_Framework_TestCase +{ + + public function testSetAppValueIfSetToNull() { + + $key = uniqid("key-"); + + $result = \OCP\Config::setAppValue('unit-test', $key, null); + $this->assertTrue($result); + + $result = \OCP\Config::setAppValue('unit-test', $key, '12'); + $this->assertTrue($result); + + } + +} From 85e7921b149cf555e5c5f81837da5cd68696014a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Mon, 7 Apr 2014 20:57:08 +0200 Subject: [PATCH 2/3] fixing undefined exception classes --- lib/public/config.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/public/config.php b/lib/public/config.php index bb973939f44..8e3791b449b 100644 --- a/lib/public/config.php +++ b/lib/public/config.php @@ -64,7 +64,7 @@ class Config { public static function setSystemValue( $key, $value ) { try { \OC_Config::setValue( $key, $value ); - } catch (Exception $e) { + } catch (\Exception $e) { return false; } return true; @@ -96,7 +96,7 @@ class Config { public static function setAppValue( $app, $key, $value ) { try { \OC_Appconfig::setValue( $app, $key, $value ); - } catch (Exception $e) { + } catch (\Exception $e) { return false; } return true; @@ -131,7 +131,7 @@ class Config { public static function setUserValue( $user, $app, $key, $value ) { try { \OC_Preferences::setValue( $user, $app, $key, $value ); - } catch (Exception $e) { + } catch (\Exception $e) { return false; } return true; From c1fd3000484972b9eaca22831ca4cc441bde5cf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Mon, 7 Apr 2014 21:05:48 +0200 Subject: [PATCH 3/3] using array_key_exists() instead of isset() - required because in case the value is null isset is returning false --- lib/private/appconfig.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/appconfig.php b/lib/private/appconfig.php index cfb84309c67..fed6989a438 100644 --- a/lib/private/appconfig.php +++ b/lib/private/appconfig.php @@ -147,7 +147,7 @@ class AppConfig implements \OCP\IAppConfig { */ public function hasKey($app, $key) { $values = $this->getAppValues($app); - return isset($values[$key]); + return array_key_exists($key, $values); } /**