From af0069c00e402bed58df4780b40302b7d5fa3908 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 30 Mar 2026 18:12:40 +0200 Subject: [PATCH] test: adjust tests to full address book sync Signed-off-by: Robin Appelman --- .../tests/unit/CardDAV/SyncServiceTest.php | 83 +++++++++++++++++-- 1 file changed, 78 insertions(+), 5 deletions(-) diff --git a/apps/dav/tests/unit/CardDAV/SyncServiceTest.php b/apps/dav/tests/unit/CardDAV/SyncServiceTest.php index 499ba57e042..63cd6afbe0b 100644 --- a/apps/dav/tests/unit/CardDAV/SyncServiceTest.php +++ b/apps/dav/tests/unit/CardDAV/SyncServiceTest.php @@ -100,7 +100,7 @@ class SyncServiceTest extends TestCase { 'system', 'system', '1234567890', - null, + '1', '1', 'principals/system/system', [] @@ -171,7 +171,7 @@ END:VCARD'; 'system', 'system', '1234567890', - null, + '1', '1', 'principals/system/system', [] @@ -242,7 +242,7 @@ END:VCARD'; 'system', 'system', '1234567890', - null, + '1', '1', 'principals/system/system', [] @@ -283,7 +283,7 @@ END:VCARD'; 'system', 'system', '1234567890', - null, + '1', '1', 'principals/system/system', [] @@ -292,6 +292,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 | \PHPUnit\Framework\MockObject\MockObject $backend */ $backend = $this->getMockBuilder(CardDavBackend::class)->disableOriginalConstructor()->getMock(); @@ -468,7 +541,7 @@ END:VCARD'; 'system', 'remote.php/dav/addressbooks/system/system/system', '1234567890', - null, + '1', '1', 'principals/system/system', []