diff options
author | leith abdulla <online-nextcloud@eleith.com> | 2020-11-07 15:56:32 +0000 |
---|---|---|
committer | leith abdulla <online-nextcloud@eleith.com> | 2020-11-07 08:13:47 -0800 |
commit | 3d6bcd3bf97741c729b23ba79a3e737aec483fa2 (patch) | |
tree | 9e09a62fefc16e058e396928e8989671f918104f /tests/unit/Service/SocialApiServiceTest.php | |
parent | e1f1a0e797ef67d16b03aa69cf7b4538b8ec6f6c (diff) |
vcard should only have 1 photo field when adding/removing photos
when adding photo fields through the social api service, an extra photo
field is created for vcard version 3.0 due to setting a field as empty
instead of unsetting it all together
when removing photo fields, this empty photo field is left untouched
thus, syncing photos to address book clients can be buggy as most
address book clients do not properly iterate through all photo fields to
display the contact photo
Signed-off-by: leith abdulla <online-nextcloud@eleith.com>
Diffstat (limited to 'tests/unit/Service/SocialApiServiceTest.php')
-rw-r--r-- | tests/unit/Service/SocialApiServiceTest.php | 71 |
1 files changed, 70 insertions, 1 deletions
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"; |