add unit test
This commit is contained in:
parent
2c00ab13cf
commit
724d027f19
|
@ -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"));
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue