server/tests/lib/InstallerTest.php

100 lines
2.2 KiB
PHP
Raw Normal View History

2014-06-04 14:29:41 +00:00
<?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.
*/
2016-04-28 13:15:34 +00:00
namespace Test;
use OC\Installer;
class InstallerTest extends TestCase {
2014-06-04 14:29:41 +00:00
private static $appid = 'testapp';
2014-06-05 14:32:12 +00:00
private $appstore;
protected function setUp() {
parent::setUp();
$config = \OC::$server->getConfig();
$this->appstore = $config->setSystemValue('appstoreenabled', true);
$config->setSystemValue('appstoreenabled', true);
2016-04-28 13:15:34 +00:00
Installer::removeApp(self::$appid);
2014-06-05 14:32:12 +00:00
}
protected function tearDown() {
2016-04-28 13:15:34 +00:00
Installer::removeApp(self::$appid);
\OC::$server->getConfig()->setSystemValue('appstoreenabled', $this->appstore);
parent::tearDown();
2014-06-05 14:32:12 +00:00
}
2014-06-04 14:29:41 +00:00
public function testInstallApp() {
$pathOfTestApp = __DIR__;
$pathOfTestApp .= '/../data/';
$pathOfTestApp .= 'testapp.zip';
2015-12-18 10:25:33 +00:00
$tmp = \OC::$server->getTempManager()->getTemporaryFile('.zip');
2016-04-28 13:15:34 +00:00
\OC_Helper::copyr($pathOfTestApp, $tmp);
2014-06-04 14:29:41 +00:00
$data = array(
'path' => $tmp,
'source' => 'path',
'appdata' => [
'id' => 'Bar',
'level' => 100,
]
2014-06-04 14:29:41 +00:00
);
2016-04-28 13:15:34 +00:00
Installer::installApp($data);
$isInstalled = Installer::isInstalled(self::$appid);
2014-06-04 14:29:41 +00:00
$this->assertTrue($isInstalled);
}
public function testUpdateApp() {
$pathOfOldTestApp = __DIR__;
$pathOfOldTestApp .= '/../data/';
$pathOfOldTestApp .= 'testapp.zip';
2015-12-18 10:25:33 +00:00
$oldTmp = \OC::$server->getTempManager()->getTemporaryFile('.zip');
2016-04-28 13:15:34 +00:00
\OC_Helper::copyr($pathOfOldTestApp, $oldTmp);
2014-06-04 14:29:41 +00:00
$oldData = array(
'path' => $oldTmp,
'source' => 'path',
'appdata' => [
'id' => 'Bar',
'level' => 100,
]
2014-06-04 14:29:41 +00:00
);
$pathOfNewTestApp = __DIR__;
$pathOfNewTestApp .= '/../data/';
$pathOfNewTestApp .= 'testapp2.zip';
2015-12-18 10:25:33 +00:00
$newTmp = \OC::$server->getTempManager()->getTemporaryFile('.zip');
2016-04-28 13:15:34 +00:00
\OC_Helper::copyr($pathOfNewTestApp, $newTmp);
2014-06-04 14:29:41 +00:00
$newData = array(
'path' => $newTmp,
'source' => 'path',
'appdata' => [
'id' => 'Bar',
'level' => 100,
]
2014-06-04 14:29:41 +00:00
);
2016-04-28 13:15:34 +00:00
Installer::installApp($oldData);
$oldVersionNumber = \OC_App::getAppVersion(self::$appid);
2014-06-04 14:29:41 +00:00
2016-04-28 13:15:34 +00:00
Installer::updateApp($newData);
$newVersionNumber = \OC_App::getAppVersion(self::$appid);
2014-06-04 14:29:41 +00:00
$this->assertNotEquals($oldVersionNumber, $newVersionNumber);
}
}