[Pkg-owncloud-commits] [owncloud] 10/223: add unit test

David Prévot taffit at moszumanska.debian.org
Sun Jun 22 01:53:58 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 724d027f199f77c6e1442c03dba4b3363f973412
Author: Georg Ehrke <developer at georgehrke.com>
Date:   Wed Jun 4 16:29:41 2014 +0200

    add unit test
---
 lib/private/installer.php   |  41 ++++++++++++++----------
 settings/ajax/updateapp.php |   2 +-
 tests/data/testapp.zip      | Bin 0 -> 895 bytes
 tests/data/testapp2.zip     | Bin 0 -> 2449 bytes
 tests/lib/installer.php     |  74 ++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 100 insertions(+), 17 deletions(-)

diff --git a/lib/private/installer.php b/lib/private/installer.php
index bbb8bc5..0667711 100644
--- a/lib/private/installer.php
+++ b/lib/private/installer.php
@@ -164,21 +164,7 @@ class OC_Installer{
 	 * upgrade.php can determine the current installed version of the app using
 	 * "OC_Appconfig::getValue($appid, 'installed_version')"
 	 */
-	public static function updateApp( $app ) {
-		$appdata = OC_OCSClient::getApplication($app);
-		$download = OC_OCSClient::getApplicationDownload($app, 1);
-
-		if (isset($download['downloadlink']) && trim($download['downloadlink']) !== '') {
-			$download['downloadlink'] = str_replace(' ', '%20', $download['downloadlink']);
-			$info = array(
-				'source' => 'http',
-				'href' => $download['downloadlink'],
-				'appdata' => $appdata
-			);
-		} else {
-			throw new \Exception('Could not fetch app info!');
-		}
-
+	public static function updateApp( $info=array() ) {
 		list($extractDir, $path) = self::downloadApp($info);
 		$info = self::checkAppsIntegrity($info, $extractDir, $path);
 
@@ -206,6 +192,29 @@ class OC_Installer{
 		return OC_App::updateApp($info['id']);
 	}
 
+	/**
+	 * update an app by it's id
+	 * @param integer $ocsid
+	 * @return bool
+	 * @throws Exception
+	 */
+	public static function updateAppByOCSId($ocsid) {
+		$appdata = OC_OCSClient::getApplication($ocsid);
+		$download = OC_OCSClient::getApplicationDownload($ocsid, 1);
+
+		if (isset($download['downloadlink']) && trim($download['downloadlink']) !== '') {
+			$download['downloadlink'] = str_replace(' ', '%20', $download['downloadlink']);
+			$info = array(
+				'source' => 'http',
+				'href' => $download['downloadlink'],
+				'appdata' => $appdata
+			);
+		} else {
+			throw new \Exception('Could not fetch app info!');
+		}
+
+		return self::updateApp($info);
+	}
 
 	/**
 	 * @param array $data
@@ -322,7 +331,7 @@ class OC_Installer{
 			$version = trim($info['version']);
 		}
 
-		if($version<>trim($data['appdata']['version'])) {
+		if(isset($data['appdata']['version']) && $version<>trim($data['appdata']['version'])) {
 			OC_Helper::rmdirr($extractDir);
 			throw new \Exception($l->t("App can't be installed because the version in info.xml/version is not the same as the version reported from the app store"));
 		}
diff --git a/settings/ajax/updateapp.php b/settings/ajax/updateapp.php
index 5eb0a27..7010dfe 100644
--- a/settings/ajax/updateapp.php
+++ b/settings/ajax/updateapp.php
@@ -30,7 +30,7 @@ if (!is_numeric($appId)) {
 
 $appId = OC_App::cleanAppId($appId);
 
-$result = OC_Installer::updateApp($appId);
+$result = OC_Installer::updateAppByOCSId($appId);
 if($result !== false) {
 	OC_JSON::success(array('data' => array('appid' => $appId)));
 } else {
diff --git a/tests/data/testapp.zip b/tests/data/testapp.zip
new file mode 100644
index 0000000..e76c0d1
Binary files /dev/null and b/tests/data/testapp.zip differ
diff --git a/tests/data/testapp2.zip b/tests/data/testapp2.zip
new file mode 100644
index 0000000..f46832f
Binary files /dev/null and b/tests/data/testapp2.zip differ
diff --git a/tests/lib/installer.php b/tests/lib/installer.php
new file mode 100644
index 0000000..97b14ef
--- /dev/null
+++ b/tests/lib/installer.php
@@ -0,0 +1,74 @@
+<?php
+/**
+ * Copyright (c) 2014 Georg Ehrke <georg at owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+class Test_Installer extends PHPUnit_Framework_TestCase {
+
+	private static $appid = 'testapp';
+
+	public function testInstallApp() {
+		$pathOfTestApp  = __DIR__;
+		$pathOfTestApp .= '/../data/';
+		$pathOfTestApp .= 'testapp.zip';
+
+		$tmp = OC_Helper::tmpFile();
+		OC_Helper::copyr($pathOfTestApp, $tmp);
+
+		$data = array(
+			'path' => $tmp,
+			'source' => 'path',
+		);
+
+		OC_Installer::installApp($data);
+		$isInstalled = OC_Installer::isInstalled(self::$appid);
+
+		$this->assertTrue($isInstalled);
+
+		//clean-up
+		OC_Installer::removeApp(self::$appid);
+		unlink($tmp);
+	}
+
+	public function testUpdateApp() {
+		$pathOfOldTestApp  = __DIR__;
+		$pathOfOldTestApp .= '/../data/';
+		$pathOfOldTestApp .= 'testapp.zip';
+
+		$oldTmp = OC_Helper::tmpFile();
+		OC_Helper::copyr($pathOfOldTestApp, $oldTmp);
+
+		$oldData = array(
+			'path' => $oldTmp,
+			'source' => 'path',
+		);
+
+		$pathOfNewTestApp  = __DIR__;
+		$pathOfNewTestApp .= '/../data/';
+		$pathOfNewTestApp .= 'testapp2.zip';
+
+		$newTmp = OC_Helper::tmpFile();
+		OC_Helper::copyr($pathOfNewTestApp, $newTmp);
+
+		$newData = array(
+			'path' => $newTmp,
+			'source' => 'path',
+		);
+
+		OC_Installer::installApp($oldData);
+		$oldVersionNumber = OC_App::getAppVersion(self::$appid);
+
+		OC_Installer::updateApp($newData);
+		$newVersionNumber = OC_App::getAppVersion(self::$appid);
+
+		$this->assertNotEquals($oldVersionNumber, $newVersionNumber);
+
+		//clean-up
+		OC_Installer::removeApp(self::$appid);
+		unlink($oldTmp);
+		unlink($newTmp);
+	}
+}

-- 
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