From 887b2aba4ef830d45b7be5a0a8553edd670ff6e7 Mon Sep 17 00:00:00 2001 From: call-me-matt Date: Sun, 1 Jan 2023 15:18:40 +0100 Subject: use Mastodon API instead of scraping fixes #3151 Signed-off-by: call-me-matt --- tests/unit/Service/Social/MastodonProviderTest.php | 39 ++++++++++++++-------- 1 file changed, 25 insertions(+), 14 deletions(-) (limited to 'tests') diff --git a/tests/unit/Service/Social/MastodonProviderTest.php b/tests/unit/Service/Social/MastodonProviderTest.php index 9611bf6b..db1d6fc3 100644 --- a/tests/unit/Service/Social/MastodonProviderTest.php +++ b/tests/unit/Service/Social/MastodonProviderTest.php @@ -90,20 +90,33 @@ class MastodonProviderTest extends TestCase { $contactWithSocial = [ 'X-SOCIALPROFILE' => [ ["value" => "user1@cloud1", "type" => "mastodon"], - ["value" => "user2@cloud2", "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/@user1", - "https://cloud2/@user2", + "https://cloud1/api/v2/search?q=user1", + "https://cloud2/api/v2/search?q=user2", + "https://cloud3//api/v2/search?q=user3", + "https://cloud1/api/v1/accounts/1", + "https://cloud2/api/v1/accounts/2", + "https://cloud3//api/v1/accounts/3" ]; - $contactWithSocialHtml = [ - '', - '' + $contactWithSocialApi = [ + '{"accounts":[{"id":"1","username":"user1"}]}', + '{"accounts":[{"id":"2","username":"user2"}]}', + '{"accounts":[{"id":"3","username":"user3"}]}', + '{"id":"1","avatar":"user1.jpg"}', + '{"id":"2","avatar":"user2.jpg"}', + '{"id":"3","avatar":"user3.jpg"}' ]; $contactWithSocialImgs = [ "user1.jpg", - "user2.jpg" + "user2.jpg", + "user3.jpg" ]; $contactWithoutSocial = [ @@ -113,19 +126,19 @@ class MastodonProviderTest extends TestCase { ] ]; $contactWithoutSocialUrls = []; - $contactWithoutSocialHtml = []; + $contactWithoutSocialApi = []; $contactWithoutSocialImgs = []; return [ 'contact with mastodon fields' => [ $contactWithSocial, - $contactWithSocialHtml, + $contactWithSocialApi, $contactWithSocialUrls, $contactWithSocialImgs ], 'contact without mastodon fields' => [ $contactWithoutSocial, - $contactWithoutSocialHtml, + $contactWithoutSocialApi, $contactWithoutSocialUrls, $contactWithoutSocialImgs ] @@ -135,9 +148,9 @@ class MastodonProviderTest extends TestCase { /** * @dataProvider dataProviderGetImageUrls */ - public function testGetImageUrls($contact, $htmls, $urls, $imgs) { + public function testGetImageUrls($contact, $api, $urls, $imgs) { if (count($urls)) { - $this->response->method("getBody")->willReturnOnConsecutiveCalls(...$htmls); + $this->response->method("getBody")->willReturnOnConsecutiveCalls(...$api); $this->client ->expects($this->exactly(count($urls))) ->method("get") @@ -146,8 +159,6 @@ class MastodonProviderTest extends TestCase { }, $urls)) ->willReturn($this->response); } - - $result = $this->provider->getImageUrls($contact); $this->assertEquals($imgs, $result); } -- cgit v1.2.3