55 * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
66 * SPDX-License-Identifier: AGPL-3.0-only
77 */
8+
89namespace OCA \DAV \Tests \unit \CardDAV ;
910
1011use GuzzleHttp \Exception \ClientException ;
@@ -293,10 +294,26 @@ public function testSyncWithDeletedElement(): void {
293294 }
294295
295296 public function testFullSyncWithOrphanElement (): void {
297+ $ pendingCards = [];
296298 $ this ->backend ->expects ($ this ->exactly (0 ))
297299 ->method ('createCard ' );
298300 $ this ->backend ->expects ($ this ->exactly (1 ))
299- ->method ('updateCard ' );
301+ ->method ('updateCard ' )
302+ ->willReturnCallback (function ($ id , $ uri ) use (&$ pendingCards ) {
303+ unset($ pendingCards [$ uri ]);
304+ });
305+ $ this ->backend ->expects ($ this ->exactly (1 ))
306+ ->method ('markCardsAsPending ' )
307+ ->willReturnCallback (function ($ id ) use (&$ pendingCards ) {
308+ $ cards = array_values ($ this ->backend ->getCards ($ id ));
309+ $ uris = array_map (fn ($ card ) => $ card ['uri ' ], $ cards );
310+ $ pendingCards = array_combine ($ uris , $ cards );
311+ });
312+ $ this ->backend ->expects ($ this ->exactly (1 ))
313+ ->method ('getPendingCards ' )
314+ ->willReturnCallback (function ($ id ) use (&$ pendingCards ) {
315+ return array_values ($ pendingCards );
316+ });
300317 $ this ->backend ->expects ($ this ->exactly (1 ))
301318 ->method ('deleteCard ' );
302319
@@ -351,6 +368,7 @@ public function testFullSyncWithOrphanElement(): void {
351368 ['uri ' => 'Database:bob.vcf ' ],
352369 ]);
353370
371+ $ this ->service ->markCardsAsPending (1 );
354372 $ token = $ this ->service ->syncRemoteAddressBook (
355373 '' ,
356374 'system ' ,
@@ -361,6 +379,7 @@ public function testFullSyncWithOrphanElement(): void {
361379 'principals/system/system ' ,
362380 []
363381 )[0 ];
382+ $ this ->service ->deletePendingCards (1 );
364383
365384 $ this ->assertEquals ('http://sabre.io/ns/sync/3 ' , $ token );
366385 }
0 commit comments