diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2016-10-27 17:41:15 +0200 |
---|---|---|
committer | Lukas Reschke <lukas@statuscode.ch> | 2016-10-31 17:17:44 +0100 |
commit | 32cf661215fb3926789054a3953b465fc2665330 (patch) | |
tree | 4cf2865bef5856c59a1fdacb98208a14dfc1a128 /tests/lib/App | |
parent | 357a823457397d3e93ec8cd4dc01fb6859eb0049 (diff) | |
download | nextcloud-server-32cf661215fb3926789054a3953b465fc2665330.tar.gz nextcloud-server-32cf661215fb3926789054a3953b465fc2665330.zip |
Use new appstore API
This change introduces the new appstore API in Nextcloud.
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Diffstat (limited to 'tests/lib/App')
-rw-r--r-- | tests/lib/App/AppStore/Fetcher/AppFetcherTest.php | 39 | ||||
-rw-r--r-- | tests/lib/App/AppStore/Fetcher/CategoryFetcherTest.php | 38 | ||||
-rw-r--r-- | tests/lib/App/AppStore/Fetcher/FetcherBase.php | 246 | ||||
-rw-r--r-- | tests/lib/App/AppStore/Version/VersionParserTest.php | 84 | ||||
-rw-r--r-- | tests/lib/App/AppStore/Version/VersionTest.php | 37 |
5 files changed, 444 insertions, 0 deletions
diff --git a/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php b/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php new file mode 100644 index 00000000000..3b0418a7eba --- /dev/null +++ b/tests/lib/App/AppStore/Fetcher/AppFetcherTest.php @@ -0,0 +1,39 @@ +<?php +/** + * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch> + * + * @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\AppStore\Fetcher; + +use OC\App\AppStore\Fetcher\AppFetcher; + +class AppFetcherTest extends FetcherBase { + public function setUp() { + parent::setUp(); + $this->fileName = 'apps.json'; + $this->endpoint = 'https://apps.nextcloud.com/api/v1/platform/9.2.0/apps.json'; + + $this->fetcher = new AppFetcher( + $this->appData, + $this->clientService, + $this->timeFactory, + $this->config + ); + } +} diff --git a/tests/lib/App/AppStore/Fetcher/CategoryFetcherTest.php b/tests/lib/App/AppStore/Fetcher/CategoryFetcherTest.php new file mode 100644 index 00000000000..db4354119a0 --- /dev/null +++ b/tests/lib/App/AppStore/Fetcher/CategoryFetcherTest.php @@ -0,0 +1,38 @@ +<?php +/** + * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch> + * + * @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\AppStore\Fetcher; + +use OC\App\AppStore\Fetcher\CategoryFetcher; + +class CategoryFetcherTest extends FetcherBase { + public function setUp() { + parent::setUp(); + $this->fileName = 'categories.json'; + $this->endpoint = 'https://apps.nextcloud.com/api/v1/categories.json'; + + $this->fetcher = new CategoryFetcher( + $this->appData, + $this->clientService, + $this->timeFactory + ); + } +} diff --git a/tests/lib/App/AppStore/Fetcher/FetcherBase.php b/tests/lib/App/AppStore/Fetcher/FetcherBase.php new file mode 100644 index 00000000000..66df81f1b2e --- /dev/null +++ b/tests/lib/App/AppStore/Fetcher/FetcherBase.php @@ -0,0 +1,246 @@ +<?php +/** + * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch> + * + * @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\AppStore\Fetcher; + +use OC\App\AppStore\Fetcher\AppFetcher; +use OC\App\AppStore\Fetcher\Fetcher; +use OCP\AppFramework\Utility\ITimeFactory; +use OCP\Files\IAppData; +use OCP\Files\NotFoundException; +use OCP\Files\SimpleFS\ISimpleFile; +use OCP\Files\SimpleFS\ISimpleFolder; +use OCP\Http\Client\IClient; +use OCP\Http\Client\IClientService; +use OCP\Http\Client\IResponse; +use OCP\IConfig; +use Test\TestCase; + +abstract class FetcherBase extends TestCase { + /** @var IAppData|\PHPUnit_Framework_MockObject_MockObject */ + protected $appData; + /** @var IClientService|\PHPUnit_Framework_MockObject_MockObject */ + protected $clientService; + /** @var ITimeFactory|\PHPUnit_Framework_MockObject_MockObject */ + protected $timeFactory; + /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ + protected $config; + /** @var Fetcher */ + protected $fetcher; + /** @var string */ + protected $fileName; + /** @var string */ + protected $endpoint; + + public function setUp() { + parent::setUp(); + $this->appData = $this->createMock(IAppData::class); + $this->clientService = $this->createMock(IClientService::class); + $this->timeFactory = $this->createMock(ITimeFactory::class); + $this->config = $this->createMock(IConfig::class); + } + + public function testGetWithAlreadyExistingFileAndUpToDateTimestamp() { + $folder = $this->createMock(ISimpleFolder::class); + $file = $this->createMock(ISimpleFile::class); + $this->appData + ->expects($this->once()) + ->method('getFolder') + ->with('/') + ->willReturn($folder); + $folder + ->expects($this->once()) + ->method('getFile') + ->with($this->fileName) + ->willReturn($file); + $file + ->expects($this->once()) + ->method('getContent') + ->willReturn('{"timestamp":1200,"data":[{"id":"MyApp"}]}'); + $this->timeFactory + ->expects($this->once()) + ->method('getTime') + ->willReturn(1499); + + $expected = [ + [ + 'id' => 'MyApp', + ], + ]; + $this->assertSame($expected, $this->fetcher->get()); + } + + public function testGetWithNotExistingFileAndUpToDateTimestamp() { + $folder = $this->createMock(ISimpleFolder::class); + $file = $this->createMock(ISimpleFile::class); + $this->appData + ->expects($this->once()) + ->method('getFolder') + ->with('/') + ->willReturn($folder); + $folder + ->expects($this->at(0)) + ->method('getFile') + ->with($this->fileName) + ->willThrowException(new NotFoundException()); + $folder + ->expects($this->at(1)) + ->method('newFile') + ->with($this->fileName) + ->willReturn($file); + $client = $this->createMock(IClient::class); + $this->clientService + ->expects($this->once()) + ->method('newClient') + ->willReturn($client); + $response = $this->createMock(IResponse::class); + $client + ->expects($this->once()) + ->method('get') + ->with($this->endpoint) + ->willReturn($response); + $response + ->expects($this->once()) + ->method('getBody') + ->willReturn('[{"id":"MyNewApp", "foo": "foo"}, {"id":"bar"}]'); + $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1502}'; + $file + ->expects($this->at(0)) + ->method('putContent') + ->with($fileData); + $file + ->expects($this->at(1)) + ->method('getContent') + ->willReturn($fileData); + $this->timeFactory + ->expects($this->at(0)) + ->method('getTime') + ->willReturn(1502); + + $expected = [ + [ + 'id' => 'MyNewApp', + 'foo' => 'foo', + ], + [ + 'id' => 'bar', + ], + ]; + $this->assertSame($expected, $this->fetcher->get()); + } + + public function testGetWithAlreadyExistingFileAndOutdatedTimestamp() { + $folder = $this->createMock(ISimpleFolder::class); + $file = $this->createMock(ISimpleFile::class); + $this->appData + ->expects($this->once()) + ->method('getFolder') + ->with('/') + ->willReturn($folder); + $folder + ->expects($this->once()) + ->method('getFile') + ->with($this->fileName) + ->willReturn($file); + $file + ->expects($this->at(0)) + ->method('getContent') + ->willReturn('{"timestamp":1200,"data":{"MyApp":{"id":"MyApp"}}}'); + $this->timeFactory + ->expects($this->at(0)) + ->method('getTime') + ->willReturn(1501); + $client = $this->createMock(IClient::class); + $this->clientService + ->expects($this->once()) + ->method('newClient') + ->willReturn($client); + $response = $this->createMock(IResponse::class); + $client + ->expects($this->once()) + ->method('get') + ->with($this->endpoint) + ->willReturn($response); + $response + ->expects($this->once()) + ->method('getBody') + ->willReturn('[{"id":"MyNewApp", "foo": "foo"}, {"id":"bar"}]'); + $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1502}'; + $file + ->expects($this->at(1)) + ->method('putContent') + ->with($fileData); + $file + ->expects($this->at(2)) + ->method('getContent') + ->willReturn($fileData); + $this->timeFactory + ->expects($this->at(1)) + ->method('getTime') + ->willReturn(1502); + + $expected = [ + [ + 'id' => 'MyNewApp', + 'foo' => 'foo', + ], + [ + 'id' => 'bar', + ], + ]; + $this->assertSame($expected, $this->fetcher->get()); + } + + public function testGetWithExceptionInClient() { + $folder = $this->createMock(ISimpleFolder::class); + $file = $this->createMock(ISimpleFile::class); + $this->appData + ->expects($this->once()) + ->method('getFolder') + ->with('/') + ->willReturn($folder); + $folder + ->expects($this->once()) + ->method('getFile') + ->with($this->fileName) + ->willReturn($file); + $file + ->expects($this->at(0)) + ->method('getContent') + ->willReturn('{"timestamp":1200,"data":{"MyApp":{"id":"MyApp"}}}'); + $this->timeFactory + ->expects($this->at(0)) + ->method('getTime') + ->willReturn(1501); + $client = $this->createMock(IClient::class); + $this->clientService + ->expects($this->once()) + ->method('newClient') + ->willReturn($client); + $client + ->expects($this->once()) + ->method('get') + ->with($this->endpoint) + ->willThrowException(new \Exception()); + + $this->assertSame([], $this->fetcher->get()); + } +} diff --git a/tests/lib/App/AppStore/Version/VersionParserTest.php b/tests/lib/App/AppStore/Version/VersionParserTest.php new file mode 100644 index 00000000000..ccf557eefbc --- /dev/null +++ b/tests/lib/App/AppStore/Version/VersionParserTest.php @@ -0,0 +1,84 @@ +<?php +/** + * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch> + * + * @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\AppStore\Version; + +use OC\App\AppStore\Version\Version; +use OC\App\AppStore\Version\VersionParser; +use Test\TestCase; + +class VersionParserTest extends TestCase { + /** @var VersionParser */ + private $versionParser; + + public function setUp() { + parent::setUp(); + $this->versionParser = new VersionParser(); + } + + /** + * @return array + */ + public function versionProvider() { + return [ + [ + '*', + new Version('', ''), + ], + [ + '<=8.1.2', + new Version('', '8.1.2'), + ], + [ + '<=9', + new Version('', '9'), + ], + [ + '>=9.3.2', + new Version('9.3.2', ''), + ], + [ + '>=8.1.2 <=9.3.2', + new Version('8.1.2', '9.3.2'), + ], + [ + '>=8.2 <=9.1', + new Version('8.2', '9.1'), + ], + [ + '>=9 <=11', + new Version('9', '11'), + ], + ]; + } + + /** + * @dataProvider versionProvider + * + * @param string $input + * @param Version $expected + */ + public function testGetVersion($input, + Version $expected) { + $this->assertEquals($expected, $this->versionParser->getVersion($input)); + } + +} diff --git a/tests/lib/App/AppStore/Version/VersionTest.php b/tests/lib/App/AppStore/Version/VersionTest.php new file mode 100644 index 00000000000..969c96a57a8 --- /dev/null +++ b/tests/lib/App/AppStore/Version/VersionTest.php @@ -0,0 +1,37 @@ +<?php +/** + * @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch> + * + * @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\AppStore\Version; + +use OC\App\AppStore\Version\Version; +use Test\TestCase; + +class VersionTest extends TestCase { + public function testGetMinimumVersion() { + $version = new Version('9', '10'); + $this->assertSame('9', $version->getMinimumVersion()); + } + + public function testGetMaximumVersion() { + $version = new Version('9', '10'); + $this->assertSame('10', $version->getMaximumVersion()); + } +} |