aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Updater/VersionCheckTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Updater/VersionCheckTest.php')
-rw-r--r--tests/lib/Updater/VersionCheckTest.php68
1 files changed, 28 insertions, 40 deletions
diff --git a/tests/lib/Updater/VersionCheckTest.php b/tests/lib/Updater/VersionCheckTest.php
index ed04975fc54..1936062a5d0 100644
--- a/tests/lib/Updater/VersionCheckTest.php
+++ b/tests/lib/Updater/VersionCheckTest.php
@@ -1,23 +1,9 @@
<?php
+
/**
- * @author Lukas Reschke <lukas@owncloud.com>
- * @author Victor Dubiniuk <dubiniuk@owncloud.com>
- *
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace Test\Updater;
@@ -27,33 +13,33 @@ use OCP\Http\Client\IClientService;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IUserManager;
+use OCP\Server;
+use OCP\ServerVersion;
use OCP\Support\Subscription\IRegistry;
-use OCP\Util;
use Psr\Log\LoggerInterface;
class VersionCheckTest extends \Test\TestCase {
+ /** @var ServerVersion|\PHPUnit\Framework\MockObject\MockObject */
+ private $serverVersion;
/** @var IConfig| \PHPUnit\Framework\MockObject\MockObject */
private $config;
/** @var IAppConfig| \PHPUnit\Framework\MockObject\MockObject */
private $appConfig;
- /** @var VersionCheck | \PHPUnit\Framework\MockObject\MockObject*/
+ /** @var VersionCheck | \PHPUnit\Framework\MockObject\MockObject */
private $updater;
- /** @var IRegistry | \PHPUnit\Framework\Mo2ckObject\MockObject*/
+ /** @var IRegistry | \PHPUnit\Framework\Mo2ckObject\MockObject */
private $registry;
- /** @var LoggerInterface | \PHPUnit\Framework\Mo2ckObject\MockObject*/
+ /** @var LoggerInterface | \PHPUnit\Framework\Mo2ckObject\MockObject */
private $logger;
protected function setUp(): void {
parent::setUp();
- $this->config = $this->getMockBuilder(IConfig::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->appConfig = $this->getMockBuilder(IAppConfig::class)
- ->disableOriginalConstructor()
- ->getMock();
- $clientService = $this->getMockBuilder(IClientService::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $this->serverVersion = $this->createMock(ServerVersion::class);
+ $this->config = $this->createMock(IConfig::class);
+ $this->appConfig = $this->createMock(IAppConfig::class);
+ $clientService = $this->createMock(IClientService::class);
+
+ $this->serverVersion->method('getChannel')->willReturn('git');
$this->registry = $this->createMock(IRegistry::class);
$this->registry
@@ -61,8 +47,9 @@ class VersionCheckTest extends \Test\TestCase {
->willReturn(false);
$this->logger = $this->createMock(LoggerInterface::class);
$this->updater = $this->getMockBuilder(VersionCheck::class)
- ->setMethods(['getUrlContent'])
+ ->onlyMethods(['getUrlContent'])
->setConstructorArgs([
+ $this->serverVersion,
$clientService,
$this->config,
$this->appConfig,
@@ -78,10 +65,11 @@ class VersionCheckTest extends \Test\TestCase {
* @return string
*/
private function buildUpdateUrl($baseUrl) {
- return $baseUrl . '?version='.implode('x', Util::getVersion()).'xinstalledatx' . time() . 'x'.\OC_Util::getChannel().'xxx'.PHP_MAJOR_VERSION.'x'.PHP_MINOR_VERSION.'x'.PHP_RELEASE_VERSION.'x0x0';
+ $serverVersion = Server::get(ServerVersion::class);
+ return $baseUrl . '?version=' . implode('x', $serverVersion->getVersion()) . 'xinstalledatx' . time() . 'x' . $serverVersion->getChannel() . 'xxx' . PHP_MAJOR_VERSION . 'x' . PHP_MINOR_VERSION . 'x' . PHP_RELEASE_VERSION . 'x0x0';
}
- public function testCheckInCache() {
+ public function testCheckInCache(): void {
$expectedResult = [
'version' => '8.0.4.2',
'versionstring' => 'ownCloud 8.0.4',
@@ -109,7 +97,7 @@ class VersionCheckTest extends \Test\TestCase {
$this->assertSame($expectedResult, $this->updater->check());
}
- public function testCheckWithoutUpdateUrl() {
+ public function testCheckWithoutUpdateUrl(): void {
$expectedResult = [
'version' => '8.0.4.2',
'versionstring' => 'ownCloud 8.0.4',
@@ -170,7 +158,7 @@ class VersionCheckTest extends \Test\TestCase {
$this->assertSame($expectedResult, $this->updater->check());
}
- public function testCheckWithInvalidXml() {
+ public function testCheckWithInvalidXml(): void {
$this->config
->expects($this->once())
->method('getSystemValueBool')
@@ -213,7 +201,7 @@ class VersionCheckTest extends \Test\TestCase {
$this->assertSame([], $this->updater->check());
}
- public function testCheckWithEmptyValidXmlResponse() {
+ public function testCheckWithEmptyValidXmlResponse(): void {
$expectedResult = [
'version' => '',
'versionstring' => '',
@@ -273,7 +261,7 @@ class VersionCheckTest extends \Test\TestCase {
$this->assertSame($expectedResult, $this->updater->check());
}
- public function testCheckWithEmptyInvalidXmlResponse() {
+ public function testCheckWithEmptyInvalidXmlResponse(): void {
$expectedResult = [];
$this->config
@@ -318,7 +306,7 @@ class VersionCheckTest extends \Test\TestCase {
$this->assertSame($expectedResult, $this->updater->check());
}
- public function testCheckWithMissingAttributeXmlResponse() {
+ public function testCheckWithMissingAttributeXmlResponse(): void {
$expectedResult = [
'version' => '',
'versionstring' => '',
@@ -378,7 +366,7 @@ class VersionCheckTest extends \Test\TestCase {
$this->assertSame($expectedResult, $this->updater->check());
}
- public function testNoInternet() {
+ public function testNoInternet(): void {
$this->config
->expects($this->once())
->method('getSystemValueBool')