diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2016-01-22 11:16:30 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-01-22 11:16:30 +0100 |
commit | 57b17cdd989aa7075e98de1a6448bad3f963f7da (patch) | |
tree | 217e0fbe9f9af566bc71f80bc9f632d35c54ed06 | |
parent | 141012075839f1f08cb42aa14396ae69e024f97f (diff) | |
parent | df27a939ce76c06a1a1f1ecf0525c62553ac4f0a (diff) | |
download | nextcloud-server-57b17cdd989aa7075e98de1a6448bad3f963f7da.tar.gz nextcloud-server-57b17cdd989aa7075e98de1a6448bad3f963f7da.zip |
Merge pull request #21826 from owncloud/dav-fix-user-deletion
No card ID when deleting is acceptable
-rw-r--r-- | apps/dav/lib/carddav/carddavbackend.php | 10 | ||||
-rw-r--r-- | apps/dav/tests/unit/carddav/carddavbackendtest.php | 41 |
2 files changed, 49 insertions, 2 deletions
diff --git a/apps/dav/lib/carddav/carddavbackend.php b/apps/dav/lib/carddav/carddavbackend.php index 7b8c43958b6..97067abb7c3 100644 --- a/apps/dav/lib/carddav/carddavbackend.php +++ b/apps/dav/lib/carddav/carddavbackend.php @@ -536,7 +536,11 @@ class CardDavBackend implements BackendInterface, SyncSupport { * @return bool */ function deleteCard($addressBookId, $cardUri) { - $cardId = $this->getCardId($cardUri); + try { + $cardId = $this->getCardId($cardUri); + } catch (\InvalidArgumentException $e) { + $cardId = null; + } $query = $this->db->getQueryBuilder(); $ret = $query->delete('cards') ->where($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId))) @@ -546,7 +550,9 @@ class CardDavBackend implements BackendInterface, SyncSupport { $this->addChange($addressBookId, $cardUri, 3); if ($ret === 1) { - $this->purgeProperties($addressBookId, $cardId); + if ($cardId !== null) { + $this->purgeProperties($addressBookId, $cardId); + } return true; } diff --git a/apps/dav/tests/unit/carddav/carddavbackendtest.php b/apps/dav/tests/unit/carddav/carddavbackendtest.php index 3291314ec40..1a0d32c186c 100644 --- a/apps/dav/tests/unit/carddav/carddavbackendtest.php +++ b/apps/dav/tests/unit/carddav/carddavbackendtest.php @@ -218,6 +218,47 @@ class CardDavBackendTest extends TestCase { $this->assertEquals(0, count($cards)); } + public function testDeleteWithoutCard() { + + $this->backend = $this->getMockBuilder('OCA\DAV\CardDAV\CardDavBackend') + ->setConstructorArgs([$this->db, $this->principal]) + ->setMethods([ + 'getCardId', + 'addChange', + 'purgeProperties', + 'updateProperties', + ]) + ->getMock(); + + // create a new address book + $this->backend->createAddressBook(self::UNIT_TEST_USER, 'Example', []); + $books = $this->backend->getAddressBooksForUser(self::UNIT_TEST_USER); + $this->assertEquals(1, count($books)); + + $bookId = $books[0]['id']; + $uri = $this->getUniqueID('card'); + + // create a new address book + $this->backend->expects($this->once()) + ->method('getCardId') + ->with($uri) + ->willThrowException(new \InvalidArgumentException()); + $this->backend->expects($this->exactly(2)) + ->method('addChange') + ->withConsecutive( + [$bookId, $uri, 1], + [$bookId, $uri, 3] + ); + $this->backend->expects($this->never()) + ->method('purgeProperties'); + + // create a card + $this->backend->createCard($bookId, $uri, ''); + + // delete the card + $this->assertTrue($this->backend->deleteCard($bookId, $uri)); + } + public function testSyncSupport() { $this->backend = $this->getMockBuilder('OCA\DAV\CardDAV\CardDavBackend') |