Skip to content

Commit af0069c

Browse files
committed
test: adjust tests to full address book sync
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent be81390 commit af0069c

1 file changed

Lines changed: 78 additions & 5 deletions

File tree

apps/dav/tests/unit/CardDAV/SyncServiceTest.php

Lines changed: 78 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function testEmptySync(): void {
100100
'system',
101101
'system',
102102
'1234567890',
103-
null,
103+
'1',
104104
'1',
105105
'principals/system/system',
106106
[]
@@ -171,7 +171,7 @@ public function testSyncWithNewElement(): void {
171171
'system',
172172
'system',
173173
'1234567890',
174-
null,
174+
'1',
175175
'1',
176176
'principals/system/system',
177177
[]
@@ -242,7 +242,7 @@ public function testSyncWithUpdatedElement(): void {
242242
'system',
243243
'system',
244244
'1234567890',
245-
null,
245+
'1',
246246
'1',
247247
'principals/system/system',
248248
[]
@@ -283,7 +283,7 @@ public function testSyncWithDeletedElement(): void {
283283
'system',
284284
'system',
285285
'1234567890',
286-
null,
286+
'1',
287287
'1',
288288
'principals/system/system',
289289
[]
@@ -292,6 +292,79 @@ public function testSyncWithDeletedElement(): void {
292292
$this->assertEquals('http://sabre.io/ns/sync/4', $token);
293293
}
294294

295+
public function testFullSyncWithOrphanElement(): void {
296+
$this->backend->expects($this->exactly(0))
297+
->method('createCard');
298+
$this->backend->expects($this->exactly(1))
299+
->method('updateCard');
300+
$this->backend->expects($this->exactly(1))
301+
->method('deleteCard');
302+
303+
$body = '<?xml version="1.0"?>
304+
<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:card="urn:ietf:params:xml:ns:carddav" xmlns:oc="http://owncloud.org/ns">
305+
<d:response>
306+
<d:href>/remote.php/dav/addressbooks/system/system/system/Database:alice.vcf</d:href>
307+
<d:propstat>
308+
<d:prop>
309+
<d:getcontenttype>text/vcard; charset=utf-8</d:getcontenttype>
310+
<d:getetag>&quot;2df155fa5c2a24cd7f750353fc63f037&quot;</d:getetag>
311+
</d:prop>
312+
<d:status>HTTP/1.1 200 OK</d:status>
313+
</d:propstat>
314+
</d:response>
315+
<d:sync-token>http://sabre.io/ns/sync/3</d:sync-token>
316+
</d:multistatus>';
317+
318+
$reportResponse = new Response(new PsrResponse(
319+
207,
320+
['Content-Type' => 'application/xml; charset=utf-8', 'Content-Length' => strlen($body)],
321+
$body
322+
));
323+
324+
$this->client
325+
->method('request')
326+
->willReturn($reportResponse);
327+
328+
$vCard = 'BEGIN:VCARD
329+
VERSION:3.0
330+
PRODID:-//Sabre//Sabre VObject 4.5.4//EN
331+
UID:alice
332+
FN;X-NC-SCOPE=v2-federated:alice
333+
N;X-NC-SCOPE=v2-federated:alice;;;;
334+
X-SOCIALPROFILE;TYPE=NEXTCLOUD;X-NC-SCOPE=v2-published:https://server2.internal/index.php/u/alice
335+
CLOUD:alice@server2.internal
336+
END:VCARD';
337+
338+
$getResponse = new Response(new PsrResponse(
339+
200,
340+
['Content-Type' => 'text/vcard; charset=utf-8', 'Content-Length' => strlen($vCard)],
341+
$vCard,
342+
));
343+
344+
$this->client
345+
->method('get')
346+
->willReturn($getResponse);
347+
348+
$this->backend->method('getCards')
349+
->willReturn([
350+
['uri' => 'Database:alice.vcf'],
351+
['uri' => 'Database:bob.vcf'],
352+
]);
353+
354+
$token = $this->service->syncRemoteAddressBook(
355+
'',
356+
'system',
357+
'system',
358+
'1234567890',
359+
null,
360+
'1',
361+
'principals/system/system',
362+
[]
363+
)[0];
364+
365+
$this->assertEquals('http://sabre.io/ns/sync/3', $token);
366+
}
367+
295368
public function testEnsureSystemAddressBookExists(): void {
296369
/** @var CardDavBackend | \PHPUnit\Framework\MockObject\MockObject $backend */
297370
$backend = $this->getMockBuilder(CardDavBackend::class)->disableOriginalConstructor()->getMock();
@@ -468,7 +541,7 @@ public function testUseAbsoluteUriReport(string $host, string $expected): void {
468541
'system',
469542
'remote.php/dav/addressbooks/system/system/system',
470543
'1234567890',
471-
null,
544+
'1',
472545
'1',
473546
'principals/system/system',
474547
[]

0 commit comments

Comments
 (0)