@@ -17,43 +17,43 @@ |
||
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 | } |
@@ -9,16 +9,16 @@ |
||
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 | } |
@@ -9,19 +9,19 @@ |
||
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 | } |
@@ -23,652 +23,652 @@ |
||
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 | } |
@@ -10,13 +10,13 @@ |
||
10 | 10 | use Test\TestCase; |
11 | 11 | |
12 | 12 | class VersionTest extends TestCase { |
13 | - public function testGetMinimumVersion(): void { |
|
14 | - $version = new Version('9', '10'); |
|
15 | - $this->assertSame('9', $version->getMinimumVersion()); |
|
16 | - } |
|
13 | + public function testGetMinimumVersion(): void { |
|
14 | + $version = new Version('9', '10'); |
|
15 | + $this->assertSame('9', $version->getMinimumVersion()); |
|
16 | + } |
|
17 | 17 | |
18 | - public function testGetMaximumVersion(): void { |
|
19 | - $version = new Version('9', '10'); |
|
20 | - $this->assertSame('10', $version->getMaximumVersion()); |
|
21 | - } |
|
18 | + public function testGetMaximumVersion(): void { |
|
19 | + $version = new Version('9', '10'); |
|
20 | + $this->assertSame('10', $version->getMaximumVersion()); |
|
21 | + } |
|
22 | 22 | } |
@@ -11,95 +11,95 @@ |
||
11 | 11 | use OCP\Http\Client\IResponse; |
12 | 12 | |
13 | 13 | trait ClientServiceTrait { |
14 | - /** @var IClientService|\PHPUnit\Framework\MockObject\MockObject */ |
|
15 | - private $clientService; |
|
16 | - /** @var IClient|\PHPUnit\Framework\MockObject\MockObject */ |
|
17 | - private $client; |
|
18 | - private $expectedGetRequests = []; |
|
19 | - private $expectedPostRequests = []; |
|
14 | + /** @var IClientService|\PHPUnit\Framework\MockObject\MockObject */ |
|
15 | + private $clientService; |
|
16 | + /** @var IClient|\PHPUnit\Framework\MockObject\MockObject */ |
|
17 | + private $client; |
|
18 | + private $expectedGetRequests = []; |
|
19 | + private $expectedPostRequests = []; |
|
20 | 20 | |
21 | - /** |
|
22 | - * Wrapper to be forward compatible to phpunit 5.4+ |
|
23 | - * |
|
24 | - * @param string $originalClassName |
|
25 | - * @return \PHPUnit\Framework\MockObject\MockObject |
|
26 | - */ |
|
27 | - abstract protected function createMock(string $originalClassName); |
|
21 | + /** |
|
22 | + * Wrapper to be forward compatible to phpunit 5.4+ |
|
23 | + * |
|
24 | + * @param string $originalClassName |
|
25 | + * @return \PHPUnit\Framework\MockObject\MockObject |
|
26 | + */ |
|
27 | + abstract protected function createMock(string $originalClassName); |
|
28 | 28 | |
29 | - /** |
|
30 | - * Returns a matcher that matches when the method is executed |
|
31 | - * zero or more times. |
|
32 | - * |
|
33 | - * @return \PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount |
|
34 | - * |
|
35 | - * @since Method available since Release 3.0.0 |
|
36 | - */ |
|
37 | - abstract public static function any(); |
|
29 | + /** |
|
30 | + * Returns a matcher that matches when the method is executed |
|
31 | + * zero or more times. |
|
32 | + * |
|
33 | + * @return \PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount |
|
34 | + * |
|
35 | + * @since Method available since Release 3.0.0 |
|
36 | + */ |
|
37 | + abstract public static function any(); |
|
38 | 38 | |
39 | - protected function setUpClientServiceTrait() { |
|
40 | - $this->clientService = $this->createMock(IClientService::class); |
|
41 | - $this->client = $this->createMock(IClient::class); |
|
42 | - $this->clientService->expects($this->any()) |
|
43 | - ->method('newClient') |
|
44 | - ->willReturn($this->client); |
|
45 | - $this->client->expects($this->any()) |
|
46 | - ->method('get') |
|
47 | - ->willReturnCallback(function ($url) { |
|
48 | - if (!isset($this->expectedGetRequests[$url])) { |
|
49 | - throw new \Exception('unexpected request: ' . $url); |
|
50 | - } |
|
51 | - $result = $this->expectedGetRequests[$url]; |
|
39 | + protected function setUpClientServiceTrait() { |
|
40 | + $this->clientService = $this->createMock(IClientService::class); |
|
41 | + $this->client = $this->createMock(IClient::class); |
|
42 | + $this->clientService->expects($this->any()) |
|
43 | + ->method('newClient') |
|
44 | + ->willReturn($this->client); |
|
45 | + $this->client->expects($this->any()) |
|
46 | + ->method('get') |
|
47 | + ->willReturnCallback(function ($url) { |
|
48 | + if (!isset($this->expectedGetRequests[$url])) { |
|
49 | + throw new \Exception('unexpected request: ' . $url); |
|
50 | + } |
|
51 | + $result = $this->expectedGetRequests[$url]; |
|
52 | 52 | |
53 | - if ($result instanceof \Exception) { |
|
54 | - throw $result; |
|
55 | - } else { |
|
56 | - $response = $this->createMock(IResponse::class); |
|
57 | - $response->expects($this->any()) |
|
58 | - ->method('getBody') |
|
59 | - ->willReturn($result); |
|
60 | - return $response; |
|
61 | - } |
|
62 | - }); |
|
63 | - $this->client->expects($this->any()) |
|
64 | - ->method('post') |
|
65 | - ->willReturnCallback(function ($url) { |
|
66 | - if (!isset($this->expectedPostRequests[$url])) { |
|
67 | - throw new \Exception('unexpected request: ' . $url); |
|
68 | - } |
|
69 | - $result = $this->expectedPostRequests[$url]; |
|
53 | + if ($result instanceof \Exception) { |
|
54 | + throw $result; |
|
55 | + } else { |
|
56 | + $response = $this->createMock(IResponse::class); |
|
57 | + $response->expects($this->any()) |
|
58 | + ->method('getBody') |
|
59 | + ->willReturn($result); |
|
60 | + return $response; |
|
61 | + } |
|
62 | + }); |
|
63 | + $this->client->expects($this->any()) |
|
64 | + ->method('post') |
|
65 | + ->willReturnCallback(function ($url) { |
|
66 | + if (!isset($this->expectedPostRequests[$url])) { |
|
67 | + throw new \Exception('unexpected request: ' . $url); |
|
68 | + } |
|
69 | + $result = $this->expectedPostRequests[$url]; |
|
70 | 70 | |
71 | - if ($result instanceof \Exception) { |
|
72 | - throw $result; |
|
73 | - } else { |
|
74 | - $response = $this->createMock(IResponse::class); |
|
75 | - $response->expects($this->any()) |
|
76 | - ->method('getBody') |
|
77 | - ->willReturn($result); |
|
78 | - return $response; |
|
79 | - } |
|
80 | - }); |
|
81 | - } |
|
71 | + if ($result instanceof \Exception) { |
|
72 | + throw $result; |
|
73 | + } else { |
|
74 | + $response = $this->createMock(IResponse::class); |
|
75 | + $response->expects($this->any()) |
|
76 | + ->method('getBody') |
|
77 | + ->willReturn($result); |
|
78 | + return $response; |
|
79 | + } |
|
80 | + }); |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * @param string $url |
|
85 | - * @param string|\Exception $result |
|
86 | - */ |
|
87 | - protected function expectGetRequest($url, $result) { |
|
88 | - $this->expectedGetRequests[$url] = $result; |
|
89 | - } |
|
83 | + /** |
|
84 | + * @param string $url |
|
85 | + * @param string|\Exception $result |
|
86 | + */ |
|
87 | + protected function expectGetRequest($url, $result) { |
|
88 | + $this->expectedGetRequests[$url] = $result; |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @param string $url |
|
93 | - * @param string|\Exception $result |
|
94 | - */ |
|
95 | - protected function expectPostRequest($url, $result) { |
|
96 | - $this->expectedPostRequests[$url] = $result; |
|
97 | - } |
|
91 | + /** |
|
92 | + * @param string $url |
|
93 | + * @param string|\Exception $result |
|
94 | + */ |
|
95 | + protected function expectPostRequest($url, $result) { |
|
96 | + $this->expectedPostRequests[$url] = $result; |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * @return IClientService|\PHPUnit\Framework\MockObject\MockObject |
|
101 | - */ |
|
102 | - protected function getClientService() { |
|
103 | - return $this->clientService; |
|
104 | - } |
|
99 | + /** |
|
100 | + * @return IClientService|\PHPUnit\Framework\MockObject\MockObject |
|
101 | + */ |
|
102 | + protected function getClientService() { |
|
103 | + return $this->clientService; |
|
104 | + } |
|
105 | 105 | } |
@@ -14,15 +14,15 @@ |
||
14 | 14 | use Test\TestCase; |
15 | 15 | |
16 | 16 | class AddFeaturePolicyEventTest extends TestCase { |
17 | - public function testAddEvent(): void { |
|
18 | - $manager = $this->createMock(FeaturePolicyManager::class); |
|
19 | - $policy = $this->createMock(FeaturePolicy::class); |
|
20 | - $event = new AddFeaturePolicyEvent($manager); |
|
17 | + public function testAddEvent(): void { |
|
18 | + $manager = $this->createMock(FeaturePolicyManager::class); |
|
19 | + $policy = $this->createMock(FeaturePolicy::class); |
|
20 | + $event = new AddFeaturePolicyEvent($manager); |
|
21 | 21 | |
22 | - $manager->expects($this->once()) |
|
23 | - ->method('addDefaultPolicy') |
|
24 | - ->with($policy); |
|
22 | + $manager->expects($this->once()) |
|
23 | + ->method('addDefaultPolicy') |
|
24 | + ->with($policy); |
|
25 | 25 | |
26 | - $event->addPolicy($policy); |
|
27 | - } |
|
26 | + $event->addPolicy($policy); |
|
27 | + } |
|
28 | 28 | } |
@@ -18,8 +18,8 @@ discard block |
||
18 | 18 | use Test\TestCase; |
19 | 19 | |
20 | 20 | class SignerTest extends TestCase { |
21 | - /** @var string */ |
|
22 | - private $private = '-----BEGIN PRIVATE KEY----- |
|
21 | + /** @var string */ |
|
22 | + private $private = '-----BEGIN PRIVATE KEY----- |
|
23 | 23 | MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDImc6QvHBjBIoo |
24 | 24 | w9nnywiPNESleUuFJ2yQ3Gd/3w2BkblojlUAJAsUd/bQokjOH9d+7nqyzgSiXjRl |
25 | 25 | iwKagY6NjcNEEq0X5KOMNwx6uEbtq3+7pA7H2JefNrnAuD+Fhp3Hyo3h1cse6hAq |
@@ -48,8 +48,8 @@ discard block |
||
48 | 48 | kC6HCb+CXsMRD7yp8KrrYnw= |
49 | 49 | -----END PRIVATE KEY-----'; |
50 | 50 | |
51 | - /** @var string */ |
|
52 | - private $public = '-----BEGIN PUBLIC KEY----- |
|
51 | + /** @var string */ |
|
52 | + private $public = '-----BEGIN PUBLIC KEY----- |
|
53 | 53 | MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyJnOkLxwYwSKKMPZ58sI |
54 | 54 | jzREpXlLhSdskNxnf98NgZG5aI5VACQLFHf20KJIzh/Xfu56ss4Eol40ZYsCmoGO |
55 | 55 | jY3DRBKtF+SjjDcMerhG7at/u6QOx9iXnza5wLg/hYadx8qN4dXLHuoQKuma/IWg |
@@ -59,130 +59,130 @@ discard block |
||
59 | 59 | gQIDAQAB |
60 | 60 | -----END PUBLIC KEY-----'; |
61 | 61 | |
62 | - /** @var Key */ |
|
63 | - private $key; |
|
64 | - |
|
65 | - /** @var Manager|\PHPUnit\Framework\MockObject\MockObject */ |
|
66 | - private $keyManager; |
|
67 | - |
|
68 | - /** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */ |
|
69 | - private $timeFactory; |
|
70 | - |
|
71 | - /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
72 | - private $userManager; |
|
73 | - |
|
74 | - /** @var Signer */ |
|
75 | - private $signer; |
|
76 | - |
|
77 | - protected function setUp(): void { |
|
78 | - parent::setUp(); |
|
79 | - |
|
80 | - $this->key = new Key($this->public, $this->private); |
|
81 | - |
|
82 | - $this->keyManager = $this->createMock(Manager::class); |
|
83 | - $this->timeFactory = $this->createMock(ITimeFactory::class); |
|
84 | - $this->userManager = $this->createMock(IUserManager::class); |
|
85 | - |
|
86 | - $this->signer = new Signer( |
|
87 | - $this->keyManager, |
|
88 | - $this->timeFactory, |
|
89 | - $this->userManager |
|
90 | - ); |
|
91 | - } |
|
92 | - |
|
93 | - public function testSign(): void { |
|
94 | - $user = $this->createMock(IUser::class); |
|
95 | - $user->method('getCloudId') |
|
96 | - ->willReturn('[email protected]'); |
|
97 | - |
|
98 | - $this->timeFactory->method('getTime') |
|
99 | - ->willReturn(42); |
|
100 | - |
|
101 | - $this->keyManager->method('getKey') |
|
102 | - ->with($this->equalTo($user)) |
|
103 | - ->willReturn($this->key); |
|
104 | - |
|
105 | - $data = [ |
|
106 | - 'foo' => 'bar', |
|
107 | - 'abc' => 'def', |
|
108 | - 'xyz' => 123, |
|
109 | - ]; |
|
110 | - |
|
111 | - $expects = [ |
|
112 | - 'message' => [ |
|
113 | - 'data' => $data, |
|
114 | - 'type' => 'myType', |
|
115 | - 'signer' => '[email protected]', |
|
116 | - 'timestamp' => 42, |
|
117 | - ], |
|
118 | - 'signature' => 'E1fNdoWMX1QmSyKv+S3FtOgLe9niYGQFWOKGaMLxc2h7s3V++EIqJvw/NCLBfrUowzWkTzhkjfbHaf88Hz34WAn4sAwXYAO8cnboQs6SClKRzQ/nvbtLgd2wm9RQ8UTOM7wR6C7HpIn4qqJ4BTQ1bAwYAiJ2GoK+W8wC0o0Gpub2906j3JJ4cbc9lufd5ohWKCev8Ubem/EEKaRIZA7qHh+Q1MKXTaJQJlCjTMe5PyGy0fsmtVxsPls3/Fkd9sVeHEHSYHzOiF6ttlxWou4TdRbq3WSEVpt1DOOvkKI9w2+zBJ7IPH8CnVpXcdIzWDctUygZKzNMUQnweDOOziEdUw==' |
|
119 | - ]; |
|
120 | - |
|
121 | - $result = $this->signer->sign('myType', $data, $user); |
|
122 | - |
|
123 | - $this->assertEquals($expects, $result); |
|
124 | - } |
|
125 | - |
|
126 | - public function testVerifyValid(): void { |
|
127 | - $data = [ |
|
128 | - 'message' => [ |
|
129 | - 'data' => [ |
|
130 | - 'foo' => 'bar', |
|
131 | - 'abc' => 'def', |
|
132 | - 'xyz' => 123, |
|
133 | - ], |
|
134 | - 'type' => 'myType', |
|
135 | - 'signer' => '[email protected]', |
|
136 | - 'timestamp' => 42, |
|
137 | - ], |
|
138 | - 'signature' => 'E1fNdoWMX1QmSyKv+S3FtOgLe9niYGQFWOKGaMLxc2h7s3V++EIqJvw/NCLBfrUowzWkTzhkjfbHaf88Hz34WAn4sAwXYAO8cnboQs6SClKRzQ/nvbtLgd2wm9RQ8UTOM7wR6C7HpIn4qqJ4BTQ1bAwYAiJ2GoK+W8wC0o0Gpub2906j3JJ4cbc9lufd5ohWKCev8Ubem/EEKaRIZA7qHh+Q1MKXTaJQJlCjTMe5PyGy0fsmtVxsPls3/Fkd9sVeHEHSYHzOiF6ttlxWou4TdRbq3WSEVpt1DOOvkKI9w2+zBJ7IPH8CnVpXcdIzWDctUygZKzNMUQnweDOOziEdUw==' |
|
139 | - ]; |
|
140 | - |
|
141 | - $user = $this->createMock(IUser::class); |
|
142 | - |
|
143 | - $this->keyManager->method('getKey') |
|
144 | - ->with($this->equalTo($user)) |
|
145 | - ->willReturn($this->key); |
|
146 | - |
|
147 | - $this->userManager->method('get') |
|
148 | - ->with('foo') |
|
149 | - ->willReturn($user); |
|
150 | - |
|
151 | - $this->assertTrue($this->signer->verify($data)); |
|
152 | - } |
|
153 | - |
|
154 | - public function testVerifyInvalid(): void { |
|
155 | - $data = [ |
|
156 | - 'message' => [ |
|
157 | - 'data' => [ |
|
158 | - 'foo' => 'bar', |
|
159 | - 'abc' => 'def', |
|
160 | - 'xyz' => 123, |
|
161 | - ], |
|
162 | - 'type' => 'myType', |
|
163 | - 'signer' => '[email protected]', |
|
164 | - 'timestamp' => 42, |
|
165 | - ], |
|
166 | - 'signature' => 'Invalid sig' |
|
167 | - ]; |
|
168 | - |
|
169 | - $user = $this->createMock(IUser::class); |
|
170 | - |
|
171 | - $this->keyManager->method('getKey') |
|
172 | - ->with($this->equalTo($user)) |
|
173 | - ->willReturn($this->key); |
|
174 | - |
|
175 | - $this->userManager->method('get') |
|
176 | - ->with('foo') |
|
177 | - ->willReturn($user); |
|
178 | - |
|
179 | - $this->assertFalse($this->signer->verify($data)); |
|
180 | - } |
|
181 | - |
|
182 | - public function testVerifyInvalidData(): void { |
|
183 | - $data = [ |
|
184 | - ]; |
|
185 | - |
|
186 | - $this->assertFalse($this->signer->verify($data)); |
|
187 | - } |
|
62 | + /** @var Key */ |
|
63 | + private $key; |
|
64 | + |
|
65 | + /** @var Manager|\PHPUnit\Framework\MockObject\MockObject */ |
|
66 | + private $keyManager; |
|
67 | + |
|
68 | + /** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */ |
|
69 | + private $timeFactory; |
|
70 | + |
|
71 | + /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
72 | + private $userManager; |
|
73 | + |
|
74 | + /** @var Signer */ |
|
75 | + private $signer; |
|
76 | + |
|
77 | + protected function setUp(): void { |
|
78 | + parent::setUp(); |
|
79 | + |
|
80 | + $this->key = new Key($this->public, $this->private); |
|
81 | + |
|
82 | + $this->keyManager = $this->createMock(Manager::class); |
|
83 | + $this->timeFactory = $this->createMock(ITimeFactory::class); |
|
84 | + $this->userManager = $this->createMock(IUserManager::class); |
|
85 | + |
|
86 | + $this->signer = new Signer( |
|
87 | + $this->keyManager, |
|
88 | + $this->timeFactory, |
|
89 | + $this->userManager |
|
90 | + ); |
|
91 | + } |
|
92 | + |
|
93 | + public function testSign(): void { |
|
94 | + $user = $this->createMock(IUser::class); |
|
95 | + $user->method('getCloudId') |
|
96 | + ->willReturn('[email protected]'); |
|
97 | + |
|
98 | + $this->timeFactory->method('getTime') |
|
99 | + ->willReturn(42); |
|
100 | + |
|
101 | + $this->keyManager->method('getKey') |
|
102 | + ->with($this->equalTo($user)) |
|
103 | + ->willReturn($this->key); |
|
104 | + |
|
105 | + $data = [ |
|
106 | + 'foo' => 'bar', |
|
107 | + 'abc' => 'def', |
|
108 | + 'xyz' => 123, |
|
109 | + ]; |
|
110 | + |
|
111 | + $expects = [ |
|
112 | + 'message' => [ |
|
113 | + 'data' => $data, |
|
114 | + 'type' => 'myType', |
|
115 | + 'signer' => '[email protected]', |
|
116 | + 'timestamp' => 42, |
|
117 | + ], |
|
118 | + 'signature' => 'E1fNdoWMX1QmSyKv+S3FtOgLe9niYGQFWOKGaMLxc2h7s3V++EIqJvw/NCLBfrUowzWkTzhkjfbHaf88Hz34WAn4sAwXYAO8cnboQs6SClKRzQ/nvbtLgd2wm9RQ8UTOM7wR6C7HpIn4qqJ4BTQ1bAwYAiJ2GoK+W8wC0o0Gpub2906j3JJ4cbc9lufd5ohWKCev8Ubem/EEKaRIZA7qHh+Q1MKXTaJQJlCjTMe5PyGy0fsmtVxsPls3/Fkd9sVeHEHSYHzOiF6ttlxWou4TdRbq3WSEVpt1DOOvkKI9w2+zBJ7IPH8CnVpXcdIzWDctUygZKzNMUQnweDOOziEdUw==' |
|
119 | + ]; |
|
120 | + |
|
121 | + $result = $this->signer->sign('myType', $data, $user); |
|
122 | + |
|
123 | + $this->assertEquals($expects, $result); |
|
124 | + } |
|
125 | + |
|
126 | + public function testVerifyValid(): void { |
|
127 | + $data = [ |
|
128 | + 'message' => [ |
|
129 | + 'data' => [ |
|
130 | + 'foo' => 'bar', |
|
131 | + 'abc' => 'def', |
|
132 | + 'xyz' => 123, |
|
133 | + ], |
|
134 | + 'type' => 'myType', |
|
135 | + 'signer' => '[email protected]', |
|
136 | + 'timestamp' => 42, |
|
137 | + ], |
|
138 | + 'signature' => 'E1fNdoWMX1QmSyKv+S3FtOgLe9niYGQFWOKGaMLxc2h7s3V++EIqJvw/NCLBfrUowzWkTzhkjfbHaf88Hz34WAn4sAwXYAO8cnboQs6SClKRzQ/nvbtLgd2wm9RQ8UTOM7wR6C7HpIn4qqJ4BTQ1bAwYAiJ2GoK+W8wC0o0Gpub2906j3JJ4cbc9lufd5ohWKCev8Ubem/EEKaRIZA7qHh+Q1MKXTaJQJlCjTMe5PyGy0fsmtVxsPls3/Fkd9sVeHEHSYHzOiF6ttlxWou4TdRbq3WSEVpt1DOOvkKI9w2+zBJ7IPH8CnVpXcdIzWDctUygZKzNMUQnweDOOziEdUw==' |
|
139 | + ]; |
|
140 | + |
|
141 | + $user = $this->createMock(IUser::class); |
|
142 | + |
|
143 | + $this->keyManager->method('getKey') |
|
144 | + ->with($this->equalTo($user)) |
|
145 | + ->willReturn($this->key); |
|
146 | + |
|
147 | + $this->userManager->method('get') |
|
148 | + ->with('foo') |
|
149 | + ->willReturn($user); |
|
150 | + |
|
151 | + $this->assertTrue($this->signer->verify($data)); |
|
152 | + } |
|
153 | + |
|
154 | + public function testVerifyInvalid(): void { |
|
155 | + $data = [ |
|
156 | + 'message' => [ |
|
157 | + 'data' => [ |
|
158 | + 'foo' => 'bar', |
|
159 | + 'abc' => 'def', |
|
160 | + 'xyz' => 123, |
|
161 | + ], |
|
162 | + 'type' => 'myType', |
|
163 | + 'signer' => '[email protected]', |
|
164 | + 'timestamp' => 42, |
|
165 | + ], |
|
166 | + 'signature' => 'Invalid sig' |
|
167 | + ]; |
|
168 | + |
|
169 | + $user = $this->createMock(IUser::class); |
|
170 | + |
|
171 | + $this->keyManager->method('getKey') |
|
172 | + ->with($this->equalTo($user)) |
|
173 | + ->willReturn($this->key); |
|
174 | + |
|
175 | + $this->userManager->method('get') |
|
176 | + ->with('foo') |
|
177 | + ->willReturn($user); |
|
178 | + |
|
179 | + $this->assertFalse($this->signer->verify($data)); |
|
180 | + } |
|
181 | + |
|
182 | + public function testVerifyInvalidData(): void { |
|
183 | + $data = [ |
|
184 | + ]; |
|
185 | + |
|
186 | + $this->assertFalse($this->signer->verify($data)); |
|
187 | + } |
|
188 | 188 | } |
@@ -13,20 +13,20 @@ |
||
13 | 13 | use Test\TestCase; |
14 | 14 | |
15 | 15 | class KeyTest extends TestCase { |
16 | - /** @var Key */ |
|
17 | - private $key; |
|
16 | + /** @var Key */ |
|
17 | + private $key; |
|
18 | 18 | |
19 | - protected function setUp(): void { |
|
20 | - parent::setUp(); |
|
19 | + protected function setUp(): void { |
|
20 | + parent::setUp(); |
|
21 | 21 | |
22 | - $this->key = new Key('public', 'private'); |
|
23 | - } |
|
22 | + $this->key = new Key('public', 'private'); |
|
23 | + } |
|
24 | 24 | |
25 | - public function testGetPrivate(): void { |
|
26 | - $this->assertSame('private', $this->key->getPrivate()); |
|
27 | - } |
|
25 | + public function testGetPrivate(): void { |
|
26 | + $this->assertSame('private', $this->key->getPrivate()); |
|
27 | + } |
|
28 | 28 | |
29 | - public function testGetPublic(): void { |
|
30 | - $this->assertSame('public', $this->key->getPublic()); |
|
31 | - } |
|
29 | + public function testGetPublic(): void { |
|
30 | + $this->assertSame('public', $this->key->getPublic()); |
|
31 | + } |
|
32 | 32 | } |