aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-04-11 15:48:23 +0200
committerGitHub <noreply@github.com>2018-04-11 15:48:23 +0200
commit88c1b8edbdc109a21435cd6434517b2c34cbb3e4 (patch)
tree411f81f2a64ba5d74b51777d243573cff90d805d /tests
parenta18a853e68573d1df18f5e9c322ee27236152ee0 (diff)
parent52f1f047d69cf78a67c71178dcfef348b31006e0 (diff)
downloadnextcloud-server-88c1b8edbdc109a21435cd6434517b2c34cbb3e4.tar.gz
nextcloud-server-88c1b8edbdc109a21435cd6434517b2c34cbb3e4.zip
Merge pull request #9024 from nextcloud/fix/app-fetcher-major-minor-versions
Fix version comparison with minor and patch level requirements
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/App/AppStore/Fetcher/AppFetcherTest.php18
-rw-r--r--tests/lib/App/CompareVersionTest.php91
2 files changed, 103 insertions, 6 deletions
diff --git a/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php b/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php
index 4549b05935c..59dc7366cc0 100644
--- a/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php
+++ b/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php
@@ -22,6 +22,7 @@
namespace Test\App\AppStore\Fetcher;
use OC\App\AppStore\Fetcher\AppFetcher;
+use OC\App\CompareVersion;
use OC\Files\AppData\Factory;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Files\IAppData;
@@ -33,18 +34,21 @@ use OCP\Http\Client\IClientService;
use OCP\Http\Client\IResponse;
use OCP\IConfig;
use OCP\ILogger;
+use PHPUnit_Framework_MockObject_MockObject;
use Test\TestCase;
class AppFetcherTest extends TestCase {
- /** @var IAppData|\PHPUnit_Framework_MockObject_MockObject */
+ /** @var IAppData|PHPUnit_Framework_MockObject_MockObject */
protected $appData;
- /** @var IClientService|\PHPUnit_Framework_MockObject_MockObject */
+ /** @var IClientService|PHPUnit_Framework_MockObject_MockObject */
protected $clientService;
- /** @var ITimeFactory|\PHPUnit_Framework_MockObject_MockObject */
+ /** @var ITimeFactory|PHPUnit_Framework_MockObject_MockObject */
protected $timeFactory;
- /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
+ /** @var IConfig|PHPUnit_Framework_MockObject_MockObject */
protected $config;
- /** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
+ /** @var CompareVersion|PHPUnit_Framework_MockObject_MockObject */
+ protected $compareVersion;
+ /** @var ILogger|PHPUnit_Framework_MockObject_MockObject */
protected $logger;
/** @var AppFetcher */
protected $fetcher;
@@ -57,7 +61,7 @@ EOD;
public function setUp() {
parent::setUp();
- /** @var Factory|\PHPUnit_Framework_MockObject_MockObject $factory */
+ /** @var Factory|PHPUnit_Framework_MockObject_MockObject $factory */
$factory = $this->createMock(Factory::class);
$this->appData = $this->createMock(IAppData::class);
$factory->expects($this->once())
@@ -67,6 +71,7 @@ EOD;
$this->clientService = $this->createMock(IClientService::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->config = $this->createMock(IConfig::class);
+ $this->compareVersion = new CompareVersion();
$this->logger = $this->createMock(ILogger::class);
$this->config
@@ -79,6 +84,7 @@ EOD;
$this->clientService,
$this->timeFactory,
$this->config,
+ $this->compareVersion,
$this->logger
);
}
diff --git a/tests/lib/App/CompareVersionTest.php b/tests/lib/App/CompareVersionTest.php
new file mode 100644
index 00000000000..60309fdeae4
--- /dev/null
+++ b/tests/lib/App/CompareVersionTest.php
@@ -0,0 +1,91 @@
+<?php
+
+/**
+ * @copyright 2018 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @author 2018 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * 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
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Test\App;
+
+use InvalidArgumentException;
+use OC\App\CompareVersion;
+use Test\TestCase;
+
+class CompareVersionTest extends TestCase {
+
+ /** @var CompareVersion */
+ private $compare;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->compare = new CompareVersion();
+ }
+
+ public function comparisonData() {
+ return [
+ // Compatible versions
+ ['13.0.0.3', '13.0.0', '>=', true],
+ ['13.0.0.3', '13.0.0', '<=', true],
+ ['13.0.0', '13.0.0', '>=', true],
+ ['13.0.0', '13.0', '<=', true],
+ ['13.0.0', '13', '>=', true],
+ ['13.0.1', '13', '>=', true],
+ ['13.0.1', '13', '<=', true],
+ // Incompatible major versions
+ ['13.0.0.3', '13.0.0', '<', false],
+ ['12.0.0', '13.0.0', '>=', false],
+ ['12.0.0', '13.0', '>=', false],
+ ['12.0.0', '13', '>=', false],
+ // Incompatible minor and patch versions
+ ['13.0.0', '13.0.1', '>=', false],
+ ['13.0.0', '13.1', '>=', false],
+ // Compatible minor and patch versions
+ ['13.0.1', '13.0.0', '>=', true],
+ ['13.2.0', '13.1', '>=', true],
+ ];
+ }
+
+ /**
+ * @dataProvider comparisonData
+ */
+ public function testComparison(string $actualVersion, string $requiredVersion,
+ string $comparator, bool $expected) {
+ $isCompatible = $this->compare->isCompatible($actualVersion, $requiredVersion,
+ $comparator);
+
+ $this->assertEquals($expected, $isCompatible);
+ }
+
+ public function testInvalidServerVersion() {
+ $actualVersion = '13';
+ $this->expectException(InvalidArgumentException::class);
+
+ $this->compare->isCompatible($actualVersion, '13.0.0');
+ }
+
+ public function testInvalidRequiredVersion() {
+ $actualVersion = '13.0.0';
+ $this->expectException(InvalidArgumentException::class);
+
+ $this->compare->isCompatible($actualVersion, '13.0.0.9');
+ }
+
+}