aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/InstallerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/InstallerTest.php')
-rw-r--r--tests/lib/InstallerTest.php135
1 files changed, 73 insertions, 62 deletions
diff --git a/tests/lib/InstallerTest.php b/tests/lib/InstallerTest.php
index 352580337ad..06163cdaedb 100644
--- a/tests/lib/InstallerTest.php
+++ b/tests/lib/InstallerTest.php
@@ -1,9 +1,9 @@
<?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.
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test;
@@ -11,10 +11,12 @@ namespace Test;
use OC\App\AppStore\Fetcher\AppFetcher;
use OC\Archive\ZIP;
use OC\Installer;
+use OCP\App\IAppManager;
use OCP\Http\Client\IClient;
use OCP\Http\Client\IClientService;
use OCP\IConfig;
use OCP\ITempManager;
+use OCP\Server;
use Psr\Log\LoggerInterface;
/**
@@ -46,14 +48,14 @@ class InstallerTest extends TestCase {
$this->logger = $this->createMock(LoggerInterface::class);
$this->config = $this->createMock(IConfig::class);
- $config = \OC::$server->getConfig();
+ $config = Server::get(IConfig::class);
$this->appstore = $config->setSystemValue('appstoreenabled', true);
$config->setSystemValue('appstoreenabled', true);
$installer = new Installer(
- \OC::$server->getAppFetcher(),
- \OC::$server->getHTTPClientService(),
- \OC::$server->getTempManager(),
- \OC::$server->get(LoggerInterface::class),
+ Server::get(AppFetcher::class),
+ Server::get(IClientService::class),
+ Server::get(ITempManager::class),
+ Server::get(LoggerInterface::class),
$config,
false
);
@@ -73,45 +75,47 @@ class InstallerTest extends TestCase {
protected function tearDown(): void {
$installer = new Installer(
- \OC::$server->getAppFetcher(),
- \OC::$server->getHTTPClientService(),
- \OC::$server->getTempManager(),
- \OC::$server->get(LoggerInterface::class),
- \OC::$server->getConfig(),
+ Server::get(AppFetcher::class),
+ Server::get(IClientService::class),
+ Server::get(ITempManager::class),
+ Server::get(LoggerInterface::class),
+ Server::get(IConfig::class),
false
);
$installer->removeApp(self::$appid);
- \OC::$server->getConfig()->setSystemValue('appstoreenabled', $this->appstore);
+ Server::get(IConfig::class)->setSystemValue('appstoreenabled', $this->appstore);
parent::tearDown();
}
- public function testInstallApp() {
+ public function testInstallApp(): void {
// Read the current version of the app to check for bug #2572
- \OC_App::getAppVersion('testapp');
+ Server::get(IAppManager::class)->getAppVersion('testapp', true);
+
+ // Build installer
+ $installer = new Installer(
+ Server::get(AppFetcher::class),
+ Server::get(IClientService::class),
+ Server::get(ITempManager::class),
+ Server::get(LoggerInterface::class),
+ Server::get(IConfig::class),
+ false
+ );
// Extract app
$pathOfTestApp = __DIR__ . '/../data/testapp.zip';
$tar = new ZIP($pathOfTestApp);
- $tar->extract(\OC_App::getInstallPath());
+ $tar->extract($installer->getInstallPath());
// Install app
- $installer = new Installer(
- \OC::$server->getAppFetcher(),
- \OC::$server->getHTTPClientService(),
- \OC::$server->getTempManager(),
- \OC::$server->get(LoggerInterface::class),
- \OC::$server->getConfig(),
- false
- );
- $this->assertNull(\OC::$server->getConfig()->getAppValue('testapp', 'enabled', null), 'Check that the app is not listed before installation');
+ $this->assertNull(Server::get(IConfig::class)->getAppValue('testapp', 'enabled', null), 'Check that the app is not listed before installation');
$this->assertSame('testapp', $installer->installApp(self::$appid));
- $this->assertSame('no', \OC::$server->getConfig()->getAppValue('testapp', 'enabled', null), 'Check that the app is listed after installation');
- $this->assertSame('0.9', \OC::$server->getConfig()->getAppValue('testapp', 'installed_version'));
+ $this->assertSame('no', Server::get(IConfig::class)->getAppValue('testapp', 'enabled', null), 'Check that the app is listed after installation');
+ $this->assertSame('0.9', Server::get(IConfig::class)->getAppValue('testapp', 'installed_version'));
$installer->removeApp(self::$appid);
}
- public function updateArrayProvider() {
+ public static function updateArrayProvider(): array {
return [
// Update available
[
@@ -145,11 +149,11 @@ class InstallerTest extends TestCase {
}
/**
- * @dataProvider updateArrayProvider
* @param array $appArray
* @param string|bool $updateAvailable
*/
- public function testIsUpdateAvailable(array $appArray, $updateAvailable) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('updateArrayProvider')]
+ public function testIsUpdateAvailable(array $appArray, $updateAvailable): void {
$this->appFetcher
->expects($this->once())
->method('get')
@@ -161,7 +165,7 @@ class InstallerTest extends TestCase {
}
- public function testDownloadAppWithRevokedCertificate() {
+ public function testDownloadAppWithRevokedCertificate(): void {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Certificate "4112" has been revoked');
@@ -205,7 +209,7 @@ gLgK8d8sKL60JMmKHN3boHrsThKBVA==
}
- public function testDownloadAppWithNotNextcloudCertificate() {
+ public function testDownloadAppWithNotNextcloudCertificate(): void {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('App with id news has a certificate not issued by a trusted Code Signing Authority');
@@ -248,7 +252,7 @@ YSu356M=
}
- public function testDownloadAppWithDifferentCN() {
+ public function testDownloadAppWithDifferentCN(): void {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('App with id news has a cert issued to passman');
@@ -291,7 +295,7 @@ u/spPSSVhaun5BA1FlphB2TkgnzlCmxJa63nFY045e/Jq+IKMcqqZl/092gbI2EQ
}
- public function testDownloadAppWithInvalidSignature() {
+ public function testDownloadAppWithInvalidSignature(): void {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('App with id passman has invalid signature');
@@ -337,7 +341,7 @@ u/spPSSVhaun5BA1FlphB2TkgnzlCmxJa63nFY045e/Jq+IKMcqqZl/092gbI2EQ
->expects($this->once())
->method('get')
->willReturn($appArray);
- $realTmpFile = \OC::$server->getTempManager()->getTemporaryFile('.tar.gz');
+ $realTmpFile = Server::get(ITempManager::class)->getTemporaryFile('.tar.gz');
copy(__DIR__ . '/../data/testapp.tar.gz', $realTmpFile);
$this->tempManager
->expects($this->once())
@@ -359,7 +363,7 @@ u/spPSSVhaun5BA1FlphB2TkgnzlCmxJa63nFY045e/Jq+IKMcqqZl/092gbI2EQ
}
- public function testDownloadAppWithMoreThanOneFolderDownloaded() {
+ public function testDownloadAppWithMoreThanOneFolderDownloaded(): void {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Extracted app testapp has more than 1 folder');
@@ -415,14 +419,14 @@ YwDVP+QmNRzx72jtqAN/Kc3CvQ9nkgYhU65B95aX0xA=',
->expects($this->once())
->method('get')
->willReturn($appArray);
- $realTmpFile = \OC::$server->getTempManager()->getTemporaryFile('.tar.gz');
+ $realTmpFile = Server::get(ITempManager::class)->getTemporaryFile('.tar.gz');
copy(__DIR__ . '/../data/testapp1.tar.gz', $realTmpFile);
$this->tempManager
->expects($this->once())
->method('getTemporaryFile')
->with('.tar.gz')
->willReturn($realTmpFile);
- $realTmpFolder = \OC::$server->getTempManager()->getTemporaryFolder();
+ $realTmpFolder = Server::get(ITempManager::class)->getTemporaryFolder();
mkdir($realTmpFolder . '/testfolder');
$this->tempManager
->expects($this->once())
@@ -443,7 +447,7 @@ YwDVP+QmNRzx72jtqAN/Kc3CvQ9nkgYhU65B95aX0xA=',
}
- public function testDownloadAppWithMismatchingIdentifier() {
+ public function testDownloadAppWithMismatchingIdentifier(): void {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('App for id testapp has a wrong app ID in info.xml: testapp1');
@@ -499,14 +503,14 @@ YwDVP+QmNRzx72jtqAN/Kc3CvQ9nkgYhU65B95aX0xA=',
->expects($this->once())
->method('get')
->willReturn($appArray);
- $realTmpFile = \OC::$server->getTempManager()->getTemporaryFile('.tar.gz');
+ $realTmpFile = Server::get(ITempManager::class)->getTemporaryFile('.tar.gz');
copy(__DIR__ . '/../data/testapp1.tar.gz', $realTmpFile);
$this->tempManager
->expects($this->once())
->method('getTemporaryFile')
->with('.tar.gz')
->willReturn($realTmpFile);
- $realTmpFolder = \OC::$server->getTempManager()->getTemporaryFolder();
+ $realTmpFolder = Server::get(ITempManager::class)->getTemporaryFolder();
$this->tempManager
->expects($this->once())
->method('getTemporaryFolder')
@@ -525,7 +529,7 @@ YwDVP+QmNRzx72jtqAN/Kc3CvQ9nkgYhU65B95aX0xA=',
$installer->downloadApp('testapp');
}
- public function testDownloadAppSuccessful() {
+ public function testDownloadAppSuccessful(): void {
$appArray = [
[
'id' => 'testapp',
@@ -575,30 +579,30 @@ MPLX6f5V9tCJtlH6ztmEcDROfvuVc0U3rEhqx2hphoyo+MZrPFpdcJL8KkIdMKbY
],
];
$this->appFetcher
- ->expects($this->atLeastOnce())
+ ->expects($this->once())
->method('get')
- ->willReturnOnConsecutiveCalls($appArray);
- $realTmpFile = \OC::$server->getTempManager()->getTemporaryFile('.tar.gz');
+ ->willReturn($appArray);
+ $realTmpFile = Server::get(ITempManager::class)->getTemporaryFile('.tar.gz');
copy(__DIR__ . '/../data/testapp.tar.gz', $realTmpFile);
$this->tempManager
- ->expects($this->atLeastOnce())
+ ->expects($this->once())
->method('getTemporaryFile')
->with('.tar.gz')
- ->willReturnOnConsecutiveCalls($realTmpFile);
- $realTmpFolder = \OC::$server->getTempManager()->getTemporaryFolder();
+ ->willReturn($realTmpFile);
+ $realTmpFolder = Server::get(ITempManager::class)->getTemporaryFolder();
$this->tempManager
- ->expects($this->atLeastOnce())
+ ->expects($this->once())
->method('getTemporaryFolder')
- ->willReturnOnConsecutiveCalls($realTmpFolder);
+ ->willReturn($realTmpFolder);
$client = $this->createMock(IClient::class);
$client
->expects($this->once())
->method('get')
->with('https://example.com', ['sink' => $realTmpFile, 'timeout' => 120]);
$this->clientService
- ->expects($this->atLeastOnce())
+ ->expects($this->once())
->method('newClient')
- ->willReturnOnConsecutiveCalls($client);
+ ->willReturn($client);
$installer = $this->getInstaller();
$installer->downloadApp('testapp');
@@ -608,7 +612,15 @@ MPLX6f5V9tCJtlH6ztmEcDROfvuVc0U3rEhqx2hphoyo+MZrPFpdcJL8KkIdMKbY
}
- public function testDownloadAppWithDowngrade() {
+ public function testDownloadAppWithDowngrade(): void {
+ // Use previous test to download the application in version 0.9
+ $this->testDownloadAppSuccessful();
+
+ // Reset mocks
+ $this->appFetcher = $this->createMock(AppFetcher::class);
+ $this->clientService = $this->createMock(IClientService::class);
+ $this->tempManager = $this->createMock(ITempManager::class);
+
$this->expectException(\Exception::class);
$this->expectExceptionMessage('App for id testapp has version 0.9 and tried to update to lower version 0.8');
@@ -661,19 +673,19 @@ JXhrdaWDZ8fzpUjugrtC3qslsqL0dzgU37anS3HwrT8=',
],
];
$this->appFetcher
- ->expects($this->at(1))
+ ->expects($this->once())
->method('get')
->willReturn($appArray);
- $realTmpFile = \OC::$server->getTempManager()->getTemporaryFile('.tar.gz');
+ $realTmpFile = Server::get(ITempManager::class)->getTemporaryFile('.tar.gz');
copy(__DIR__ . '/../data/testapp.0.8.tar.gz', $realTmpFile);
$this->tempManager
- ->expects($this->at(2))
+ ->expects($this->once())
->method('getTemporaryFile')
->with('.tar.gz')
->willReturn($realTmpFile);
- $realTmpFolder = \OC::$server->getTempManager()->getTemporaryFolder();
+ $realTmpFolder = Server::get(ITempManager::class)->getTemporaryFolder();
$this->tempManager
- ->expects($this->at(3))
+ ->expects($this->once())
->method('getTemporaryFolder')
->willReturn($realTmpFolder);
$client = $this->createMock(IClient::class);
@@ -682,10 +694,9 @@ JXhrdaWDZ8fzpUjugrtC3qslsqL0dzgU37anS3HwrT8=',
->method('get')
->with('https://example.com', ['sink' => $realTmpFile, 'timeout' => 120]);
$this->clientService
- ->expects($this->at(1))
+ ->expects($this->once())
->method('newClient')
->willReturn($client);
- $this->testDownloadAppSuccessful();
$this->assertTrue(file_exists(__DIR__ . '/../../apps/testapp/appinfo/info.xml'));
$this->assertEquals('0.9', \OC_App::getAppVersionByPath(__DIR__ . '/../../apps/testapp/'));