Skip to content

Commit 2875692

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

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
@@ -104,7 +104,7 @@ public function testEmptySync(): void {
104104
'system',
105105
'system',
106106
'1234567890',
107-
null,
107+
'1',
108108
'1',
109109
'principals/system/system',
110110
[]
@@ -175,7 +175,7 @@ public function testSyncWithNewElement(): void {
175175
'system',
176176
'system',
177177
'1234567890',
178-
null,
178+
'1',
179179
'1',
180180
'principals/system/system',
181181
[]
@@ -246,7 +246,7 @@ public function testSyncWithUpdatedElement(): void {
246246
'system',
247247
'system',
248248
'1234567890',
249-
null,
249+
'1',
250250
'1',
251251
'principals/system/system',
252252
[]
@@ -287,7 +287,7 @@ public function testSyncWithDeletedElement(): void {
287287
'system',
288288
'system',
289289
'1234567890',
290-
null,
290+
'1',
291291
'1',
292292
'principals/system/system',
293293
[]
@@ -296,6 +296,79 @@ public function testSyncWithDeletedElement(): void {
296296
$this->assertEquals('http://sabre.io/ns/sync/4', $token);
297297
}
298298

299+
public function testFullSyncWithOrphanElement(): void {
300+
$this->backend->expects($this->exactly(0))
301+
->method('createCard');
302+
$this->backend->expects($this->exactly(1))
303+
->method('updateCard');
304+
$this->backend->expects($this->exactly(1))
305+
->method('deleteCard');
306+
307+
$body = '<?xml version="1.0"?>
308+
<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">
309+
<d:response>
310+
<d:href>/remote.php/dav/addressbooks/system/system/system/Database:alice.vcf</d:href>
311+
<d:propstat>
312+
<d:prop>
313+
<d:getcontenttype>text/vcard; charset=utf-8</d:getcontenttype>
314+
<d:getetag>&quot;2df155fa5c2a24cd7f750353fc63f037&quot;</d:getetag>
315+
</d:prop>
316+
<d:status>HTTP/1.1 200 OK</d:status>
317+
</d:propstat>
318+
</d:response>
319+
<d:sync-token>http://sabre.io/ns/sync/3</d:sync-token>
320+
</d:multistatus>';
321+
322+
$reportResponse = new Response(new PsrResponse(
323+
207,
324+
['Content-Type' => 'application/xml; charset=utf-8', 'Content-Length' => strlen($body)],
325+
$body
326+
));
327+
328+
$this->client
329+
->method('request')
330+
->willReturn($reportResponse);
331+
332+
$vCard = 'BEGIN:VCARD
333+
VERSION:3.0
334+
PRODID:-//Sabre//Sabre VObject 4.5.4//EN
335+
UID:alice
336+
FN;X-NC-SCOPE=v2-federated:alice
337+
N;X-NC-SCOPE=v2-federated:alice;;;;
338+
X-SOCIALPROFILE;TYPE=NEXTCLOUD;X-NC-SCOPE=v2-published:https://server2.internal/index.php/u/alice
339+
CLOUD:alice@server2.internal
340+
END:VCARD';
341+
342+
$getResponse = new Response(new PsrResponse(
343+
200,
344+
['Content-Type' => 'text/vcard; charset=utf-8', 'Content-Length' => strlen($vCard)],
345+
$vCard,
346+
));
347+
348+
$this->client
349+
->method('get')
350+
->willReturn($getResponse);
351+
352+
$this->backend->method('getCards')
353+
->willReturn([
354+
['uri' => 'Database:alice.vcf'],
355+
['uri' => 'Database:bob.vcf'],
356+
]);
357+
358+
$token = $this->service->syncRemoteAddressBook(
359+
'',
360+
'system',
361+
'system',
362+
'1234567890',
363+
null,
364+
'1',
365+
'principals/system/system',
366+
[]
367+
)[0];
368+
369+
$this->assertEquals('http://sabre.io/ns/sync/3', $token);
370+
}
371+
299372
public function testEnsureSystemAddressBookExists(): void {
300373
/** @var CardDavBackend&MockObject $backend */
301374
$backend = $this->createMock(CardDavBackend::class);
@@ -458,7 +531,7 @@ public function testUseAbsoluteUriReport(string $host, string $expected): void {
458531
'system',
459532
'remote.php/dav/addressbooks/system/system/system',
460533
'1234567890',
461-
null,
534+
'1',
462535
'1',
463536
'principals/system/system',
464537
[]

0 commit comments

Comments
 (0)