summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorleith abdulla <online-nextcloud@eleith.com>2020-11-04 11:04:41 -0800
committerleith abdulla <online-nextcloud@eleith.com>2020-11-04 11:10:50 -0800
commitca1c40a8ae2b388f5e923e70c9ac2c3af176e71d (patch)
tree14706b573dbcb632d3333d2f19bfad7417a9ad1b /lib
parentda321c14516862c1216f57060d1d609704f61c9d (diff)
unit tests for all providers
this commit adds unit tests for all providers while also reducing some redundancy in looking up social fields minor feedback was addressed as well as some minor bugs fixed Signed-off-by: leith abdulla <online-nextcloud@eleith.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Service/Social/DiasporaProvider.php15
-rw-r--r--lib/Service/Social/FacebookProvider.php35
-rw-r--r--lib/Service/Social/GravatarProvider.php32
-rw-r--r--lib/Service/Social/InstagramProvider.php41
-rw-r--r--lib/Service/Social/MastodonProvider.php13
-rw-r--r--lib/Service/Social/TumblrProvider.php13
-rw-r--r--lib/Service/Social/TwitterProvider.php11
-rw-r--r--lib/Service/Social/XingProvider.php14
8 files changed, 64 insertions, 110 deletions
diff --git a/lib/Service/Social/DiasporaProvider.php b/lib/Service/Social/DiasporaProvider.php
index 31269029..c0af278f 100644
--- a/lib/Service/Social/DiasporaProvider.php
+++ b/lib/Service/Social/DiasporaProvider.php
@@ -49,17 +49,8 @@ class DiasporaProvider implements ISocialProvider {
* @return bool
*/
public function supportsContact(array $contact):bool {
- $socialprofiles = $contact['X-SOCIALPROFILE'];
- $supports = false;
- if (isset($socialprofiles)) {
- foreach ($socialprofiles as $profile) {
- if ($profile['type'] == $this->name) {
- $supports = true;
- break;
- }
- }
- }
- return $supports;
+ $socialprofiles = $this->getProfileIds($contact);
+ return isset($socialprofiles) && count($socialprofiles) > 0;
}
/**
@@ -150,7 +141,7 @@ class DiasporaProvider implements ISocialProvider {
$user_server = explode('@', $candidate);
$candidate = 'https://' . array_pop($user_server) . '/public/' . array_pop($user_server) . '.atom';
}
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$candidate = null;
}
return $candidate;
diff --git a/lib/Service/Social/FacebookProvider.php b/lib/Service/Social/FacebookProvider.php
index 0202e6d0..e5d34397 100644
--- a/lib/Service/Social/FacebookProvider.php
+++ b/lib/Service/Social/FacebookProvider.php
@@ -45,17 +45,8 @@ class FacebookProvider implements ISocialProvider {
* @return bool
*/
public function supportsContact(array $contact):bool {
- $socialprofiles = $contact['X-SOCIALPROFILE'];
- $supports = false;
- if (isset($socialprofiles)) {
- foreach ($socialprofiles as $profile) {
- if (strtolower($profile['type']) == $this->name) {
- $supports = true;
- break;
- }
- }
- }
- return $supports;
+ $socialprofiles = $this->getProfiles($contact);
+ return isset($socialprofiles) && count($socialprofiles) > 0;
}
/**
@@ -98,16 +89,32 @@ class FacebookProvider implements ISocialProvider {
*
* @return array of string profile ids
*/
- protected function getProfileIds($contact):array {
+ protected function getProfiles(array $contact):array {
$socialprofiles = $contact['X-SOCIALPROFILE'];
- $profileIds = [];
+ $profiles = [];
if (isset($socialprofiles)) {
foreach ($socialprofiles as $profile) {
if (strtolower($profile['type']) == $this->name) {
- $profileIds[] = $this->cleanupId($profile['value']);
+ $profiles[] = $profile['value'];
}
}
}
+ return $profiles;
+ }
+
+ /**
+ * Returns all possible profile ids for contact
+ *
+ * @param {array} contact information
+ *
+ * @return array of string profile ids
+ */
+ protected function getProfileIds(array $contact):array {
+ $profiles = $this->getProfiles($contact);
+ $profileIds = [];
+ foreach ($profiles as $profile) {
+ $profileIds[] = $this->cleanupId($profile);
+ }
return $profileIds;
}
diff --git a/lib/Service/Social/GravatarProvider.php b/lib/Service/Social/GravatarProvider.php
index 07b0f83e..4b9d9a84 100644
--- a/lib/Service/Social/GravatarProvider.php
+++ b/lib/Service/Social/GravatarProvider.php
@@ -23,14 +23,11 @@
namespace OCA\Contacts\Service\Social;
-use OCP\Http\Client\IClientService;
-
class GravatarProvider implements ISocialProvider {
/** @var string */
public $name = "gravatar";
- public function __construct(IClientService $httpClient) {
- $this->httpClient = $httpClient->NewClient();
+ public function __construct() {
}
/**
@@ -53,29 +50,16 @@ class GravatarProvider implements ISocialProvider {
* @return array
*/
public function getImageUrls(array $contact):array {
- $emails = $this->getProfileIds($contact);
$urls = [];
- foreach ($emails as $email) {
- $hash = md5(strtolower(trim($email['value'])));
- $recipe = 'https://www.gravatar.com/avatar/{hash}?s=720&d=404';
- $connector = str_replace("{hash}", $hash, $recipe);
- $urls[] = $connector;
- }
- return $urls;
- }
-
- /**
- * Returns all possible profile ids for contact
- *
- * @param {array} contact information
- *
- * @return array of string profile ids
- */
- protected function getProfileIds(array $contact):array {
$emails = $contact['EMAIL'];
if (isset($emails)) {
- return $emails;
+ foreach ($emails as $email) {
+ $hash = md5(strtolower(trim($email['value'])));
+ $recipe = 'https://www.gravatar.com/avatar/{hash}?s=720&d=404';
+ $connector = str_replace("{hash}", $hash, $recipe);
+ $urls[] = $connector;
+ }
}
- return [];
+ return $urls;
}
}
diff --git a/lib/Service/Social/InstagramProvider.php b/lib/Service/Social/InstagramProvider.php
index f0c593c7..a43d12c3 100644
--- a/lib/Service/Social/InstagramProvider.php
+++ b/lib/Service/Social/InstagramProvider.php
@@ -45,17 +45,8 @@ class InstagramProvider implements ISocialProvider {
* @return bool
*/
public function supportsContact(array $contact):bool {
- $socialprofiles = $contact['X-SOCIALPROFILE'];
- $supports = false;
- if (isset($socialprofiles)) {
- foreach ($socialprofiles as $profile) {
- if (strtolower($profile['type']) == $this->name) {
- $supports = true;
- break;
- }
- }
- }
- return $supports;
+ $socialprofiles = $this->getProfiles($contact);
+ return isset($socialprofiles) && count($socialprofiles) > 0;
}
/**
@@ -88,24 +79,40 @@ class InstagramProvider implements ISocialProvider {
$candidate = preg_replace('/^' . preg_quote('x-apple:', '/') . '/', '', $candidate);
return basename($candidate);
}
-
+
/**
- * Returns all possible profile ids for contact
+ * Returns all possible profile urls for contact
*
* @param {array} contact information
*
- * @return array of string profile ids
+ * @return array of string profile urls
*/
- protected function getProfileIds($contact):array {
+ protected function getProfiles($contact):array {
$socialprofiles = $contact['X-SOCIALPROFILE'];
- $profileIds = [];
+ $profiles = [];
if (isset($socialprofiles)) {
foreach ($socialprofiles as $profile) {
if (strtolower($profile['type']) == $this->name) {
- $profileIds[] = $this->cleanupId($profile['value']);
+ $profiles[] = $profile['value'];
}
}
}
+ return $profiles;
+ }
+
+ /**
+ * Returns all possible profile ids for contact
+ *
+ * @param {array} contact information
+ *
+ * @return array of string profile ids
+ */
+ protected function getProfileIds($contact):array {
+ $socialprofiles = $this->getProfiles($contact);
+ $profileIds = [];
+ foreach ($socialprofiles as $profile) {
+ $profileIds[] = $this->cleanupId($profile);
+ }
return $profileIds;
}
diff --git a/lib/Service/Social/MastodonProvider.php b/lib/Service/Social/MastodonProvider.php
index b1bb5097..a212433c 100644
--- a/lib/Service/Social/MastodonProvider.php
+++ b/lib/Service/Social/MastodonProvider.php
@@ -45,17 +45,8 @@ class MastodonProvider implements ISocialProvider {
* @return bool
*/
public function supportsContact(array $contact):bool {
- $socialprofiles = $contact['X-SOCIALPROFILE'];
- $supports = false;
- if (isset($socialprofiles)) {
- foreach ($socialprofiles as $profile) {
- if (strtolower($profile['type']) == $this->name) {
- $supports = true;
- break;
- }
- }
- }
- return $supports;
+ $profiles = $this->getProfileIds($contact);
+ return isset($profiles) && count($profiles) > 0;
}
/**
diff --git a/lib/Service/Social/TumblrProvider.php b/lib/Service/Social/TumblrProvider.php
index c0d8ffca..cd3d577f 100644
--- a/lib/Service/Social/TumblrProvider.php
+++ b/lib/Service/Social/TumblrProvider.php
@@ -38,17 +38,8 @@ class TumblrProvider implements ISocialProvider {
* @return bool
*/
public function supportsContact(array $contact):bool {
- $socialprofiles = $contact['X-SOCIALPROFILE'];
- $supports = false;
- if (isset($socialprofiles)) {
- foreach ($socialprofiles as $profile) {
- if (strtolower($profile['type']) == $this->name) {
- $supports = true;
- break;
- }
- }
- }
- return $supports;
+ $socialprofiles = $this->getProfileIds($contact);
+ return isset($socialprofiles) && count($socialprofiles) > 0;
}
/**
diff --git a/lib/Service/Social/TwitterProvider.php b/lib/Service/Social/TwitterProvider.php
index 08aab855..18cd0d46 100644
--- a/lib/Service/Social/TwitterProvider.php
+++ b/lib/Service/Social/TwitterProvider.php
@@ -44,15 +44,8 @@ class TwitterProvider implements ISocialProvider {
* @return bool
*/
public function supportsContact(array $contact):bool {
- $socialprofiles = $contact['X-SOCIALPROFILE'];
- if (isset($socialprofiles)) {
- foreach ($socialprofiles as $profile) {
- if (strtolower($profile['type']) == $this->name) {
- return true;
- }
- }
- }
- return false;
+ $socialprofiles = $this->getProfileIds($contact);
+ return isset($socialprofiles) && count($socialprofiles) > 0;
}
/**
diff --git a/lib/Service/Social/XingProvider.php b/lib/Service/Social/XingProvider.php
index c0a816d9..a752d3c6 100644
--- a/lib/Service/Social/XingProvider.php
+++ b/lib/Service/Social/XingProvider.php
@@ -35,7 +35,6 @@ class XingProvider implements ISocialProvider {
public function __construct(IClientService $httpClient) {
$this->httpClient = $httpClient->NewClient();
- $this->looping = false;
}
/**
@@ -46,17 +45,8 @@ class XingProvider implements ISocialProvider {
* @return bool
*/
public function supportsContact(array $contact):bool {
- $socialprofiles = $contact['X-SOCIALPROFILE'];
- $supports = false;
- if (isset($socialprofiles)) {
- foreach ($socialprofiles as $profile) {
- if (strtolower($profile['type']) == $this->name) {
- $supports = true;
- break;
- }
- }
- }
- return $supports;
+ $socialprofiles = $this->getProfileIds($contact);
+ return isset($socialprofiles) && count($socialprofiles) > 0;
}
/**