diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs new file mode 100644 index 000000000..22e87e35d --- /dev/null +++ b/.git-blame-ignore-revs @@ -0,0 +1,7 @@ +# .git-blame-ignore-revs + +# SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors +# SPDX-License-Identifier: AGPL-3.0-or-later + +# Update to coding-standard 1.2.3 +fe16be69e7a10647508f8c0b63383cbb5ffbde84 diff --git a/.nextcloudignore b/.nextcloudignore index ad30e5ae1..046ea96e5 100644 --- a/.nextcloudignore +++ b/.nextcloudignore @@ -3,6 +3,7 @@ .editorconfig .eslintrc.js .git +.git-blame-ignore-revs .github .gitignore .gitlab-ci.yml diff --git a/composer.lock b/composer.lock index 63163ef15..18f45d142 100644 --- a/composer.lock +++ b/composer.lock @@ -180,16 +180,16 @@ }, { "name": "nextcloud/coding-standard", - "version": "v1.2.1", + "version": "v1.2.3", "source": { "type": "git", "url": "https://github.com/nextcloud/coding-standard.git", - "reference": "cf5f18d989ec62fb4cdc7fc92a36baf34b3d829e" + "reference": "bc9c53a5306114b60c4363057aff9c2ed10a54da" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nextcloud/coding-standard/zipball/cf5f18d989ec62fb4cdc7fc92a36baf34b3d829e", - "reference": "cf5f18d989ec62fb4cdc7fc92a36baf34b3d829e", + "url": "https://api.github.com/repos/nextcloud/coding-standard/zipball/bc9c53a5306114b60c4363057aff9c2ed10a54da", + "reference": "bc9c53a5306114b60c4363057aff9c2ed10a54da", "shasum": "" }, "require": { @@ -215,9 +215,9 @@ "description": "Nextcloud coding standards for the php cs fixer", "support": { "issues": "https://github.com/nextcloud/coding-standard/issues", - "source": "https://github.com/nextcloud/coding-standard/tree/v1.2.1" + "source": "https://github.com/nextcloud/coding-standard/tree/v1.2.3" }, - "time": "2024-02-01T14:54:37+00:00" + "time": "2024-08-23T14:32:32+00:00" }, { "name": "nikic/php-parser", diff --git a/lib/Service/Social/MastodonProvider.php b/lib/Service/Social/MastodonProvider.php index 246185fff..ee7934abb 100644 --- a/lib/Service/Social/MastodonProvider.php +++ b/lib/Service/Social/MastodonProvider.php @@ -65,7 +65,7 @@ public function getImageUrl(string $profileUrl):?string { try { $result = $this->httpClient->get($profileUrl, ['headers' => ['Accept' => 'application/json']]); $jsonResult = json_decode($result->getBody(), true); - return $jsonResult["icon"]["url"] ?? null; + return $jsonResult['icon']['url'] ?? null; } catch (\Exception $e) { return null; } @@ -89,12 +89,12 @@ protected function getProfileIds($contact):array { try { [$masto_user, $masto_server] = $masto_user_server; # search for user webfinger - $webfinger = $masto_server . '/.well-known/webfinger?resource=acct:' . $masto_user . '@' . parse_url($masto_server)["host"]; + $webfinger = $masto_server . '/.well-known/webfinger?resource=acct:' . $masto_user . '@' . parse_url($masto_server)['host']; $result = $this->httpClient->get($webfinger); $jsonResult = json_decode($result->getBody(), null, 512, JSON_THROW_ON_ERROR); # find account link foreach ($jsonResult->links as $link) { - if (($link->rel == "self") and ($link->type == "application/activity+json")) { + if (($link->rel == 'self') and ($link->type == 'application/activity+json')) { $profileId = $link->href; $profileIds[] = $profileId; break; @@ -122,7 +122,7 @@ protected function cleanupId(string $candidate):?array { try { $user_server = explode('@', $candidate); if (strpos($candidate, 'http') !== 0) { - $masto_server = "https://" . array_pop($user_server); + $masto_server = 'https://' . array_pop($user_server); $masto_user = array_pop($user_server); } else { $masto_user = array_pop($user_server); diff --git a/lib/Service/Social/TelegramProvider.php b/lib/Service/Social/TelegramProvider.php index e79d3fb5a..3108d62b1 100644 --- a/lib/Service/Social/TelegramProvider.php +++ b/lib/Service/Social/TelegramProvider.php @@ -71,7 +71,7 @@ public function getImageUrls(array $contact):array { * @return string */ protected function cleanupId(string $candidate):string { - $candidate = basename($candidate, ".t.me"); + $candidate = basename($candidate, '.t.me'); if ($candidate[0] === '@') { $candidate = substr($candidate, 1); } diff --git a/lib/Service/SocialApiService.php b/lib/Service/SocialApiService.php index cff8b1fef..a05099379 100644 --- a/lib/Service/SocialApiService.php +++ b/lib/Service/SocialApiService.php @@ -35,9 +35,9 @@ class SocialApiService { private $config; /** @var IClientService */ private $clientService; - /** @var IL10N */ + /** @var IL10N */ private $l10n; - /** @var IURLGenerator */ + /** @var IURLGenerator */ private $urlGen; /** @var CardDavBackend */ private $davBackend; @@ -398,7 +398,7 @@ public function updateAddressbooks(string $userId, ?string $offsetBook = null, ? try { $r = $this->updateContact($addressBook->getURI(), $contact['UID'], $network); - $response = $this->registerUpdateResult($response, $contact['FN'], (int) $r->getStatus()); + $response = $this->registerUpdateResult($response, $contact['FN'], (int)$r->getStatus()); } catch (\Exception $e) { $response = $this->registerUpdateResult($response, $contact['FN'], -1); } diff --git a/lib/Settings/AdminSettings.php b/lib/Settings/AdminSettings.php index b8cac869a..d56df2c89 100644 --- a/lib/Settings/AdminSettings.php +++ b/lib/Settings/AdminSettings.php @@ -53,8 +53,8 @@ public function getSection() { /** * @return int whether the form should be rather on the top or bottom of - * the admin section. The forms are arranged in ascending order of the - * priority values. It is required to return a value between 0 and 100. + * the admin section. The forms are arranged in ascending order of the + * priority values. It is required to return a value between 0 and 100. */ public function getPriority() { return 75; diff --git a/tests/unit/ContactsMenu/Provider/DetailsProviderTest.php b/tests/unit/ContactsMenu/Provider/DetailsProviderTest.php index 8491d25b5..7da3652c1 100644 --- a/tests/unit/ContactsMenu/Provider/DetailsProviderTest.php +++ b/tests/unit/ContactsMenu/Provider/DetailsProviderTest.php @@ -66,63 +66,63 @@ public function testProcessContact() { $resultUri = "$domain/index.php/apps/contacts/direct/contact/$uid~$abUri"; $entry->expects($this->exactly(3)) - ->method('getProperty') - ->will($this->returnValueMap([ - ['UID', $uid], - ['isLocalSystemBook', null], - ['addressbook-key', 1] - ])); + ->method('getProperty') + ->will($this->returnValueMap([ + ['UID', $uid], + ['isLocalSystemBook', null], + ['addressbook-key', 1] + ])); $addressbook->expects($this->once()) - ->method('getKey') - ->willReturn(1); + ->method('getKey') + ->willReturn(1); $addressbook->expects($this->once()) - ->method('getUri') - ->willReturn($abUri); + ->method('getUri') + ->willReturn($abUri); $this->manager->expects($this->once()) - ->method('getUserAddressbooks') - ->willReturn([1 => $addressbook]); + ->method('getUserAddressbooks') + ->willReturn([1 => $addressbook]); // Action icon $this->urlGenerator->expects($this->once()) - ->method('imagePath') - ->with('core', 'actions/info.svg') - ->willReturn($iconUrl); + ->method('imagePath') + ->with('core', 'actions/info.svg') + ->willReturn($iconUrl); // $this->urlGenerator->expects($this->once()) - ->method('linkToRoute') - ->with('contacts.contacts.direct', [ - 'contact' => $uid . '~' . $abUri - ]) - ->willReturn("/apps/contacts/direct/contact/$uid~$abUri"); + ->method('linkToRoute') + ->with('contacts.contacts.direct', [ + 'contact' => $uid . '~' . $abUri + ]) + ->willReturn("/apps/contacts/direct/contact/$uid~$abUri"); // Action icon and contact absolute urls $this->urlGenerator->expects($this->exactly(2)) - ->method('getAbsoluteURL') - ->will($this->returnValueMap([ - [$iconUrl, "$domain/$iconUrl"], - ["/apps/contacts/direct/contact/$uid~$abUri", $resultUri] - ])); + ->method('getAbsoluteURL') + ->will($this->returnValueMap([ + [$iconUrl, "$domain/$iconUrl"], + ["/apps/contacts/direct/contact/$uid~$abUri", $resultUri] + ])); // Translations $this->l10n->expects($this->once()) - ->method('t') - ->with('Details') - ->willReturnArgument(0); + ->method('t') + ->with('Details') + ->willReturnArgument(0); $this->actionFactory->expects($this->once()) - ->method('newLinkAction') - ->with($this->equalTo("$domain/$iconUrl"), $this->equalTo('Details'), $this->equalTo($resultUri)) - ->willReturn($action); + ->method('newLinkAction') + ->with($this->equalTo("$domain/$iconUrl"), $this->equalTo('Details'), $this->equalTo($resultUri)) + ->willReturn($action); $action->expects($this->once()) - ->method('setPriority') - ->with($this->equalTo(0)); + ->method('setPriority') + ->with($this->equalTo(0)); $entry->expects($this->once()) - ->method('addAction') - ->with($action); + ->method('addAction') + ->with($action); $this->provider->process($entry); } @@ -130,11 +130,11 @@ public function testProcessContact() { public function testProcessNoUID() { $entry = $this->createMock(IEntry::class); $entry->expects($this->once()) - ->method('getProperty') - ->with($this->equalTo('UID')) - ->willReturn(null); + ->method('getProperty') + ->with($this->equalTo('UID')) + ->willReturn(null); $entry->expects($this->never()) - ->method('addAction'); + ->method('addAction'); $this->provider->process($entry); } @@ -142,13 +142,13 @@ public function testProcessNoUID() { public function testProcessSystemContact() { $entry = $this->createMock(IEntry::class); $entry->expects($this->exactly(2)) - ->method('getProperty') - ->will($this->returnValueMap([ - ['UID', 1234], - ['isLocalSystemBook', true] - ])); + ->method('getProperty') + ->will($this->returnValueMap([ + ['UID', 1234], + ['isLocalSystemBook', true] + ])); $entry->expects($this->never()) - ->method('addAction'); + ->method('addAction'); $this->provider->process($entry); } diff --git a/tests/unit/Controller/ContactsControllerTest.php b/tests/unit/Controller/ContactsControllerTest.php index b8c624adf..59130849f 100644 --- a/tests/unit/Controller/ContactsControllerTest.php +++ b/tests/unit/Controller/ContactsControllerTest.php @@ -19,7 +19,7 @@ class ContactsControllerTest extends TestCase { /** @var IL10N|MockObject */ private $l10n; - /** @var IURLGenerator|MockObject*/ + /** @var IURLGenerator|MockObject */ private $urlGenerator; diff --git a/tests/unit/Controller/PageControllerTest.php b/tests/unit/Controller/PageControllerTest.php index 38e47003e..b958d92ed 100644 --- a/tests/unit/Controller/PageControllerTest.php +++ b/tests/unit/Controller/PageControllerTest.php @@ -25,7 +25,7 @@ class PageControllerTest extends TestCase { /** @var IRequest|MockObject */ private $request; - /** @var IConfig|MockObject*/ + /** @var IConfig|MockObject */ private $config; /** @var IInitialStateService|MockObject */ @@ -37,13 +37,13 @@ class PageControllerTest extends TestCase { /** @var IUserSession|MockObject */ private $userSession; - /** @var SocialApiService|MockObject*/ + /** @var SocialApiService|MockObject */ private $socialApi; - /** @var IAppManager|MockObject*/ + /** @var IAppManager|MockObject */ private $appManager; - /** @var CompareVersion|MockObject*/ + /** @var CompareVersion|MockObject */ private $compareVersion; protected function setUp(): void { diff --git a/tests/unit/Service/Social/DiasporaProviderTest.php b/tests/unit/Service/Social/DiasporaProviderTest.php index 4bf5a4ed2..3b3ef68f3 100644 --- a/tests/unit/Service/Social/DiasporaProviderTest.php +++ b/tests/unit/Service/Social/DiasporaProviderTest.php @@ -119,18 +119,18 @@ public function dataProviderGetImageUrls() { public function testGetImageUrls($contact, $urls, $htmls, $imgs) { if (count($urls)) { $this->response - ->method('getBody') - ->willReturnOnConsecutiveCalls(...$htmls); + ->method('getBody') + ->willReturnOnConsecutiveCalls(...$htmls); $urlArgs = array_map(function ($url) { return [$url]; }, $urls); $this->client - ->expects($this->exactly(count($urls))) - ->method('get') - ->withConsecutive(...$urlArgs) - ->willReturn($this->response); + ->expects($this->exactly(count($urls))) + ->method('get') + ->withConsecutive(...$urlArgs) + ->willReturn($this->response); } $result = $this->provider->getImageUrls($contact); @@ -150,14 +150,14 @@ public function testGetImageUrlLoop() { $img = $url2.'-large-avatar.jpg'; $this->response - ->method('getBody') - ->willReturnOnConsecutiveCalls($html1, $html2); + ->method('getBody') + ->willReturnOnConsecutiveCalls($html1, $html2); $this->client - ->expects($this->exactly(2)) - ->method('get') - ->withConsecutive([$url1], [$url2]) - ->willReturn($this->response); + ->expects($this->exactly(2)) + ->method('get') + ->withConsecutive([$url1], [$url2]) + ->willReturn($this->response); $result = $this->provider->getImageUrls($contact); $this->assertEquals([$img], $result); diff --git a/tests/unit/Service/Social/FacebookProviderTest.php b/tests/unit/Service/Social/FacebookProviderTest.php index 52d10542f..454171a01 100644 --- a/tests/unit/Service/Social/FacebookProviderTest.php +++ b/tests/unit/Service/Social/FacebookProviderTest.php @@ -120,18 +120,18 @@ public function testGetImageUrlLookup() { $html1 = '"entity_id":"1234567"'; $this->response - ->method('getBody') - ->willReturn($html1); + ->method('getBody') + ->willReturn($html1); $this->response - ->method('getStatusCode') - ->willReturn(200); + ->method('getStatusCode') + ->willReturn(200); $this->client - ->expects($this->once()) - ->method('get') - ->with($url1) - ->willReturn($this->response); + ->expects($this->once()) + ->method('get') + ->with($url1) + ->willReturn($this->response); $result = $this->provider->getImageUrls($contact); $this->assertEquals([$url2], $result); diff --git a/tests/unit/Service/Social/GravatarProviderTest.php b/tests/unit/Service/Social/GravatarProviderTest.php index d15bc6189..adf1e3a58 100644 --- a/tests/unit/Service/Social/GravatarProviderTest.php +++ b/tests/unit/Service/Social/GravatarProviderTest.php @@ -25,7 +25,7 @@ public function dataProviderSupportsContact() { ]; $contactWithoutEmail = [ - 'PHONE' => [['value' => 'one'], ["value" => "two"]] + 'PHONE' => [['value' => 'one'], ['value' => 'two']] ]; return [ @@ -44,11 +44,11 @@ public function testSupportsContact($contact, $expected) { public function dataProviderGetImageUrls() { $contactWithEmail = [ - 'EMAIL' => [["value" => "one"], ["value" => "two"]] + 'EMAIL' => [['value' => 'one'], ['value' => 'two']] ]; $contactWithoutEmail = [ - 'PHONE' => [["value" => "one"], ["value" => "two"]] + 'PHONE' => [['value' => 'one'], ['value' => 'two']] ]; $urls = []; @@ -56,7 +56,7 @@ public function dataProviderGetImageUrls() { foreach ($contactWithEmail['EMAIL'] as $email) { $hash = md5(strtolower(trim($email['value']))); $recipe = 'https://www.gravatar.com/avatar/{hash}?s=720&d=404'; - $urls[] = str_replace("{hash}", $hash, $recipe); + $urls[] = str_replace('{hash}', $hash, $recipe); } return [ diff --git a/tests/unit/Service/Social/InstagramProviderTest.php b/tests/unit/Service/Social/InstagramProviderTest.php index b3a88a686..c4321c633 100644 --- a/tests/unit/Service/Social/InstagramProviderTest.php +++ b/tests/unit/Service/Social/InstagramProviderTest.php @@ -48,15 +48,15 @@ protected function setUp(): void { public function dataProviderSupportsContact() { $contactWithSocial = [ 'X-SOCIALPROFILE' => [ - ["value" => "username1", "type" => "instagram"], - ["value" => "username2", "type" => "instagram"] + ['value' => 'username1', 'type' => 'instagram'], + ['value' => 'username2', 'type' => 'instagram'] ] ]; $contactWithoutSocial = [ 'X-SOCIALPROFILE' => [ - ["value" => "one", "type" => "social2"], - ["value" => "two", "type" => "social1"] + ['value' => 'one', 'type' => 'social2'], + ['value' => 'two', 'type' => 'social1'] ] ]; @@ -77,31 +77,31 @@ public function testSupportsContact($contact, $expected) { public function dataProviderGetImageUrls() { $contactWithSocial = [ 'X-SOCIALPROFILE' => [ - ["value" => "username1", "type" => "instagram"], - ["value" => "username2", "type" => "instagram"] + ['value' => 'username1', 'type' => 'instagram'], + ['value' => 'username2', 'type' => 'instagram'] ] ]; $contactWithSocialUrls = [ - "https://www.instagram.com/username1/?__a=1", - "https://www.instagram.com/username2/?__a=1", + 'https://www.instagram.com/username1/?__a=1', + 'https://www.instagram.com/username2/?__a=1', ]; $contactWithSocialJson = [ json_encode( - ["graphql" => ["user" => ["profile_pic_url_hd" => "username1.jpg"]]] + ['graphql' => ['user' => ['profile_pic_url_hd' => 'username1.jpg']]] ), json_encode( - ["graphql" => ["user" => ["profile_pic_url_hd" => "username2.jpg"]]] + ['graphql' => ['user' => ['profile_pic_url_hd' => 'username2.jpg']]] ) ]; $contactWithSocialImgs = [ - "username1.jpg", - "username2.jpg" + 'username1.jpg', + 'username2.jpg' ]; $contactWithoutSocial = [ 'X-SOCIALPROFILE' => [ - ["value" => "one", "type" => "social2"], - ["value" => "two", "type" => "social1"] + ['value' => 'one', 'type' => 'social2'], + ['value' => 'two', 'type' => 'social1'] ] ]; $contactWithoutSocialUrls = []; @@ -129,14 +129,14 @@ public function dataProviderGetImageUrls() { */ public function testGetImageUrls($contact, $json, $urls, $imgs) { if (count($urls)) { - $this->response->method("getBody")->willReturnOnConsecutiveCalls(...$json); + $this->response->method('getBody')->willReturnOnConsecutiveCalls(...$json); $this->client - ->expects($this->exactly(count($urls))) - ->method("get") - ->withConsecutive(...array_map(function ($a) { - return [$a]; - }, $urls)) - ->willReturn($this->response); + ->expects($this->exactly(count($urls))) + ->method('get') + ->withConsecutive(...array_map(function ($a) { + return [$a]; + }, $urls)) + ->willReturn($this->response); } diff --git a/tests/unit/Service/Social/MastodonProviderTest.php b/tests/unit/Service/Social/MastodonProviderTest.php index 4deb568d1..4317ba98a 100644 --- a/tests/unit/Service/Social/MastodonProviderTest.php +++ b/tests/unit/Service/Social/MastodonProviderTest.php @@ -43,15 +43,15 @@ protected function setUp(): void { public function dataProviderSupportsContact() { $contactWithSocial = [ 'X-SOCIALPROFILE' => [ - ["value" => "user1@cloud1", "type" => "mastodon"], - ["value" => "user2@cloud2", "type" => "mastodon"] + ['value' => 'user1@cloud1', 'type' => 'mastodon'], + ['value' => 'user2@cloud2', 'type' => 'mastodon'] ] ]; $contactWithoutSocial = [ 'X-SOCIALPROFILE' => [ - ["value" => "one", "type" => "social2"], - ["value" => "two", "type" => "social1"] + ['value' => 'one', 'type' => 'social2'], + ['value' => 'two', 'type' => 'social1'] ] ]; @@ -65,7 +65,7 @@ public function dataProviderSupportsContact() { * @dataProvider dataProviderSupportsContact */ public function testSupportsContact($contact, $expected) { - $this->client->method("get")->willReturn($this->response); + $this->client->method('get')->willReturn($this->response); $this->body = '{ "subject": "acct:user1@cloud1", "aliases": [ @@ -80,7 +80,7 @@ public function testSupportsContact($contact, $expected) { } ] }'; - $this->response->method("getBody")->willReturn($this->body); + $this->response->method('getBody')->willReturn($this->body); $result = $this->provider->supportsContact($contact); $this->assertEquals($expected, $result); } @@ -88,21 +88,21 @@ public function testSupportsContact($contact, $expected) { public function dataProviderGetImageUrls() { $contactWithSocial = [ 'X-SOCIALPROFILE' => [ - ["value" => "user1@cloud1", "type" => "mastodon"], - ["value" => "@user2@cloud2", "type" => "mastodon"], - ["value" => "https://cloud3/@user3", "type" => "mastodon"], - ["value" => "https://cloud/wrongSyntax", "type" => "mastodon"], - ["value" => "@wrongSyntax", "type" => "mastodon"], - ["value" => "wrongSyntax", "type" => "mastodon"] + ['value' => 'user1@cloud1', 'type' => 'mastodon'], + ['value' => '@user2@cloud2', 'type' => 'mastodon'], + ['value' => 'https://cloud3/@user3', 'type' => 'mastodon'], + ['value' => 'https://cloud/wrongSyntax', 'type' => 'mastodon'], + ['value' => '@wrongSyntax', 'type' => 'mastodon'], + ['value' => 'wrongSyntax', 'type' => 'mastodon'] ] ]; $contactWithSocialUrls = [ - "https://cloud1/.well-known/webfinger?resource=acct:user1@cloud1", - "https://cloud2/.well-known/webfinger?resource=acct:user2@cloud2", - "https://cloud3/.well-known/webfinger?resource=acct:user3@cloud3", - "https://cloud1/users/user1", - "https://cloud2/users/user2", - "https://cloud3/users/user3", + 'https://cloud1/.well-known/webfinger?resource=acct:user1@cloud1', + 'https://cloud2/.well-known/webfinger?resource=acct:user2@cloud2', + 'https://cloud3/.well-known/webfinger?resource=acct:user3@cloud3', + 'https://cloud1/users/user1', + 'https://cloud2/users/user2', + 'https://cloud3/users/user3', ]; $contactWithSocialApi = [ '{"subject":"acct:user1@cloud1","aliases":["https://cloud1/@user1","https://cloud1/users/user1"],"links":[{"rel":"self","type":"application/activity+json","href":"https://cloud1/users/user1"}]}', @@ -113,15 +113,15 @@ public function dataProviderGetImageUrls() { '{"id":"3","icon":{"url":"user3.jpg"}}', ]; $contactWithSocialImgs = [ - "user1.jpg", - "user2.jpg", - "user3.jpg" + 'user1.jpg', + 'user2.jpg', + 'user3.jpg' ]; $contactWithoutSocial = [ 'X-SOCIALPROFILE' => [ - ["value" => "one", "type" => "socialx"], - ["value" => "two", "type" => "socialy"] + ['value' => 'one', 'type' => 'socialx'], + ['value' => 'two', 'type' => 'socialy'] ] ]; $contactWithoutSocialUrls = []; @@ -149,14 +149,14 @@ public function dataProviderGetImageUrls() { */ public function testGetImageUrls($contact, $api, $urls, $imgs) { if (count($urls)) { - $this->response->method("getBody")->willReturnOnConsecutiveCalls(...$api); + $this->response->method('getBody')->willReturnOnConsecutiveCalls(...$api); $this->client - ->expects($this->exactly(count($urls))) - ->method("get") - ->withConsecutive(...array_map(function ($a) { - return [$a]; - }, $urls)) - ->willReturn($this->response); + ->expects($this->exactly(count($urls))) + ->method('get') + ->withConsecutive(...array_map(function ($a) { + return [$a]; + }, $urls)) + ->willReturn($this->response); } $result = $this->provider->getImageUrls($contact); $this->assertEquals($imgs, $result); diff --git a/tests/unit/Service/Social/TelegramProviderTest.php b/tests/unit/Service/Social/TelegramProviderTest.php index 556760237..815a4bb3e 100644 --- a/tests/unit/Service/Social/TelegramProviderTest.php +++ b/tests/unit/Service/Social/TelegramProviderTest.php @@ -144,12 +144,12 @@ public function testGetImageUrls($contact, $htmls, $urls, $imgs) { if (count($urls)) { $this->response->method('getBody')->willReturnOnConsecutiveCalls(...$htmls); $this->client - ->expects($this->exactly(count($urls))) - ->method('get') - ->withConsecutive(...array_map(function ($a) { - return [$a]; - }, $urls)) - ->willReturn($this->response); + ->expects($this->exactly(count($urls))) + ->method('get') + ->withConsecutive(...array_map(function ($a) { + return [$a]; + }, $urls)) + ->willReturn($this->response); } diff --git a/tests/unit/Service/Social/XingProviderTest.php b/tests/unit/Service/Social/XingProviderTest.php index 2c7e10761..807e0f14f 100644 --- a/tests/unit/Service/Social/XingProviderTest.php +++ b/tests/unit/Service/Social/XingProviderTest.php @@ -50,8 +50,8 @@ public function dataProviderSupportsContact() { $contactWithoutSocial = [ 'X-SOCIALPROFILE' => [ - ['value' => 'one', "type" => "social2"], - ["value" => "two", "type" => "social1"] + ['value' => 'one', 'type' => 'social2'], + ['value' => 'two', 'type' => 'social1'] ] ]; @@ -71,21 +71,21 @@ public function testSupportsContact($contact, $expected) { public function dataProviderGetImageUrls() { $contactImages = [ - "username1" => "https://profile-images-abcusername1.jpg", - "username2" => "https://profile-images-abcusername2.jpg", - "username3" => "https://".urlencode("profile-images-abc.ÄÖÜ/äöü_ß.jpg") + 'username1' => 'https://profile-images-abcusername1.jpg', + 'username2' => 'https://profile-images-abcusername2.jpg', + 'username3' => 'https://'.urlencode('profile-images-abc.ÄÖÜ/äöü_ß.jpg') ]; $contactWithSocial = [ 'X-SOCIALPROFILE' => [ - ["value" => "username1", "type" => "xing"], - ["value" => "username2", "type" => "xing"], - ["value" => "username3", "type" => "xing"] + ['value' => 'username1', 'type' => 'xing'], + ['value' => 'username2', 'type' => 'xing'], + ['value' => 'username3', 'type' => 'xing'] ] ]; $contactWithSocialUrls = [ - "https://www.xing.com/profile/username1", - "https://www.xing.com/profile/username2", - "https://www.xing.com/profile/username3" + 'https://www.xing.com/profile/username1', + 'https://www.xing.com/profile/username2', + 'https://www.xing.com/profile/username3' ]; $contactWithSocialHtml = array_map(function ($profile) use ($contactImages) { return ''; @@ -96,8 +96,8 @@ public function dataProviderGetImageUrls() { $contactWithoutSocial = [ 'X-SOCIALPROFILE' => [ - ["value" => "one", "type" => "social2"], - ["value" => "two", "type" => "social1"] + ['value' => 'one', 'type' => 'social2'], + ['value' => 'two', 'type' => 'social1'] ] ]; $contactWithoutSocialUrls = []; @@ -126,18 +126,18 @@ public function dataProviderGetImageUrls() { public function testGetImageUrls($contact, $urls, $htmls, $imgs) { if (count($urls)) { $this->response - ->method('getBody') - ->willReturnOnConsecutiveCalls(...$htmls); + ->method('getBody') + ->willReturnOnConsecutiveCalls(...$htmls); $urlArgs = array_map(function ($url) { return [$url]; }, $urls); $this->client - ->expects($this->exactly(count($urls))) - ->method('get') - ->withConsecutive(...$urlArgs) - ->willReturn($this->response); + ->expects($this->exactly(count($urls))) + ->method('get') + ->withConsecutive(...$urlArgs) + ->willReturn($this->response); } $result = $this->provider->getImageUrls($contact); diff --git a/tests/unit/Service/SocialApiServiceTest.php b/tests/unit/Service/SocialApiServiceTest.php index ec6b54407..f6f70e194 100644 --- a/tests/unit/Service/SocialApiServiceTest.php +++ b/tests/unit/Service/SocialApiServiceTest.php @@ -37,9 +37,9 @@ class SocialApiServiceTest extends TestCase { private $config; /** @var IClientService|MockObject */ private $clientService; - /** @var IL10N|MockObject */ + /** @var IL10N|MockObject */ private $l10n; - /** @var IURLGenerator|MockObject */ + /** @var IURLGenerator|MockObject */ private $urlGen; /** @var CardDavBackend|MockObject */ private $davBackend; @@ -49,15 +49,15 @@ class SocialApiServiceTest extends TestCase { private $imageResizer; public function allSocialProfileProviders(): array { - $body = "the body"; - $imageType = "jpg"; + $body = 'the body'; + $imageType = 'jpg'; $contact = [ 'URI' => '3225c0d5-1bd2-43e5-a08c-4e65eaa406b0', 'VERSION' => '4.0' ]; $connector = $this->createMock(ISocialProvider::class); $connector->method('supportsContact')->willReturn(true); - $connector->method('getImageUrls')->willReturn(["https://https://url1.com/an-url/an-url"]); + $connector->method('getImageUrls')->willReturn(['https://https://url1.com/an-url/an-url']); $connectorNoSupport = $this->createMock(ISocialProvider::class); $connectorNoSupport->method('supportsContact')->willReturn(false); @@ -83,11 +83,11 @@ public function allSocialProfileProviders(): array { ->willReturn([$contact]); return [ - 'no address book found' => [null, [], "", "", Http::STATUS_BAD_REQUEST], - 'no contact found' => [[$addressbookEmpty], [], "", "", Http::STATUS_PRECONDITION_FAILED], - 'no supporting contacts found' => [[$addressbook], [$connectorNoSupport], "", "", Http::STATUS_PRECONDITION_FAILED], - 'no url found' => [[$addressbook], [$connectorNoUrl], "", "", Http::STATUS_BAD_REQUEST], - 'no image found' => [[$addressbook], [$connector], "", "", Http::STATUS_NOT_FOUND], + 'no address book found' => [null, [], '', '', Http::STATUS_BAD_REQUEST], + 'no contact found' => [[$addressbookEmpty], [], '', '', Http::STATUS_PRECONDITION_FAILED], + 'no supporting contacts found' => [[$addressbook], [$connectorNoSupport], '', '', Http::STATUS_PRECONDITION_FAILED], + 'no url found' => [[$addressbook], [$connectorNoUrl], '', '', Http::STATUS_BAD_REQUEST], + 'no image found' => [[$addressbook], [$connector], '', '', Http::STATUS_NOT_FOUND], 'image found' => [[$addressbook], [$connector], $body, $imageType, Http::STATUS_OK] ]; } @@ -167,26 +167,26 @@ public function testUpdateContactWithoutNetwork($addressbooks, $providers, $body ->willReturn($body); $result = $this->service - ->updateContact( - 'contacts', - '3225c0d5-1bd2-43e5-a08c-4e65eaa406b0', - null); + ->updateContact( + 'contacts', + '3225c0d5-1bd2-43e5-a08c-4e65eaa406b0', + null); $this->assertEquals($status, $result->getStatus()); } public function testUpdateContactWithNetworkVersion3() { - $network = "mastodon"; - $body = "the body"; - $imageType = "jpg"; - $addressBookId = "contacts"; - $contactId = "3225c0d5-1bd2-43e5-a08c-4e65eaa406b0"; + $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(["https://url1.com/an-url"]); + $provider->method('getImageUrls')->willReturn(['https://url1.com/an-url']); $addressbook = $this->createMock(IAddressBook::class); $addressbook @@ -234,32 +234,32 @@ public function testUpdateContactWithNetworkVersion3() { ]; $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); + ->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); + ->updateContact( + $addressBookId, + $contactId, + $network); $this->assertEquals(Http::STATUS_OK, $result->getStatus()); } public function testUpdateContactWithNetworkVersion4() { - $network = "mastodon"; - $body = "the body"; - $imageType = "jpg"; - $addressBookId = "contacts"; - $contactId = "3225c0d5-1bd2-43e5-a08c-4e65eaa406b0"; + $network = 'mastodon'; + $body = 'the body'; + $imageType = 'jpg'; + $addressBookId = 'contacts'; + $contactId = '3225c0d5-1bd2-43e5-a08c-4e65eaa406b0'; $contact = [ 'URI' => $contactId, 'VERSION' => '4.0' ]; $provider = $this->createMock(ISocialProvider::class); $provider->method('supportsContact')->willReturn(true); - $provider->method('getImageUrls')->willReturn(["https://url1.com/an-url"]); + $provider->method('getImageUrls')->willReturn(['https://url1.com/an-url']); $addressbook = $this->createMock(IAddressBook::class); $addressbook @@ -303,19 +303,19 @@ public function testUpdateContactWithNetworkVersion4() { $changes = [ 'URI' => $contact['URI'], 'VERSION' => $contact['VERSION'], - 'PHOTO' => "data:".$imageType.";base64," . base64_encode($body) + 'PHOTO' => 'data:'.$imageType.';base64,' . 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); + ->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); + ->updateContact( + $addressBookId, + $contactId, + $network); $this->assertEquals(Http::STATUS_OK, $result->getStatus()); } @@ -331,7 +331,7 @@ protected function setupAddressbooks() { 'UID' => '22222222-2222-2222-2222-222222222222', 'FN' => 'Valid Contact Two', 'VERSION' => '4.0', - 'PHOTO' => "data:someHeader;base64," . base64_encode('someBody'), + 'PHOTO' => 'data:someHeader;base64,' . base64_encode('someBody'), 'X-SOCIALPROFILE' => [['type' => 'someNetwork', 'value' => 'someId2']], ]; $emptyContact = [ @@ -388,17 +388,17 @@ protected function setupAddressbooks() { ]; $providerUrlMap = [ - [$validContact1, ["https://url1.com/an-url"]], + [$validContact1, ['https://url1.com/an-url']], [$emptyContact, []], [$invalidContact, []], - [$validContact2, ["https://url1.com/an-url"]] + [$validContact2, ['https://url1.com/an-url']] ]; $provider = $this->createMock(ISocialProvider::class); $provider->method('getImageUrls') - ->will($this->returnValueMap($providerUrlMap)); + ->will($this->returnValueMap($providerUrlMap)); $provider->method('supportsContact') - ->will($this->returnValueMap($providerSupportsMap)); + ->will($this->returnValueMap($providerSupportsMap)); $this->socialProvider ->method('getSocialConnectors')