diff --git a/apps/dav/tests/unit/CardDAV/SyncServiceTest.php b/apps/dav/tests/unit/CardDAV/SyncServiceTest.php index 5c8c30effbe..9fe8a7cd66e 100644 --- a/apps/dav/tests/unit/CardDAV/SyncServiceTest.php +++ b/apps/dav/tests/unit/CardDAV/SyncServiceTest.php @@ -104,7 +104,7 @@ class SyncServiceTest extends TestCase { 'system', 'system', '1234567890', - null, + '1', '1', 'principals/system/system', [] @@ -175,7 +175,7 @@ END:VCARD'; 'system', 'system', '1234567890', - null, + '1', '1', 'principals/system/system', [] @@ -246,7 +246,7 @@ END:VCARD'; 'system', 'system', '1234567890', - null, + '1', '1', 'principals/system/system', [] @@ -287,7 +287,7 @@ END:VCARD'; 'system', 'system', '1234567890', - null, + '1', '1', 'principals/system/system', [] @@ -296,6 +296,79 @@ END:VCARD'; $this->assertEquals('http://sabre.io/ns/sync/4', $token); } + public function testFullSyncWithOrphanElement(): void { + $this->backend->expects($this->exactly(0)) + ->method('createCard'); + $this->backend->expects($this->exactly(1)) + ->method('updateCard'); + $this->backend->expects($this->exactly(1)) + ->method('deleteCard'); + + $body = ' + + + /remote.php/dav/addressbooks/system/system/system/Database:alice.vcf + + + text/vcard; charset=utf-8 + "2df155fa5c2a24cd7f750353fc63f037" + + HTTP/1.1 200 OK + + + http://sabre.io/ns/sync/3 +'; + + $reportResponse = new Response(new PsrResponse( + 207, + ['Content-Type' => 'application/xml; charset=utf-8', 'Content-Length' => strlen($body)], + $body + )); + + $this->client + ->method('request') + ->willReturn($reportResponse); + + $vCard = 'BEGIN:VCARD +VERSION:3.0 +PRODID:-//Sabre//Sabre VObject 4.5.4//EN +UID:alice +FN;X-NC-SCOPE=v2-federated:alice +N;X-NC-SCOPE=v2-federated:alice;;;; +X-SOCIALPROFILE;TYPE=NEXTCLOUD;X-NC-SCOPE=v2-published:https://server2.internal/index.php/u/alice +CLOUD:alice@server2.internal +END:VCARD'; + + $getResponse = new Response(new PsrResponse( + 200, + ['Content-Type' => 'text/vcard; charset=utf-8', 'Content-Length' => strlen($vCard)], + $vCard, + )); + + $this->client + ->method('get') + ->willReturn($getResponse); + + $this->backend->method('getCards') + ->willReturn([ + ['uri' => 'Database:alice.vcf'], + ['uri' => 'Database:bob.vcf'], + ]); + + $token = $this->service->syncRemoteAddressBook( + '', + 'system', + 'system', + '1234567890', + null, + '1', + 'principals/system/system', + [] + )[0]; + + $this->assertEquals('http://sabre.io/ns/sync/3', $token); + } + public function testEnsureSystemAddressBookExists(): void { /** @var CardDavBackend&MockObject $backend */ $backend = $this->createMock(CardDavBackend::class); @@ -496,7 +569,7 @@ END:VCARD'; 'system', 'remote.php/dav/addressbooks/system/system/system', '1234567890', - null, + '1', '1', 'principals/system/system', []