Completed
Push — master ( 38c8ea...c9712b )
by Joas
40:21
created
tests/lib/Collaboration/Resources/ManagerTest.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -18,29 +18,29 @@
 block discarded – undo
18 18
 
19 19
 class ManagerTest extends TestCase {
20 20
 
21
-	protected LoggerInterface&MockObject $logger;
22
-	protected IProviderManager&MockObject $providerManager;
23
-	protected IManager $manager;
24
-
25
-	protected function setUp(): void {
26
-		parent::setUp();
27
-
28
-		$this->logger = $this->createMock(LoggerInterface::class);
29
-		$this->providerManager = $this->createMock(IProviderManager::class);
30
-
31
-		/** @var IDBConnection $connection */
32
-		$connection = $this->createMock(IDBConnection::class);
33
-		$this->manager = new Manager($connection, $this->providerManager, $this->logger);
34
-	}
35
-
36
-	public function testRegisterResourceProvider(): void {
37
-		$this->logger->expects($this->once())
38
-			->method('debug')
39
-			->with($this->equalTo('\OC\Collaboration\Resources\Manager::registerResourceProvider is deprecated'), $this->equalTo(['provider' => 'AwesomeResourceProvider']));
40
-		$this->providerManager->expects($this->once())
41
-			->method('registerResourceProvider')
42
-			->with($this->equalTo('AwesomeResourceProvider'));
43
-
44
-		$this->manager->registerResourceProvider('AwesomeResourceProvider');
45
-	}
21
+    protected LoggerInterface&MockObject $logger;
22
+    protected IProviderManager&MockObject $providerManager;
23
+    protected IManager $manager;
24
+
25
+    protected function setUp(): void {
26
+        parent::setUp();
27
+
28
+        $this->logger = $this->createMock(LoggerInterface::class);
29
+        $this->providerManager = $this->createMock(IProviderManager::class);
30
+
31
+        /** @var IDBConnection $connection */
32
+        $connection = $this->createMock(IDBConnection::class);
33
+        $this->manager = new Manager($connection, $this->providerManager, $this->logger);
34
+    }
35
+
36
+    public function testRegisterResourceProvider(): void {
37
+        $this->logger->expects($this->once())
38
+            ->method('debug')
39
+            ->with($this->equalTo('\OC\Collaboration\Resources\Manager::registerResourceProvider is deprecated'), $this->equalTo(['provider' => 'AwesomeResourceProvider']));
40
+        $this->providerManager->expects($this->once())
41
+            ->method('registerResourceProvider')
42
+            ->with($this->equalTo('AwesomeResourceProvider'));
43
+
44
+        $this->manager->registerResourceProvider('AwesomeResourceProvider');
45
+    }
46 46
 }
Please login to merge, or discard this patch.
tests/lib/Session/Session.php 1 patch
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -9,58 +9,58 @@
 block discarded – undo
9 9
 namespace Test\Session;
10 10
 
11 11
 abstract class Session extends \Test\TestCase {
12
-	/**
13
-	 * @var \OC\Session\Session
14
-	 */
15
-	protected $instance;
12
+    /**
13
+     * @var \OC\Session\Session
14
+     */
15
+    protected $instance;
16 16
 
17
-	protected function tearDown(): void {
18
-		$this->instance->clear();
19
-		parent::tearDown();
20
-	}
17
+    protected function tearDown(): void {
18
+        $this->instance->clear();
19
+        parent::tearDown();
20
+    }
21 21
 
22
-	public function testNotExistsEmpty(): void {
23
-		$this->assertFalse($this->instance->exists('foo'));
24
-	}
22
+    public function testNotExistsEmpty(): void {
23
+        $this->assertFalse($this->instance->exists('foo'));
24
+    }
25 25
 
26
-	public function testExistsAfterSet(): void {
27
-		$this->instance->set('foo', 1);
28
-		$this->assertTrue($this->instance->exists('foo'));
29
-	}
26
+    public function testExistsAfterSet(): void {
27
+        $this->instance->set('foo', 1);
28
+        $this->assertTrue($this->instance->exists('foo'));
29
+    }
30 30
 
31
-	public function testNotExistsAfterRemove(): void {
32
-		$this->instance->set('foo', 1);
33
-		$this->instance->remove('foo');
34
-		$this->assertFalse($this->instance->exists('foo'));
35
-	}
31
+    public function testNotExistsAfterRemove(): void {
32
+        $this->instance->set('foo', 1);
33
+        $this->instance->remove('foo');
34
+        $this->assertFalse($this->instance->exists('foo'));
35
+    }
36 36
 
37
-	public function testGetNonExisting(): void {
38
-		$this->assertNull($this->instance->get('foo'));
39
-	}
37
+    public function testGetNonExisting(): void {
38
+        $this->assertNull($this->instance->get('foo'));
39
+    }
40 40
 
41
-	public function testGetAfterSet(): void {
42
-		$this->instance->set('foo', 'bar');
43
-		$this->assertEquals('bar', $this->instance->get(('foo')));
44
-	}
41
+    public function testGetAfterSet(): void {
42
+        $this->instance->set('foo', 'bar');
43
+        $this->assertEquals('bar', $this->instance->get(('foo')));
44
+    }
45 45
 
46
-	public function testRemoveNonExisting(): void {
47
-		$this->assertFalse($this->instance->exists('foo'));
48
-		$this->instance->remove('foo');
49
-		$this->assertFalse($this->instance->exists('foo'));
50
-	}
46
+    public function testRemoveNonExisting(): void {
47
+        $this->assertFalse($this->instance->exists('foo'));
48
+        $this->instance->remove('foo');
49
+        $this->assertFalse($this->instance->exists('foo'));
50
+    }
51 51
 
52
-	public function testNotExistsAfterClear(): void {
53
-		$this->instance->set('foo', 1);
54
-		$this->instance->clear();
55
-		$this->assertFalse($this->instance->exists('foo'));
56
-	}
52
+    public function testNotExistsAfterClear(): void {
53
+        $this->instance->set('foo', 1);
54
+        $this->instance->clear();
55
+        $this->assertFalse($this->instance->exists('foo'));
56
+    }
57 57
 
58
-	public function testArrayInterface(): void {
59
-		$this->assertFalse(isset($this->instance['foo']));
60
-		$this->instance['foo'] = 'bar';
61
-		$this->assertTrue(isset($this->instance['foo']));
62
-		$this->assertEquals('bar', $this->instance['foo']);
63
-		unset($this->instance['foo']);
64
-		$this->assertFalse(isset($this->instance['foo']));
65
-	}
58
+    public function testArrayInterface(): void {
59
+        $this->assertFalse(isset($this->instance['foo']));
60
+        $this->instance['foo'] = 'bar';
61
+        $this->assertTrue(isset($this->instance['foo']));
62
+        $this->assertEquals('bar', $this->instance['foo']);
63
+        unset($this->instance['foo']);
64
+        $this->assertFalse(isset($this->instance['foo']));
65
+    }
66 66
 }
Please login to merge, or discard this patch.
tests/lib/BackgroundJob/TestTimedJobNew.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -13,14 +13,14 @@
 block discarded – undo
13 13
 use OCP\BackgroundJob\TimedJob;
14 14
 
15 15
 class TestTimedJobNew extends TimedJob {
16
-	public bool $ran = false;
16
+    public bool $ran = false;
17 17
 
18
-	public function __construct(ITimeFactory $timeFactory) {
19
-		parent::__construct($timeFactory);
20
-		$this->setInterval(10);
21
-	}
18
+    public function __construct(ITimeFactory $timeFactory) {
19
+        parent::__construct($timeFactory);
20
+        $this->setInterval(10);
21
+    }
22 22
 
23
-	public function run($argument) {
24
-		$this->ran = true;
25
-	}
23
+    public function run($argument) {
24
+        $this->ran = true;
25
+    }
26 26
 }
Please login to merge, or discard this patch.
tests/lib/App/AppStore/Bundles/EducationBundleTest.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -9,19 +9,19 @@
 block discarded – undo
9 9
 use OC\App\AppStore\Bundles\EducationBundle;
10 10
 
11 11
 class EducationBundleTest extends BundleBase {
12
-	protected function setUp(): void {
13
-		parent::setUp();
14
-		$this->bundle = new EducationBundle($this->l10n);
15
-		$this->bundleIdentifier = 'EducationBundle';
16
-		$this->bundleName = 'Education bundle';
17
-		$this->bundleAppIds = [
18
-			'dashboard',
19
-			'circles',
20
-			'groupfolders',
21
-			'announcementcenter',
22
-			'quota_warning',
23
-			'user_saml',
24
-			'whiteboard',
25
-		];
26
-	}
12
+    protected function setUp(): void {
13
+        parent::setUp();
14
+        $this->bundle = new EducationBundle($this->l10n);
15
+        $this->bundleIdentifier = 'EducationBundle';
16
+        $this->bundleName = 'Education bundle';
17
+        $this->bundleAppIds = [
18
+            'dashboard',
19
+            'circles',
20
+            'groupfolders',
21
+            'announcementcenter',
22
+            'quota_warning',
23
+            'user_saml',
24
+            'whiteboard',
25
+        ];
26
+    }
27 27
 }
Please login to merge, or discard this patch.
tests/lib/App/AppStore/Bundles/GroupwareBundleTest.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -9,16 +9,16 @@
 block discarded – undo
9 9
 use OC\App\AppStore\Bundles\GroupwareBundle;
10 10
 
11 11
 class GroupwareBundleTest extends BundleBase {
12
-	protected function setUp(): void {
13
-		parent::setUp();
14
-		$this->bundle = new GroupwareBundle($this->l10n);
15
-		$this->bundleIdentifier = 'GroupwareBundle';
16
-		$this->bundleName = 'Groupware bundle';
17
-		$this->bundleAppIds = [
18
-			'calendar',
19
-			'contacts',
20
-			'deck',
21
-			'mail'
22
-		];
23
-	}
12
+    protected function setUp(): void {
13
+        parent::setUp();
14
+        $this->bundle = new GroupwareBundle($this->l10n);
15
+        $this->bundleIdentifier = 'GroupwareBundle';
16
+        $this->bundleName = 'Groupware bundle';
17
+        $this->bundleAppIds = [
18
+            'calendar',
19
+            'contacts',
20
+            'deck',
21
+            'mail'
22
+        ];
23
+    }
24 24
 }
Please login to merge, or discard this patch.
tests/lib/App/AppStore/Bundles/BundleFetcherTest.php 1 patch
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -17,43 +17,43 @@
 block discarded – undo
17 17
 use Test\TestCase;
18 18
 
19 19
 class BundleFetcherTest extends TestCase {
20
-	/** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
21
-	private $l10n;
22
-	/** @var BundleFetcher */
23
-	private $bundleFetcher;
24
-
25
-	protected function setUp(): void {
26
-		parent::setUp();
27
-
28
-		$this->l10n = $this->createMock(IL10N::class);
29
-
30
-		$this->bundleFetcher = new BundleFetcher(
31
-			$this->l10n
32
-		);
33
-	}
34
-
35
-	public function testGetBundles(): void {
36
-		$expected = [
37
-			new EnterpriseBundle($this->l10n),
38
-			new HubBundle($this->l10n),
39
-			new GroupwareBundle($this->l10n),
40
-			new SocialSharingBundle($this->l10n),
41
-			new EducationBundle($this->l10n),
42
-			new PublicSectorBundle($this->l10n),
43
-		];
44
-		$this->assertEquals($expected, $this->bundleFetcher->getBundles());
45
-	}
46
-
47
-	public function testGetBundleByIdentifier(): void {
48
-		$this->assertEquals(new EnterpriseBundle($this->l10n), $this->bundleFetcher->getBundleByIdentifier('EnterpriseBundle'));
49
-		$this->assertEquals(new GroupwareBundle($this->l10n), $this->bundleFetcher->getBundleByIdentifier('GroupwareBundle'));
50
-	}
51
-
52
-
53
-	public function testGetBundleByIdentifierWithException(): void {
54
-		$this->expectException(\BadMethodCallException::class);
55
-		$this->expectExceptionMessage('Bundle with specified identifier does not exist');
56
-
57
-		$this->bundleFetcher->getBundleByIdentifier('NotExistingBundle');
58
-	}
20
+    /** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
21
+    private $l10n;
22
+    /** @var BundleFetcher */
23
+    private $bundleFetcher;
24
+
25
+    protected function setUp(): void {
26
+        parent::setUp();
27
+
28
+        $this->l10n = $this->createMock(IL10N::class);
29
+
30
+        $this->bundleFetcher = new BundleFetcher(
31
+            $this->l10n
32
+        );
33
+    }
34
+
35
+    public function testGetBundles(): void {
36
+        $expected = [
37
+            new EnterpriseBundle($this->l10n),
38
+            new HubBundle($this->l10n),
39
+            new GroupwareBundle($this->l10n),
40
+            new SocialSharingBundle($this->l10n),
41
+            new EducationBundle($this->l10n),
42
+            new PublicSectorBundle($this->l10n),
43
+        ];
44
+        $this->assertEquals($expected, $this->bundleFetcher->getBundles());
45
+    }
46
+
47
+    public function testGetBundleByIdentifier(): void {
48
+        $this->assertEquals(new EnterpriseBundle($this->l10n), $this->bundleFetcher->getBundleByIdentifier('EnterpriseBundle'));
49
+        $this->assertEquals(new GroupwareBundle($this->l10n), $this->bundleFetcher->getBundleByIdentifier('GroupwareBundle'));
50
+    }
51
+
52
+
53
+    public function testGetBundleByIdentifierWithException(): void {
54
+        $this->expectException(\BadMethodCallException::class);
55
+        $this->expectExceptionMessage('Bundle with specified identifier does not exist');
56
+
57
+        $this->bundleFetcher->getBundleByIdentifier('NotExistingBundle');
58
+    }
59 59
 }
Please login to merge, or discard this patch.
tests/lib/App/AppStore/Bundles/SocialSharingBundleTest.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -9,16 +9,16 @@
 block discarded – undo
9 9
 use OC\App\AppStore\Bundles\SocialSharingBundle;
10 10
 
11 11
 class SocialSharingBundleTest extends BundleBase {
12
-	protected function setUp(): void {
13
-		parent::setUp();
14
-		$this->bundle = new SocialSharingBundle($this->l10n);
15
-		$this->bundleIdentifier = 'SocialSharingBundle';
16
-		$this->bundleName = 'Social sharing bundle';
17
-		$this->bundleAppIds = [
18
-			'socialsharing_twitter',
19
-			'socialsharing_facebook',
20
-			'socialsharing_email',
21
-			'socialsharing_diaspora',
22
-		];
23
-	}
12
+    protected function setUp(): void {
13
+        parent::setUp();
14
+        $this->bundle = new SocialSharingBundle($this->l10n);
15
+        $this->bundleIdentifier = 'SocialSharingBundle';
16
+        $this->bundleName = 'Social sharing bundle';
17
+        $this->bundleAppIds = [
18
+            'socialsharing_twitter',
19
+            'socialsharing_facebook',
20
+            'socialsharing_email',
21
+            'socialsharing_diaspora',
22
+        ];
23
+    }
24 24
 }
Please login to merge, or discard this patch.
tests/lib/App/AppStore/Bundles/EnterpriseBundleTest.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -9,19 +9,19 @@
 block discarded – undo
9 9
 use OC\App\AppStore\Bundles\EnterpriseBundle;
10 10
 
11 11
 class EnterpriseBundleTest extends BundleBase {
12
-	protected function setUp(): void {
13
-		parent::setUp();
14
-		$this->bundle = new EnterpriseBundle($this->l10n);
15
-		$this->bundleIdentifier = 'EnterpriseBundle';
16
-		$this->bundleName = 'Enterprise bundle';
17
-		$this->bundleAppIds = [
18
-			'admin_audit',
19
-			'user_ldap',
20
-			'files_retention',
21
-			'files_automatedtagging',
22
-			'user_saml',
23
-			'files_accesscontrol',
24
-			'terms_of_service',
25
-		];
26
-	}
12
+    protected function setUp(): void {
13
+        parent::setUp();
14
+        $this->bundle = new EnterpriseBundle($this->l10n);
15
+        $this->bundleIdentifier = 'EnterpriseBundle';
16
+        $this->bundleName = 'Enterprise bundle';
17
+        $this->bundleAppIds = [
18
+            'admin_audit',
19
+            'user_ldap',
20
+            'files_retention',
21
+            'files_automatedtagging',
22
+            'user_saml',
23
+            'files_accesscontrol',
24
+            'terms_of_service',
25
+        ];
26
+    }
27 27
 }
Please login to merge, or discard this patch.
tests/lib/App/AppStore/Fetcher/FetcherBase.php 1 patch
Indentation   +648 added lines, -648 removed lines patch added patch discarded remove patch
@@ -23,652 +23,652 @@
 block discarded – undo
23 23
 use Test\TestCase;
24 24
 
25 25
 abstract class FetcherBase extends TestCase {
26
-	/** @var Factory|\PHPUnit\Framework\MockObject\MockObject */
27
-	protected $appDataFactory;
28
-	/** @var IAppData|\PHPUnit\Framework\MockObject\MockObject */
29
-	protected $appData;
30
-	/** @var IClientService|\PHPUnit\Framework\MockObject\MockObject */
31
-	protected $clientService;
32
-	/** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
33
-	protected $timeFactory;
34
-	/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
35
-	protected $config;
36
-	/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
37
-	protected $logger;
38
-	/** @var IRegistry|\PHPUnit\Framework\MockObject\MockObject */
39
-	protected $registry;
40
-	/** @var Fetcher */
41
-	protected $fetcher;
42
-	/** @var string */
43
-	protected $fileName;
44
-	/** @var string */
45
-	protected $endpoint;
46
-
47
-	protected function setUp(): void {
48
-		parent::setUp();
49
-		$this->appDataFactory = $this->createMock(Factory::class);
50
-		$this->appData = $this->createMock(AppData::class);
51
-		$this->appDataFactory->expects($this->once())
52
-			->method('get')
53
-			->with('appstore')
54
-			->willReturn($this->appData);
55
-		$this->clientService = $this->createMock(IClientService::class);
56
-		$this->timeFactory = $this->createMock(ITimeFactory::class);
57
-		$this->config = $this->createMock(IConfig::class);
58
-		$this->logger = $this->createMock(LoggerInterface::class);
59
-		$this->registry = $this->createMock(IRegistry::class);
60
-	}
61
-
62
-	public function testGetWithAlreadyExistingFileAndUpToDateTimestampAndVersion(): void {
63
-		$this->config
64
-			->method('getSystemValueString')
65
-			->willReturnCallback(function ($var, $default) {
66
-				if ($var === 'version') {
67
-					return '11.0.0.2';
68
-				}
69
-				return $default;
70
-			});
71
-		$this->config->method('getSystemValueBool')
72
-			->willReturnArgument(1);
73
-
74
-		$folder = $this->createMock(ISimpleFolder::class);
75
-		$file = $this->createMock(ISimpleFile::class);
76
-		$this->appData
77
-			->expects($this->once())
78
-			->method('getFolder')
79
-			->with('/')
80
-			->willReturn($folder);
81
-		$folder
82
-			->expects($this->once())
83
-			->method('getFile')
84
-			->with($this->fileName)
85
-			->willReturn($file);
86
-		$file
87
-			->expects($this->once())
88
-			->method('getContent')
89
-			->willReturn('{"timestamp":1200,"data":[{"id":"MyApp"}],"ncversion":"11.0.0.2"}');
90
-		$this->timeFactory
91
-			->expects($this->once())
92
-			->method('getTime')
93
-			->willReturn(1499);
94
-
95
-		$expected = [
96
-			[
97
-				'id' => 'MyApp',
98
-			],
99
-		];
100
-		$this->assertSame($expected, $this->fetcher->get());
101
-	}
102
-
103
-	public function testGetWithNotExistingFileAndUpToDateTimestampAndVersion(): void {
104
-		$this->config
105
-			->method('getSystemValueString')
106
-			->willReturnCallback(function ($var, $default) {
107
-				if ($var === 'appstoreurl') {
108
-					return 'https://apps.nextcloud.com/api/v1';
109
-				} elseif ($var === 'version') {
110
-					return '11.0.0.2';
111
-				}
112
-				return $default;
113
-			});
114
-		$this->config->method('getSystemValueBool')
115
-			->willReturnArgument(1);
116
-
117
-		$folder = $this->createMock(ISimpleFolder::class);
118
-		$file = $this->createMock(ISimpleFile::class);
119
-		$this->appData
120
-			->expects($this->once())
121
-			->method('getFolder')
122
-			->with('/')
123
-			->willReturn($folder);
124
-		$folder
125
-			->expects($this->once())
126
-			->method('getFile')
127
-			->with($this->fileName)
128
-			->willThrowException(new NotFoundException());
129
-		$folder
130
-			->expects($this->once())
131
-			->method('newFile')
132
-			->with($this->fileName)
133
-			->willReturn($file);
134
-		$client = $this->createMock(IClient::class);
135
-		$this->clientService
136
-			->expects($this->once())
137
-			->method('newClient')
138
-			->willReturn($client);
139
-		$response = $this->createMock(IResponse::class);
140
-		$client
141
-			->expects($this->once())
142
-			->method('get')
143
-			->with($this->endpoint)
144
-			->willReturn($response);
145
-		$response
146
-			->expects($this->once())
147
-			->method('getBody')
148
-			->willReturn('[{"id":"MyNewApp", "foo": "foo"}, {"id":"bar"}]');
149
-		$response->method('getHeader')
150
-			->with($this->equalTo('ETag'))
151
-			->willReturn('"myETag"');
152
-		$fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1502,"ncversion":"11.0.0.2","ETag":"\"myETag\""}';
153
-		$file
154
-			->expects($this->once())
155
-			->method('putContent')
156
-			->with($fileData);
157
-		$file
158
-			->expects($this->once())
159
-			->method('getContent')
160
-			->willReturn($fileData);
161
-		$this->timeFactory
162
-			->expects($this->once())
163
-			->method('getTime')
164
-			->willReturn(1502);
165
-
166
-		$expected = [
167
-			[
168
-				'id' => 'MyNewApp',
169
-				'foo' => 'foo',
170
-			],
171
-			[
172
-				'id' => 'bar',
173
-			],
174
-		];
175
-		$this->assertSame($expected, $this->fetcher->get());
176
-	}
177
-
178
-	public function testGetWithAlreadyExistingFileAndOutdatedTimestamp(): void {
179
-		$this->config->method('getSystemValueString')
180
-			->willReturnCallback(function ($key, $default) {
181
-				if ($key === 'version') {
182
-					return '11.0.0.2';
183
-				} else {
184
-					return $default;
185
-				}
186
-			});
187
-		$this->config->method('getSystemValueBool')
188
-			->willReturnArgument(1);
189
-
190
-		$folder = $this->createMock(ISimpleFolder::class);
191
-		$file = $this->createMock(ISimpleFile::class);
192
-		$this->appData
193
-			->expects($this->once())
194
-			->method('getFolder')
195
-			->with('/')
196
-			->willReturn($folder);
197
-		$folder
198
-			->expects($this->once())
199
-			->method('getFile')
200
-			->with($this->fileName)
201
-			->willReturn($file);
202
-		$fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1502,"ncversion":"11.0.0.2","ETag":"\"myETag\""}';
203
-		$file
204
-			->expects($this->once())
205
-			->method('putContent')
206
-			->with($fileData);
207
-		$file
208
-			->expects($this->exactly(2))
209
-			->method('getContent')
210
-			->willReturnOnConsecutiveCalls(
211
-				'{"timestamp":1200,"data":{"MyApp":{"id":"MyApp"}},"ncversion":"11.0.0.2"}',
212
-				$fileData
213
-			);
214
-		$this->timeFactory
215
-			->expects($this->exactly(2))
216
-			->method('getTime')
217
-			->willReturnOnConsecutiveCalls(
218
-				4801,
219
-				1502
220
-			);
221
-		$client = $this->createMock(IClient::class);
222
-		$this->clientService
223
-			->expects($this->once())
224
-			->method('newClient')
225
-			->willReturn($client);
226
-		$response = $this->createMock(IResponse::class);
227
-		$client
228
-			->expects($this->once())
229
-			->method('get')
230
-			->with($this->endpoint)
231
-			->willReturn($response);
232
-		$response
233
-			->expects($this->once())
234
-			->method('getBody')
235
-			->willReturn('[{"id":"MyNewApp", "foo": "foo"}, {"id":"bar"}]');
236
-		$response->method('getHeader')
237
-			->with($this->equalTo('ETag'))
238
-			->willReturn('"myETag"');
239
-
240
-		$expected = [
241
-			[
242
-				'id' => 'MyNewApp',
243
-				'foo' => 'foo',
244
-			],
245
-			[
246
-				'id' => 'bar',
247
-			],
248
-		];
249
-		$this->assertSame($expected, $this->fetcher->get());
250
-	}
251
-
252
-	public function testGetWithAlreadyExistingFileAndNoVersion(): void {
253
-		$this->config
254
-			->method('getSystemValueString')
255
-			->willReturnCallback(function ($var, $default) {
256
-				if ($var === 'appstoreurl') {
257
-					return 'https://apps.nextcloud.com/api/v1';
258
-				} elseif ($var === 'version') {
259
-					return '11.0.0.2';
260
-				}
261
-				return $default;
262
-			});
263
-		$this->config->method('getSystemValueBool')
264
-			->willReturnArgument(1);
265
-
266
-		$folder = $this->createMock(ISimpleFolder::class);
267
-		$file = $this->createMock(ISimpleFile::class);
268
-		$this->appData
269
-			->expects($this->once())
270
-			->method('getFolder')
271
-			->with('/')
272
-			->willReturn($folder);
273
-		$folder
274
-			->expects($this->once())
275
-			->method('getFile')
276
-			->with($this->fileName)
277
-			->willReturn($file);
278
-		$fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1201,"ncversion":"11.0.0.2","ETag":"\"myETag\""}';
279
-		$file
280
-			->expects($this->once())
281
-			->method('putContent')
282
-			->with($fileData);
283
-		$file
284
-			->expects($this->exactly(2))
285
-			->method('getContent')
286
-			->willReturnOnConsecutiveCalls(
287
-				'{"timestamp":1200,"data":{"MyApp":{"id":"MyApp"}}',
288
-				$fileData
289
-			);
290
-		$this->timeFactory
291
-			->expects($this->once())
292
-			->method('getTime')
293
-			->willReturn(1201);
294
-		$client = $this->createMock(IClient::class);
295
-		$this->clientService
296
-			->expects($this->once())
297
-			->method('newClient')
298
-			->willReturn($client);
299
-		$response = $this->createMock(IResponse::class);
300
-		$client
301
-			->expects($this->once())
302
-			->method('get')
303
-			->with($this->endpoint)
304
-			->willReturn($response);
305
-		$response
306
-			->expects($this->once())
307
-			->method('getBody')
308
-			->willReturn('[{"id":"MyNewApp", "foo": "foo"}, {"id":"bar"}]');
309
-		$response->method('getHeader')
310
-			->with($this->equalTo('ETag'))
311
-			->willReturn('"myETag"');
312
-
313
-		$expected = [
314
-			[
315
-				'id' => 'MyNewApp',
316
-				'foo' => 'foo',
317
-			],
318
-			[
319
-				'id' => 'bar',
320
-			],
321
-		];
322
-		$this->assertSame($expected, $this->fetcher->get());
323
-	}
324
-
325
-	public function testGetWithAlreadyExistingFileAndOutdatedVersion(): void {
326
-		$this->config
327
-			->method('getSystemValueString')
328
-			->willReturnCallback(function ($var, $default) {
329
-				if ($var === 'appstoreurl') {
330
-					return 'https://apps.nextcloud.com/api/v1';
331
-				} elseif ($var === 'version') {
332
-					return '11.0.0.2';
333
-				}
334
-				return $default;
335
-			});
336
-		$this->config->method('getSystemValueBool')
337
-			->willReturnArgument(1);
338
-
339
-		$folder = $this->createMock(ISimpleFolder::class);
340
-		$file = $this->createMock(ISimpleFile::class);
341
-		$this->appData
342
-			->expects($this->once())
343
-			->method('getFolder')
344
-			->with('/')
345
-			->willReturn($folder);
346
-		$folder
347
-			->expects($this->once())
348
-			->method('getFile')
349
-			->with($this->fileName)
350
-			->willReturn($file);
351
-		$fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1201,"ncversion":"11.0.0.2","ETag":"\"myETag\""}';
352
-		$file
353
-			->expects($this->once())
354
-			->method('putContent')
355
-			->with($fileData);
356
-		$file
357
-			->expects($this->exactly(2))
358
-			->method('getContent')
359
-			->willReturnOnConsecutiveCalls(
360
-				'{"timestamp":1200,"data":{"MyApp":{"id":"MyApp"}},"ncversion":"11.0.0.1"',
361
-				$fileData
362
-			);
363
-		$this->timeFactory
364
-			->method('getTime')
365
-			->willReturn(1201);
366
-		$client = $this->createMock(IClient::class);
367
-		$this->clientService
368
-			->expects($this->once())
369
-			->method('newClient')
370
-			->willReturn($client);
371
-		$response = $this->createMock(IResponse::class);
372
-		$client
373
-			->expects($this->once())
374
-			->method('get')
375
-			->with($this->endpoint)
376
-			->willReturn($response);
377
-		$response
378
-			->expects($this->once())
379
-			->method('getBody')
380
-			->willReturn('[{"id":"MyNewApp", "foo": "foo"}, {"id":"bar"}]');
381
-		$response->method('getHeader')
382
-			->with($this->equalTo('ETag'))
383
-			->willReturn('"myETag"');
384
-
385
-		$expected = [
386
-			[
387
-				'id' => 'MyNewApp',
388
-				'foo' => 'foo',
389
-			],
390
-			[
391
-				'id' => 'bar',
392
-			],
393
-		];
394
-		$this->assertSame($expected, $this->fetcher->get());
395
-	}
396
-
397
-	public function testGetWithExceptionInClient(): void {
398
-		$this->config->method('getSystemValueString')
399
-			->willReturnArgument(1);
400
-		$this->config->method('getSystemValueBool')
401
-			->willReturnArgument(1);
402
-
403
-		$folder = $this->createMock(ISimpleFolder::class);
404
-		$file = $this->createMock(ISimpleFile::class);
405
-		$this->appData
406
-			->expects($this->once())
407
-			->method('getFolder')
408
-			->with('/')
409
-			->willReturn($folder);
410
-		$folder
411
-			->expects($this->once())
412
-			->method('getFile')
413
-			->with($this->fileName)
414
-			->willReturn($file);
415
-		$file
416
-			->expects($this->once())
417
-			->method('getContent')
418
-			->willReturn('{"timestamp":1200,"data":{"MyApp":{"id":"MyApp"}}}');
419
-		$client = $this->createMock(IClient::class);
420
-		$this->clientService
421
-			->expects($this->once())
422
-			->method('newClient')
423
-			->willReturn($client);
424
-		$client
425
-			->expects($this->once())
426
-			->method('get')
427
-			->with($this->endpoint)
428
-			->willThrowException(new \Exception());
429
-
430
-		$this->assertSame([], $this->fetcher->get());
431
-	}
432
-
433
-	public function testGetMatchingETag(): void {
434
-		$this->config->method('getSystemValueString')
435
-			->willReturnCallback(function ($key, $default) {
436
-				if ($key === 'version') {
437
-					return '11.0.0.2';
438
-				} else {
439
-					return $default;
440
-				}
441
-			});
442
-		$this->config->method('getSystemValueBool')
443
-			->willReturnArgument(1);
444
-
445
-		$folder = $this->createMock(ISimpleFolder::class);
446
-		$file = $this->createMock(ISimpleFile::class);
447
-		$this->appData
448
-			->expects($this->once())
449
-			->method('getFolder')
450
-			->with('/')
451
-			->willReturn($folder);
452
-		$folder
453
-			->expects($this->once())
454
-			->method('getFile')
455
-			->with($this->fileName)
456
-			->willReturn($file);
457
-		$origData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1200,"ncversion":"11.0.0.2","ETag":"\"myETag\""}';
458
-
459
-		$newData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":4802,"ncversion":"11.0.0.2","ETag":"\"myETag\""}';
460
-		$file
461
-			->expects($this->once())
462
-			->method('putContent')
463
-			->with($newData);
464
-		$file
465
-			->expects($this->exactly(2))
466
-			->method('getContent')
467
-			->willReturnOnConsecutiveCalls(
468
-				$origData,
469
-				$newData,
470
-			);
471
-		$this->timeFactory
472
-			->expects($this->exactly(2))
473
-			->method('getTime')
474
-			->willReturnOnConsecutiveCalls(
475
-				4801,
476
-				4802
477
-			);
478
-		$client = $this->createMock(IClient::class);
479
-		$this->clientService
480
-			->expects($this->once())
481
-			->method('newClient')
482
-			->willReturn($client);
483
-		$response = $this->createMock(IResponse::class);
484
-		$client
485
-			->expects($this->once())
486
-			->method('get')
487
-			->with(
488
-				$this->equalTo($this->endpoint),
489
-				$this->equalTo([
490
-					'timeout' => 60,
491
-					'headers' => [
492
-						'If-None-Match' => '"myETag"'
493
-					]
494
-				])
495
-			)->willReturn($response);
496
-		$response->method('getStatusCode')
497
-			->willReturn(304);
498
-
499
-		$expected = [
500
-			[
501
-				'id' => 'MyNewApp',
502
-				'foo' => 'foo',
503
-			],
504
-			[
505
-				'id' => 'bar',
506
-			],
507
-		];
508
-
509
-		$this->assertSame($expected, $this->fetcher->get());
510
-	}
511
-
512
-	public function testGetNoMatchingETag(): void {
513
-		$this->config->method('getSystemValueString')
514
-			->willReturnCallback(function ($key, $default) {
515
-				if ($key === 'version') {
516
-					return '11.0.0.2';
517
-				} else {
518
-					return $default;
519
-				}
520
-			});
521
-		$this->config->method('getSystemValueBool')
522
-			->willReturnArgument(1);
523
-
524
-		$folder = $this->createMock(ISimpleFolder::class);
525
-		$file = $this->createMock(ISimpleFile::class);
526
-		$this->appData
527
-			->expects($this->once())
528
-			->method('getFolder')
529
-			->with('/')
530
-			->willReturn($folder);
531
-		$folder
532
-			->expects($this->once())
533
-			->method('getFile')
534
-			->with($this->fileName)
535
-			->willReturn($file);
536
-		$fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":4802,"ncversion":"11.0.0.2","ETag":"\"newETag\""}';
537
-		$file
538
-			->expects($this->once())
539
-			->method('putContent')
540
-			->with($fileData);
541
-		$file
542
-			->expects($this->exactly(2))
543
-			->method('getContent')
544
-			->willReturnOnConsecutiveCalls(
545
-				'{"data":[{"id":"MyOldApp","abc":"def"}],"timestamp":1200,"ncversion":"11.0.0.2","ETag":"\"myETag\""}',
546
-				$fileData,
547
-			);
548
-		$this->timeFactory
549
-			->expects($this->exactly(2))
550
-			->method('getTime')
551
-			->willReturnOnConsecutiveCalls(
552
-				4801,
553
-				4802,
554
-			);
555
-		$client = $this->createMock(IClient::class);
556
-		$this->clientService
557
-			->expects($this->once())
558
-			->method('newClient')
559
-			->willReturn($client);
560
-		$response = $this->createMock(IResponse::class);
561
-		$client
562
-			->expects($this->once())
563
-			->method('get')
564
-			->with(
565
-				$this->equalTo($this->endpoint),
566
-				$this->equalTo([
567
-					'timeout' => 60,
568
-					'headers' => [
569
-						'If-None-Match' => '"myETag"',
570
-					]
571
-				])
572
-			)
573
-			->willReturn($response);
574
-		$response->method('getStatusCode')
575
-			->willReturn(200);
576
-		$response
577
-			->expects($this->once())
578
-			->method('getBody')
579
-			->willReturn('[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}]');
580
-		$response->method('getHeader')
581
-			->with($this->equalTo('ETag'))
582
-			->willReturn('"newETag"');
583
-
584
-		$expected = [
585
-			[
586
-				'id' => 'MyNewApp',
587
-				'foo' => 'foo',
588
-			],
589
-			[
590
-				'id' => 'bar',
591
-			],
592
-		];
593
-		$this->assertSame($expected, $this->fetcher->get());
594
-	}
595
-
596
-
597
-	public function testFetchAfterUpgradeNoETag(): void {
598
-		$this->config->method('getSystemValueString')
599
-			->willReturnCallback(function ($key, $default) {
600
-				if ($key === 'version') {
601
-					return '11.0.0.3';
602
-				} else {
603
-					return $default;
604
-				}
605
-			});
606
-		$this->config->method('getSystemValueBool')
607
-			->willReturnArgument(1);
608
-
609
-		$folder = $this->createMock(ISimpleFolder::class);
610
-		$file = $this->createMock(ISimpleFile::class);
611
-		$this->appData
612
-			->expects($this->once())
613
-			->method('getFolder')
614
-			->with('/')
615
-			->willReturn($folder);
616
-		$folder
617
-			->expects($this->once())
618
-			->method('getFile')
619
-			->with($this->fileName)
620
-			->willReturn($file);
621
-		$fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1501,"ncversion":"11.0.0.3","ETag":"\"newETag\""}';
622
-		$file
623
-			->expects($this->once())
624
-			->method('putContent')
625
-			->with($fileData);
626
-		$file
627
-			->expects($this->exactly(2))
628
-			->method('getContent')
629
-			->willReturnOnConsecutiveCalls(
630
-				'{"data":[{"id":"MyOldApp","abc":"def"}],"timestamp":1200,"ncversion":"11.0.0.2","ETag":"\"myETag\""}',
631
-				$fileData
632
-			);
633
-		$client = $this->createMock(IClient::class);
634
-		$this->clientService
635
-			->expects($this->once())
636
-			->method('newClient')
637
-			->willReturn($client);
638
-		$response = $this->createMock(IResponse::class);
639
-		$client
640
-			->expects($this->once())
641
-			->method('get')
642
-			->with(
643
-				$this->equalTo($this->endpoint),
644
-				$this->equalTo([
645
-					'timeout' => 60,
646
-				])
647
-			)
648
-			->willReturn($response);
649
-		$response->method('getStatusCode')
650
-			->willReturn(200);
651
-		$response
652
-			->expects($this->once())
653
-			->method('getBody')
654
-			->willReturn('[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}]');
655
-		$response->method('getHeader')
656
-			->with($this->equalTo('ETag'))
657
-			->willReturn('"newETag"');
658
-		$this->timeFactory
659
-			->expects($this->once())
660
-			->method('getTime')
661
-			->willReturn(1501);
662
-
663
-		$expected = [
664
-			[
665
-				'id' => 'MyNewApp',
666
-				'foo' => 'foo',
667
-			],
668
-			[
669
-				'id' => 'bar',
670
-			],
671
-		];
672
-		$this->assertSame($expected, $this->fetcher->get());
673
-	}
26
+    /** @var Factory|\PHPUnit\Framework\MockObject\MockObject */
27
+    protected $appDataFactory;
28
+    /** @var IAppData|\PHPUnit\Framework\MockObject\MockObject */
29
+    protected $appData;
30
+    /** @var IClientService|\PHPUnit\Framework\MockObject\MockObject */
31
+    protected $clientService;
32
+    /** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
33
+    protected $timeFactory;
34
+    /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
35
+    protected $config;
36
+    /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
37
+    protected $logger;
38
+    /** @var IRegistry|\PHPUnit\Framework\MockObject\MockObject */
39
+    protected $registry;
40
+    /** @var Fetcher */
41
+    protected $fetcher;
42
+    /** @var string */
43
+    protected $fileName;
44
+    /** @var string */
45
+    protected $endpoint;
46
+
47
+    protected function setUp(): void {
48
+        parent::setUp();
49
+        $this->appDataFactory = $this->createMock(Factory::class);
50
+        $this->appData = $this->createMock(AppData::class);
51
+        $this->appDataFactory->expects($this->once())
52
+            ->method('get')
53
+            ->with('appstore')
54
+            ->willReturn($this->appData);
55
+        $this->clientService = $this->createMock(IClientService::class);
56
+        $this->timeFactory = $this->createMock(ITimeFactory::class);
57
+        $this->config = $this->createMock(IConfig::class);
58
+        $this->logger = $this->createMock(LoggerInterface::class);
59
+        $this->registry = $this->createMock(IRegistry::class);
60
+    }
61
+
62
+    public function testGetWithAlreadyExistingFileAndUpToDateTimestampAndVersion(): void {
63
+        $this->config
64
+            ->method('getSystemValueString')
65
+            ->willReturnCallback(function ($var, $default) {
66
+                if ($var === 'version') {
67
+                    return '11.0.0.2';
68
+                }
69
+                return $default;
70
+            });
71
+        $this->config->method('getSystemValueBool')
72
+            ->willReturnArgument(1);
73
+
74
+        $folder = $this->createMock(ISimpleFolder::class);
75
+        $file = $this->createMock(ISimpleFile::class);
76
+        $this->appData
77
+            ->expects($this->once())
78
+            ->method('getFolder')
79
+            ->with('/')
80
+            ->willReturn($folder);
81
+        $folder
82
+            ->expects($this->once())
83
+            ->method('getFile')
84
+            ->with($this->fileName)
85
+            ->willReturn($file);
86
+        $file
87
+            ->expects($this->once())
88
+            ->method('getContent')
89
+            ->willReturn('{"timestamp":1200,"data":[{"id":"MyApp"}],"ncversion":"11.0.0.2"}');
90
+        $this->timeFactory
91
+            ->expects($this->once())
92
+            ->method('getTime')
93
+            ->willReturn(1499);
94
+
95
+        $expected = [
96
+            [
97
+                'id' => 'MyApp',
98
+            ],
99
+        ];
100
+        $this->assertSame($expected, $this->fetcher->get());
101
+    }
102
+
103
+    public function testGetWithNotExistingFileAndUpToDateTimestampAndVersion(): void {
104
+        $this->config
105
+            ->method('getSystemValueString')
106
+            ->willReturnCallback(function ($var, $default) {
107
+                if ($var === 'appstoreurl') {
108
+                    return 'https://apps.nextcloud.com/api/v1';
109
+                } elseif ($var === 'version') {
110
+                    return '11.0.0.2';
111
+                }
112
+                return $default;
113
+            });
114
+        $this->config->method('getSystemValueBool')
115
+            ->willReturnArgument(1);
116
+
117
+        $folder = $this->createMock(ISimpleFolder::class);
118
+        $file = $this->createMock(ISimpleFile::class);
119
+        $this->appData
120
+            ->expects($this->once())
121
+            ->method('getFolder')
122
+            ->with('/')
123
+            ->willReturn($folder);
124
+        $folder
125
+            ->expects($this->once())
126
+            ->method('getFile')
127
+            ->with($this->fileName)
128
+            ->willThrowException(new NotFoundException());
129
+        $folder
130
+            ->expects($this->once())
131
+            ->method('newFile')
132
+            ->with($this->fileName)
133
+            ->willReturn($file);
134
+        $client = $this->createMock(IClient::class);
135
+        $this->clientService
136
+            ->expects($this->once())
137
+            ->method('newClient')
138
+            ->willReturn($client);
139
+        $response = $this->createMock(IResponse::class);
140
+        $client
141
+            ->expects($this->once())
142
+            ->method('get')
143
+            ->with($this->endpoint)
144
+            ->willReturn($response);
145
+        $response
146
+            ->expects($this->once())
147
+            ->method('getBody')
148
+            ->willReturn('[{"id":"MyNewApp", "foo": "foo"}, {"id":"bar"}]');
149
+        $response->method('getHeader')
150
+            ->with($this->equalTo('ETag'))
151
+            ->willReturn('"myETag"');
152
+        $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1502,"ncversion":"11.0.0.2","ETag":"\"myETag\""}';
153
+        $file
154
+            ->expects($this->once())
155
+            ->method('putContent')
156
+            ->with($fileData);
157
+        $file
158
+            ->expects($this->once())
159
+            ->method('getContent')
160
+            ->willReturn($fileData);
161
+        $this->timeFactory
162
+            ->expects($this->once())
163
+            ->method('getTime')
164
+            ->willReturn(1502);
165
+
166
+        $expected = [
167
+            [
168
+                'id' => 'MyNewApp',
169
+                'foo' => 'foo',
170
+            ],
171
+            [
172
+                'id' => 'bar',
173
+            ],
174
+        ];
175
+        $this->assertSame($expected, $this->fetcher->get());
176
+    }
177
+
178
+    public function testGetWithAlreadyExistingFileAndOutdatedTimestamp(): void {
179
+        $this->config->method('getSystemValueString')
180
+            ->willReturnCallback(function ($key, $default) {
181
+                if ($key === 'version') {
182
+                    return '11.0.0.2';
183
+                } else {
184
+                    return $default;
185
+                }
186
+            });
187
+        $this->config->method('getSystemValueBool')
188
+            ->willReturnArgument(1);
189
+
190
+        $folder = $this->createMock(ISimpleFolder::class);
191
+        $file = $this->createMock(ISimpleFile::class);
192
+        $this->appData
193
+            ->expects($this->once())
194
+            ->method('getFolder')
195
+            ->with('/')
196
+            ->willReturn($folder);
197
+        $folder
198
+            ->expects($this->once())
199
+            ->method('getFile')
200
+            ->with($this->fileName)
201
+            ->willReturn($file);
202
+        $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1502,"ncversion":"11.0.0.2","ETag":"\"myETag\""}';
203
+        $file
204
+            ->expects($this->once())
205
+            ->method('putContent')
206
+            ->with($fileData);
207
+        $file
208
+            ->expects($this->exactly(2))
209
+            ->method('getContent')
210
+            ->willReturnOnConsecutiveCalls(
211
+                '{"timestamp":1200,"data":{"MyApp":{"id":"MyApp"}},"ncversion":"11.0.0.2"}',
212
+                $fileData
213
+            );
214
+        $this->timeFactory
215
+            ->expects($this->exactly(2))
216
+            ->method('getTime')
217
+            ->willReturnOnConsecutiveCalls(
218
+                4801,
219
+                1502
220
+            );
221
+        $client = $this->createMock(IClient::class);
222
+        $this->clientService
223
+            ->expects($this->once())
224
+            ->method('newClient')
225
+            ->willReturn($client);
226
+        $response = $this->createMock(IResponse::class);
227
+        $client
228
+            ->expects($this->once())
229
+            ->method('get')
230
+            ->with($this->endpoint)
231
+            ->willReturn($response);
232
+        $response
233
+            ->expects($this->once())
234
+            ->method('getBody')
235
+            ->willReturn('[{"id":"MyNewApp", "foo": "foo"}, {"id":"bar"}]');
236
+        $response->method('getHeader')
237
+            ->with($this->equalTo('ETag'))
238
+            ->willReturn('"myETag"');
239
+
240
+        $expected = [
241
+            [
242
+                'id' => 'MyNewApp',
243
+                'foo' => 'foo',
244
+            ],
245
+            [
246
+                'id' => 'bar',
247
+            ],
248
+        ];
249
+        $this->assertSame($expected, $this->fetcher->get());
250
+    }
251
+
252
+    public function testGetWithAlreadyExistingFileAndNoVersion(): void {
253
+        $this->config
254
+            ->method('getSystemValueString')
255
+            ->willReturnCallback(function ($var, $default) {
256
+                if ($var === 'appstoreurl') {
257
+                    return 'https://apps.nextcloud.com/api/v1';
258
+                } elseif ($var === 'version') {
259
+                    return '11.0.0.2';
260
+                }
261
+                return $default;
262
+            });
263
+        $this->config->method('getSystemValueBool')
264
+            ->willReturnArgument(1);
265
+
266
+        $folder = $this->createMock(ISimpleFolder::class);
267
+        $file = $this->createMock(ISimpleFile::class);
268
+        $this->appData
269
+            ->expects($this->once())
270
+            ->method('getFolder')
271
+            ->with('/')
272
+            ->willReturn($folder);
273
+        $folder
274
+            ->expects($this->once())
275
+            ->method('getFile')
276
+            ->with($this->fileName)
277
+            ->willReturn($file);
278
+        $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1201,"ncversion":"11.0.0.2","ETag":"\"myETag\""}';
279
+        $file
280
+            ->expects($this->once())
281
+            ->method('putContent')
282
+            ->with($fileData);
283
+        $file
284
+            ->expects($this->exactly(2))
285
+            ->method('getContent')
286
+            ->willReturnOnConsecutiveCalls(
287
+                '{"timestamp":1200,"data":{"MyApp":{"id":"MyApp"}}',
288
+                $fileData
289
+            );
290
+        $this->timeFactory
291
+            ->expects($this->once())
292
+            ->method('getTime')
293
+            ->willReturn(1201);
294
+        $client = $this->createMock(IClient::class);
295
+        $this->clientService
296
+            ->expects($this->once())
297
+            ->method('newClient')
298
+            ->willReturn($client);
299
+        $response = $this->createMock(IResponse::class);
300
+        $client
301
+            ->expects($this->once())
302
+            ->method('get')
303
+            ->with($this->endpoint)
304
+            ->willReturn($response);
305
+        $response
306
+            ->expects($this->once())
307
+            ->method('getBody')
308
+            ->willReturn('[{"id":"MyNewApp", "foo": "foo"}, {"id":"bar"}]');
309
+        $response->method('getHeader')
310
+            ->with($this->equalTo('ETag'))
311
+            ->willReturn('"myETag"');
312
+
313
+        $expected = [
314
+            [
315
+                'id' => 'MyNewApp',
316
+                'foo' => 'foo',
317
+            ],
318
+            [
319
+                'id' => 'bar',
320
+            ],
321
+        ];
322
+        $this->assertSame($expected, $this->fetcher->get());
323
+    }
324
+
325
+    public function testGetWithAlreadyExistingFileAndOutdatedVersion(): void {
326
+        $this->config
327
+            ->method('getSystemValueString')
328
+            ->willReturnCallback(function ($var, $default) {
329
+                if ($var === 'appstoreurl') {
330
+                    return 'https://apps.nextcloud.com/api/v1';
331
+                } elseif ($var === 'version') {
332
+                    return '11.0.0.2';
333
+                }
334
+                return $default;
335
+            });
336
+        $this->config->method('getSystemValueBool')
337
+            ->willReturnArgument(1);
338
+
339
+        $folder = $this->createMock(ISimpleFolder::class);
340
+        $file = $this->createMock(ISimpleFile::class);
341
+        $this->appData
342
+            ->expects($this->once())
343
+            ->method('getFolder')
344
+            ->with('/')
345
+            ->willReturn($folder);
346
+        $folder
347
+            ->expects($this->once())
348
+            ->method('getFile')
349
+            ->with($this->fileName)
350
+            ->willReturn($file);
351
+        $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1201,"ncversion":"11.0.0.2","ETag":"\"myETag\""}';
352
+        $file
353
+            ->expects($this->once())
354
+            ->method('putContent')
355
+            ->with($fileData);
356
+        $file
357
+            ->expects($this->exactly(2))
358
+            ->method('getContent')
359
+            ->willReturnOnConsecutiveCalls(
360
+                '{"timestamp":1200,"data":{"MyApp":{"id":"MyApp"}},"ncversion":"11.0.0.1"',
361
+                $fileData
362
+            );
363
+        $this->timeFactory
364
+            ->method('getTime')
365
+            ->willReturn(1201);
366
+        $client = $this->createMock(IClient::class);
367
+        $this->clientService
368
+            ->expects($this->once())
369
+            ->method('newClient')
370
+            ->willReturn($client);
371
+        $response = $this->createMock(IResponse::class);
372
+        $client
373
+            ->expects($this->once())
374
+            ->method('get')
375
+            ->with($this->endpoint)
376
+            ->willReturn($response);
377
+        $response
378
+            ->expects($this->once())
379
+            ->method('getBody')
380
+            ->willReturn('[{"id":"MyNewApp", "foo": "foo"}, {"id":"bar"}]');
381
+        $response->method('getHeader')
382
+            ->with($this->equalTo('ETag'))
383
+            ->willReturn('"myETag"');
384
+
385
+        $expected = [
386
+            [
387
+                'id' => 'MyNewApp',
388
+                'foo' => 'foo',
389
+            ],
390
+            [
391
+                'id' => 'bar',
392
+            ],
393
+        ];
394
+        $this->assertSame($expected, $this->fetcher->get());
395
+    }
396
+
397
+    public function testGetWithExceptionInClient(): void {
398
+        $this->config->method('getSystemValueString')
399
+            ->willReturnArgument(1);
400
+        $this->config->method('getSystemValueBool')
401
+            ->willReturnArgument(1);
402
+
403
+        $folder = $this->createMock(ISimpleFolder::class);
404
+        $file = $this->createMock(ISimpleFile::class);
405
+        $this->appData
406
+            ->expects($this->once())
407
+            ->method('getFolder')
408
+            ->with('/')
409
+            ->willReturn($folder);
410
+        $folder
411
+            ->expects($this->once())
412
+            ->method('getFile')
413
+            ->with($this->fileName)
414
+            ->willReturn($file);
415
+        $file
416
+            ->expects($this->once())
417
+            ->method('getContent')
418
+            ->willReturn('{"timestamp":1200,"data":{"MyApp":{"id":"MyApp"}}}');
419
+        $client = $this->createMock(IClient::class);
420
+        $this->clientService
421
+            ->expects($this->once())
422
+            ->method('newClient')
423
+            ->willReturn($client);
424
+        $client
425
+            ->expects($this->once())
426
+            ->method('get')
427
+            ->with($this->endpoint)
428
+            ->willThrowException(new \Exception());
429
+
430
+        $this->assertSame([], $this->fetcher->get());
431
+    }
432
+
433
+    public function testGetMatchingETag(): void {
434
+        $this->config->method('getSystemValueString')
435
+            ->willReturnCallback(function ($key, $default) {
436
+                if ($key === 'version') {
437
+                    return '11.0.0.2';
438
+                } else {
439
+                    return $default;
440
+                }
441
+            });
442
+        $this->config->method('getSystemValueBool')
443
+            ->willReturnArgument(1);
444
+
445
+        $folder = $this->createMock(ISimpleFolder::class);
446
+        $file = $this->createMock(ISimpleFile::class);
447
+        $this->appData
448
+            ->expects($this->once())
449
+            ->method('getFolder')
450
+            ->with('/')
451
+            ->willReturn($folder);
452
+        $folder
453
+            ->expects($this->once())
454
+            ->method('getFile')
455
+            ->with($this->fileName)
456
+            ->willReturn($file);
457
+        $origData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1200,"ncversion":"11.0.0.2","ETag":"\"myETag\""}';
458
+
459
+        $newData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":4802,"ncversion":"11.0.0.2","ETag":"\"myETag\""}';
460
+        $file
461
+            ->expects($this->once())
462
+            ->method('putContent')
463
+            ->with($newData);
464
+        $file
465
+            ->expects($this->exactly(2))
466
+            ->method('getContent')
467
+            ->willReturnOnConsecutiveCalls(
468
+                $origData,
469
+                $newData,
470
+            );
471
+        $this->timeFactory
472
+            ->expects($this->exactly(2))
473
+            ->method('getTime')
474
+            ->willReturnOnConsecutiveCalls(
475
+                4801,
476
+                4802
477
+            );
478
+        $client = $this->createMock(IClient::class);
479
+        $this->clientService
480
+            ->expects($this->once())
481
+            ->method('newClient')
482
+            ->willReturn($client);
483
+        $response = $this->createMock(IResponse::class);
484
+        $client
485
+            ->expects($this->once())
486
+            ->method('get')
487
+            ->with(
488
+                $this->equalTo($this->endpoint),
489
+                $this->equalTo([
490
+                    'timeout' => 60,
491
+                    'headers' => [
492
+                        'If-None-Match' => '"myETag"'
493
+                    ]
494
+                ])
495
+            )->willReturn($response);
496
+        $response->method('getStatusCode')
497
+            ->willReturn(304);
498
+
499
+        $expected = [
500
+            [
501
+                'id' => 'MyNewApp',
502
+                'foo' => 'foo',
503
+            ],
504
+            [
505
+                'id' => 'bar',
506
+            ],
507
+        ];
508
+
509
+        $this->assertSame($expected, $this->fetcher->get());
510
+    }
511
+
512
+    public function testGetNoMatchingETag(): void {
513
+        $this->config->method('getSystemValueString')
514
+            ->willReturnCallback(function ($key, $default) {
515
+                if ($key === 'version') {
516
+                    return '11.0.0.2';
517
+                } else {
518
+                    return $default;
519
+                }
520
+            });
521
+        $this->config->method('getSystemValueBool')
522
+            ->willReturnArgument(1);
523
+
524
+        $folder = $this->createMock(ISimpleFolder::class);
525
+        $file = $this->createMock(ISimpleFile::class);
526
+        $this->appData
527
+            ->expects($this->once())
528
+            ->method('getFolder')
529
+            ->with('/')
530
+            ->willReturn($folder);
531
+        $folder
532
+            ->expects($this->once())
533
+            ->method('getFile')
534
+            ->with($this->fileName)
535
+            ->willReturn($file);
536
+        $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":4802,"ncversion":"11.0.0.2","ETag":"\"newETag\""}';
537
+        $file
538
+            ->expects($this->once())
539
+            ->method('putContent')
540
+            ->with($fileData);
541
+        $file
542
+            ->expects($this->exactly(2))
543
+            ->method('getContent')
544
+            ->willReturnOnConsecutiveCalls(
545
+                '{"data":[{"id":"MyOldApp","abc":"def"}],"timestamp":1200,"ncversion":"11.0.0.2","ETag":"\"myETag\""}',
546
+                $fileData,
547
+            );
548
+        $this->timeFactory
549
+            ->expects($this->exactly(2))
550
+            ->method('getTime')
551
+            ->willReturnOnConsecutiveCalls(
552
+                4801,
553
+                4802,
554
+            );
555
+        $client = $this->createMock(IClient::class);
556
+        $this->clientService
557
+            ->expects($this->once())
558
+            ->method('newClient')
559
+            ->willReturn($client);
560
+        $response = $this->createMock(IResponse::class);
561
+        $client
562
+            ->expects($this->once())
563
+            ->method('get')
564
+            ->with(
565
+                $this->equalTo($this->endpoint),
566
+                $this->equalTo([
567
+                    'timeout' => 60,
568
+                    'headers' => [
569
+                        'If-None-Match' => '"myETag"',
570
+                    ]
571
+                ])
572
+            )
573
+            ->willReturn($response);
574
+        $response->method('getStatusCode')
575
+            ->willReturn(200);
576
+        $response
577
+            ->expects($this->once())
578
+            ->method('getBody')
579
+            ->willReturn('[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}]');
580
+        $response->method('getHeader')
581
+            ->with($this->equalTo('ETag'))
582
+            ->willReturn('"newETag"');
583
+
584
+        $expected = [
585
+            [
586
+                'id' => 'MyNewApp',
587
+                'foo' => 'foo',
588
+            ],
589
+            [
590
+                'id' => 'bar',
591
+            ],
592
+        ];
593
+        $this->assertSame($expected, $this->fetcher->get());
594
+    }
595
+
596
+
597
+    public function testFetchAfterUpgradeNoETag(): void {
598
+        $this->config->method('getSystemValueString')
599
+            ->willReturnCallback(function ($key, $default) {
600
+                if ($key === 'version') {
601
+                    return '11.0.0.3';
602
+                } else {
603
+                    return $default;
604
+                }
605
+            });
606
+        $this->config->method('getSystemValueBool')
607
+            ->willReturnArgument(1);
608
+
609
+        $folder = $this->createMock(ISimpleFolder::class);
610
+        $file = $this->createMock(ISimpleFile::class);
611
+        $this->appData
612
+            ->expects($this->once())
613
+            ->method('getFolder')
614
+            ->with('/')
615
+            ->willReturn($folder);
616
+        $folder
617
+            ->expects($this->once())
618
+            ->method('getFile')
619
+            ->with($this->fileName)
620
+            ->willReturn($file);
621
+        $fileData = '{"data":[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}],"timestamp":1501,"ncversion":"11.0.0.3","ETag":"\"newETag\""}';
622
+        $file
623
+            ->expects($this->once())
624
+            ->method('putContent')
625
+            ->with($fileData);
626
+        $file
627
+            ->expects($this->exactly(2))
628
+            ->method('getContent')
629
+            ->willReturnOnConsecutiveCalls(
630
+                '{"data":[{"id":"MyOldApp","abc":"def"}],"timestamp":1200,"ncversion":"11.0.0.2","ETag":"\"myETag\""}',
631
+                $fileData
632
+            );
633
+        $client = $this->createMock(IClient::class);
634
+        $this->clientService
635
+            ->expects($this->once())
636
+            ->method('newClient')
637
+            ->willReturn($client);
638
+        $response = $this->createMock(IResponse::class);
639
+        $client
640
+            ->expects($this->once())
641
+            ->method('get')
642
+            ->with(
643
+                $this->equalTo($this->endpoint),
644
+                $this->equalTo([
645
+                    'timeout' => 60,
646
+                ])
647
+            )
648
+            ->willReturn($response);
649
+        $response->method('getStatusCode')
650
+            ->willReturn(200);
651
+        $response
652
+            ->expects($this->once())
653
+            ->method('getBody')
654
+            ->willReturn('[{"id":"MyNewApp","foo":"foo"},{"id":"bar"}]');
655
+        $response->method('getHeader')
656
+            ->with($this->equalTo('ETag'))
657
+            ->willReturn('"newETag"');
658
+        $this->timeFactory
659
+            ->expects($this->once())
660
+            ->method('getTime')
661
+            ->willReturn(1501);
662
+
663
+        $expected = [
664
+            [
665
+                'id' => 'MyNewApp',
666
+                'foo' => 'foo',
667
+            ],
668
+            [
669
+                'id' => 'bar',
670
+            ],
671
+        ];
672
+        $this->assertSame($expected, $this->fetcher->get());
673
+    }
674 674
 }
Please login to merge, or discard this patch.