summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorg Ehrke <developer@georgehrke.com>2014-06-04 16:29:41 +0200
committerGeorg Ehrke <developer@georgehrke.com>2014-06-04 16:29:41 +0200
commit724d027f199f77c6e1442c03dba4b3363f973412 (patch)
tree52e239f783193639789b6cf0604c1b17546ebb38
parent2c00ab13cf1dca45035e88ecad854997f78cf51c (diff)
downloadnextcloud-server-724d027f199f77c6e1442c03dba4b3363f973412.tar.gz
nextcloud-server-724d027f199f77c6e1442c03dba4b3363f973412.zip
add unit test
-rw-r--r--lib/private/installer.php41
-rw-r--r--settings/ajax/updateapp.php2
-rw-r--r--tests/data/testapp.zipbin0 -> 895 bytes
-rw-r--r--tests/data/testapp2.zipbin0 -> 2449 bytes
-rw-r--r--tests/lib/installer.php74
5 files changed, 100 insertions, 17 deletions
diff --git a/lib/private/installer.php b/lib/private/installer.php
index bbb8bc5a152..06677115c8e 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 5eb0a277cba..7010dfe23b5 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 00000000000..e76c0d18724
--- /dev/null
+++ b/tests/data/testapp.zip
Binary files differ
diff --git a/tests/data/testapp2.zip b/tests/data/testapp2.zip
new file mode 100644
index 00000000000..f46832f7a75
--- /dev/null
+++ b/tests/data/testapp2.zip
Binary files differ
diff --git a/tests/lib/installer.php b/tests/lib/installer.php
new file mode 100644
index 00000000000..97b14ef579a
--- /dev/null
+++ b/tests/lib/installer.php
@@ -0,0 +1,74 @@
+<?php
+/**
+ * Copyright (c) 2014 Georg Ehrke <georg@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);
+ }
+}