[Pkg-owncloud-commits] [owncloud] 178/258: Inject config into checkserver and cleanup tests

David Prévot taffit at moszumanska.debian.org
Sat Oct 11 17:22:34 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository owncloud.

commit 2376d6911534127431cac5ce7600d2327804440d
Author: Robin Appelman <icewind at owncloud.com>
Date:   Mon Sep 8 14:56:11 2014 +0200

    Inject config into checkserver and cleanup tests
    
    Conflicts:
    	lib/private/util.php
---
 lib/base.php                  |  2 +-
 lib/private/util.php          | 21 +++++++++--------
 lib/public/util.php           |  2 +-
 tests/lib/utilcheckserver.php | 54 ++++++++++++++++++++++++++++---------------
 4 files changed, 49 insertions(+), 30 deletions(-)

diff --git a/lib/base.php b/lib/base.php
index 3ce5a21..7335be0 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -516,7 +516,7 @@ class OC {
 		self::checkSSL();
 		OC_Response::addSecurityHeaders();
 
-		$errors = OC_Util::checkServer();
+		$errors = OC_Util::checkServer(\OC::$server->getConfig());
 		if (count($errors) > 0) {
 			if (self::$CLI) {
 				foreach ($errors as $error) {
diff --git a/lib/private/util.php b/lib/private/util.php
index ceb55bb..4c17c76 100755
--- a/lib/private/util.php
+++ b/lib/private/util.php
@@ -389,14 +389,16 @@ class OC_Util {
 
 	/**
 	 * check if the current server configuration is suitable for ownCloud
+	 *
+	 * @param \OCP\IConfig $config
 	 * @return array arrays with error messages and hints
 	 */
-	public static function checkServer() {
-		$l = OC_L10N::get('lib');
+	public static function checkServer($config) {
+		$l = \OC::$server->getL10N('lib');
 		$errors = array();
-		$CONFIG_DATADIRECTORY = OC_Config::getValue('datadirectory', OC::$SERVERROOT . '/data');
+		$CONFIG_DATADIRECTORY = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data');
 
-		if (!self::needUpgrade() && OC_Config::getValue('installed', false)) {
+		if (!self::needUpgrade($config) && $config->getSystemValue('installed', false)) {
 			// this check needs to be done every time
 			$errors = self::checkDataDirectoryValidity($CONFIG_DATADIRECTORY);
 		}
@@ -435,8 +437,8 @@ class OC_Util {
 		}
 
 		// Check if there is a writable install folder.
-		if(OC_Config::getValue('appstoreenabled', true)) {
-			if( OC_App::getInstallPath() === null
+		if ($config->getSystemValue('appstoreenabled', true)) {
+			if (OC_App::getInstallPath() === null
 				|| !is_writable(OC_App::getInstallPath())
 				|| !is_readable(OC_App::getInstallPath()) ) {
 				$errors[] = array(
@@ -1332,11 +1334,12 @@ class OC_Util {
 	 * either when the core version is higher or any app requires
 	 * an upgrade.
 	 *
+	 * @param \OCP\IConfig $config
 	 * @return bool whether the core or any app needs an upgrade
 	 */
-	public static function needUpgrade() {
-		if (OC_Config::getValue('installed', false)) {
-			$installedVersion = OC_Config::getValue('version', '0.0.0');
+	public static function needUpgrade($config) {
+		if ($config->getSystemValue('installed', false)) {
+			$installedVersion = $config->getSystemValue('version', '0.0.0');
 			$currentVersion = implode('.', OC_Util::getVersion());
 			if (version_compare($currentVersion, $installedVersion, '>')) {
 				return true;
diff --git a/lib/public/util.php b/lib/public/util.php
index 2a6e977..bcbf7ca 100644
--- a/lib/public/util.php
+++ b/lib/public/util.php
@@ -532,6 +532,6 @@ class Util {
 	 * @return bool true if upgrade is needed, false otherwise
 	 */
 	public static function needUpgrade() {
-		return \OC_Util::needUpgrade();
+		return \OC_Util::needUpgrade(\OC::$server->getConfig());
 	}
 }
diff --git a/tests/lib/utilcheckserver.php b/tests/lib/utilcheckserver.php
index 155d617..78888bd 100644
--- a/tests/lib/utilcheckserver.php
+++ b/tests/lib/utilcheckserver.php
@@ -13,8 +13,26 @@ class Test_Util_CheckServer extends PHPUnit_Framework_TestCase {
 
 	private $datadir;
 
+	/**
+	 * @param array $systemOptions
+	 * @return \OCP\IConfig | PHPUnit_Framework_MockObject_MockObject
+	 */
+	protected function getConfig($systemOptions) {
+		$systemOptions['datadirectory'] = $this->datadir;
+		$config = $this->getMockBuilder('\OCP\IConfig')
+			->disableOriginalConstructor()
+			->getMock();
+
+		$config->expects($this->any())
+			->method('getSystemValue')
+			->will($this->returnCallback(function ($key, $default) use ($systemOptions) {
+				return isset($systemOptions[$key]) ? $systemOptions[$key] : $default;
+			}));
+		return $config;
+	}
+
 	public function setUp() {
-		$this->datadir = \OC_Config::getValue('datadirectory', \OC::$SERVERROOT . '/data');
+		$this->datadir = \OC_Helper::tmpFolder();
 
 		file_put_contents($this->datadir . '/.ocdata', '');
 	}
@@ -28,7 +46,9 @@ class Test_Util_CheckServer extends PHPUnit_Framework_TestCase {
 	 * Test that checkServer() returns no errors in the regular case.
 	 */
 	public function testCheckServer() {
-		$result = \OC_Util::checkServer();
+		$result = \OC_Util::checkServer($this->getConfig(array(
+			'installed' => true
+		)));
 		$this->assertEmpty($result);
 	}
 
@@ -41,19 +61,12 @@ class Test_Util_CheckServer extends PHPUnit_Framework_TestCase {
 		// simulate old version that didn't have it
 		unlink($this->datadir . '/.ocdata');
 
-		$session = \OC::$server->getSession();
-		$oldInstalled = \OC_Config::getValue('installed', false);
-
-		// simulate that the server isn't setup yet
-		\OC_Config::setValue('installed', false);
-
 		// even though ".ocdata" is missing, the error isn't
 		// triggered to allow setup to run
-		$result = \OC_Util::checkServer();
+		$result = \OC_Util::checkServer($this->getConfig(array(
+			'installed' => false
+		)));
 		$this->assertEmpty($result);
-
-		// restore config
-		\OC_Config::setValue('installed', $oldInstalled);
 	}
 
 	/**
@@ -67,20 +80,20 @@ class Test_Util_CheckServer extends PHPUnit_Framework_TestCase {
 
 		$session = \OC::$server->getSession();
 		$oldCurrentVersion = $session->get('OC_Version');
-		$oldInstallVersion = \OC_Config::getValue('version', '0.0.0');
 
 		// upgrade condition to simulate needUpgrade() === true
 		$session->set('OC_Version', array(6, 0, 0, 2));
-		\OC_Config::setValue('version', '6.0.0.1');
 
 		// even though ".ocdata" is missing, the error isn't
 		// triggered to allow for upgrade
-		$result = \OC_Util::checkServer();
+		$result = \OC_Util::checkServer($this->getConfig(array(
+			'installed' => true,
+			'version' => '6.0.0.1'
+		)));
 		$this->assertEmpty($result);
 
 		// restore versions
 		$session->set('OC_Version', $oldCurrentVersion);
-		\OC_Config::setValue('version', $oldInstallVersion);
 	}
 
 	/**
@@ -93,7 +106,7 @@ class Test_Util_CheckServer extends PHPUnit_Framework_TestCase {
 	}
 
 	/**
-	 * Test that checkDataDirectoryValidity and checkServer 
+	 * Test that checkDataDirectoryValidity and checkServer
 	 * both return an error when ".ocdata" is missing.
 	 */
 	public function testCheckDataDirValidityWhenFileMissing() {
@@ -101,8 +114,11 @@ class Test_Util_CheckServer extends PHPUnit_Framework_TestCase {
 		$result = \OC_Util::checkDataDirectoryValidity($this->datadir);
 		$this->assertEquals(1, count($result));
 
-		$result = \OC_Util::checkServer();
-		$this->assertEquals(1, count($result));
+		$result = \OC_Util::checkServer($this->getConfig(array(
+			'installed' => true,
+			'version' => implode('.', OC_Util::getVersion())
+		)));
+		$this->assertCount(1, $result);
 	}
 
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list