summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoreleith <eleith@users.noreply.github.com>2020-11-07 08:19:59 -0800
committerGitHub <noreply@github.com>2020-11-07 08:19:59 -0800
commit8d3085ca17bb81f72c7bf2edff7edc24e94e5233 (patch)
tree9e09a62fefc16e058e396928e8989671f918104f
parente1f1a0e797ef67d16b03aa69cf7b4538b8ec6f6c (diff)
parent3d6bcd3bf97741c729b23ba79a3e737aec483fa2 (diff)
Merge pull request #1918 from eleith/double-photo-fields
vcard should only have 1 photo field when adding/removing photos
-rw-r--r--lib/Service/SocialApiService.php2
-rw-r--r--src/components/ContactDetails/ContactDetailsAvatar.vue2
-rw-r--r--tests/unit/Service/SocialApiServiceTest.php71
3 files changed, 72 insertions, 3 deletions
diff --git a/lib/Service/SocialApiService.php b/lib/Service/SocialApiService.php
index 446a9ef6..b1657734 100644
--- a/lib/Service/SocialApiService.php
+++ b/lib/Service/SocialApiService.php
@@ -118,7 +118,7 @@ class SocialApiService {
$contact['PHOTO;ENCODING=b;TYPE=' . $imageType . ';VALUE=BINARY'] = $photo;
// remove previous photo (necessary as new attribute is not equal to 'PHOTO')
- $contact['PHOTO'] = '';
+ unset($contact['PHOTO']);
}
}
diff --git a/src/components/ContactDetails/ContactDetailsAvatar.vue b/src/components/ContactDetails/ContactDetailsAvatar.vue
index 8f631eb5..5a43ac08 100644
--- a/src/components/ContactDetails/ContactDetailsAvatar.vue
+++ b/src/components/ContactDetails/ContactDetailsAvatar.vue
@@ -368,7 +368,7 @@ export default {
*/
removePhoto() {
this.maximizeAvatar = false
- this.contact.vCard.removeProperty('photo')
+ this.contact.vCard.removeAllProperties('photo')
this.$store.dispatch('updateContact', this.contact)
},
diff --git a/tests/unit/Service/SocialApiServiceTest.php b/tests/unit/Service/SocialApiServiceTest.php
index e7f4c8e3..eba6d9a3 100644
--- a/tests/unit/Service/SocialApiServiceTest.php
+++ b/tests/unit/Service/SocialApiServiceTest.php
@@ -183,7 +183,76 @@ class SocialApiServiceTest extends TestCase {
$this->assertEquals($status, $result->getStatus());
}
- public function testUpdateContactWithNetwork() {
+ public function testUpdateContactWithNetworkVersion3() {
+ $network = "mastodon";
+ $body = "the body";
+ $imageType = "jpg";
+ $addressBookId = "contacts";
+ $contactId = "3225c0d5-1bd2-43e5-a08c-4e65eaa406b0";
+ $contact = [
+ 'URI' => $contactId,
+ 'VERSION' => '3.0'
+ ];
+ $provider = $this->createMock(ISocialProvider::class);
+ $provider->method('supportsContact')->willReturn(true);
+ $provider->method('getImageUrls')->willReturn(["url1"]);
+
+ $addressbook = $this->createMock(IAddressBook::class);
+ $addressbook
+ ->method('getUri')
+ ->willReturn('contacts');
+ $addressbook
+ ->method('search')
+ ->willReturn([$contact]);
+
+ $this->manager
+ ->method('getUserAddressBooks')
+ ->willReturn([$addressbook]);
+
+ $this->socialProvider
+ ->method('getSocialConnectors')
+ ->willReturn([$provider]);
+
+ $this->socialProvider
+ ->method('getSocialConnector')
+ ->willReturn($provider);
+
+ $response = $this->createMock(IResponse::class);
+ $response
+ ->method('getBody')
+ ->willReturn($body);
+ $response
+ ->method('getHeader')
+ ->willReturn($imageType);
+ $client = $this->createMock(IClient::class);
+ $client
+ ->method('get')
+ ->willReturn($response);
+ $this->clientService
+ ->method('NewClient')
+ ->willReturn($client);
+
+ $changes = [
+ 'URI' => $contact['URI'],
+ 'VERSION' => $contact['VERSION'],
+ 'PHOTO;ENCODING=b;TYPE=' . $imageType . ';VALUE=BINARY' => base64_encode($body)
+ ];
+
+ $this->socialProvider
+ ->expects($this->once())->method("getSocialConnector")->with($network);
+ $provider->expects($this->once())->method("supportsContact")->with($contact);
+ $addressbook->expects($this->once())->method("createOrUpdate")->with($changes, $addressBookId);
+
+ $result = $this->service
+ ->updateContact(
+ $addressBookId,
+ $contactId,
+ $network);
+
+ $this->assertEquals(Http::STATUS_OK, $result->getStatus());
+ }
+
+ public function testUpdateContactWithNetworkVersion4() {
$network = "mastodon";
$body = "the body";
$imageType = "jpg";