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.php101
1 files changed, 52 insertions, 49 deletions
diff --git a/tests/lib/InstallerTest.php b/tests/lib/InstallerTest.php
index 4e622dca6d1..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;
@@ -16,6 +16,7 @@ use OCP\Http\Client\IClient;
use OCP\Http\Client\IClientService;
use OCP\IConfig;
use OCP\ITempManager;
+use OCP\Server;
use Psr\Log\LoggerInterface;
/**
@@ -47,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
);
@@ -74,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
- \OCP\Server::get(IAppManager::class)->getAppVersion('testapp', true);
+ 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
[
@@ -146,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')
@@ -162,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');
@@ -206,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');
@@ -249,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');
@@ -292,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');
@@ -338,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())
@@ -360,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');
@@ -416,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())
@@ -444,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');
@@ -500,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')
@@ -526,7 +529,7 @@ YwDVP+QmNRzx72jtqAN/Kc3CvQ9nkgYhU65B95aX0xA=',
$installer->downloadApp('testapp');
}
- public function testDownloadAppSuccessful() {
+ public function testDownloadAppSuccessful(): void {
$appArray = [
[
'id' => 'testapp',
@@ -579,14 +582,14 @@ MPLX6f5V9tCJtlH6ztmEcDROfvuVc0U3rEhqx2hphoyo+MZrPFpdcJL8KkIdMKbY
->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())
->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')
@@ -609,7 +612,7 @@ MPLX6f5V9tCJtlH6ztmEcDROfvuVc0U3rEhqx2hphoyo+MZrPFpdcJL8KkIdMKbY
}
- public function testDownloadAppWithDowngrade() {
+ public function testDownloadAppWithDowngrade(): void {
// Use previous test to download the application in version 0.9
$this->testDownloadAppSuccessful();
@@ -673,14 +676,14 @@ JXhrdaWDZ8fzpUjugrtC3qslsqL0dzgU37anS3HwrT8=',
->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->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')