Merge pull request #21826 from owncloud/dav-fix-user-deletion
No card ID when deleting is acceptable
This commit is contained in:
commit
57b17cdd98
2 changed files with 49 additions and 2 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in a new issue