diff --git a/app/Jobs/SaveProfileImage.php b/app/Jobs/SaveProfileImage.php index 4183d587..dd5422a9 100644 --- a/app/Jobs/SaveProfileImage.php +++ b/app/Jobs/SaveProfileImage.php @@ -42,6 +42,14 @@ class SaveProfileImage implements ShouldQueue $photo = Arr::get($author, 'properties.photo.0'); $home = Arr::get($author, 'properties.url.0'); + if (is_array($photo) && array_key_exists('value', $photo)) { + $photo = $photo['value']; + } + + if (is_array($home)) { + $home = array_shift($home); + } + //dont save pbs.twimg.com links if ( $photo diff --git a/tests/Unit/Jobs/SaveProfileImageJobTest.php b/tests/Unit/Jobs/SaveProfileImageJobTest.php index d29f0cc9..e2bbdd4b 100644 --- a/tests/Unit/Jobs/SaveProfileImageJobTest.php +++ b/tests/Unit/Jobs/SaveProfileImageJobTest.php @@ -106,4 +106,63 @@ class SaveProfileImageJobTest extends TestCase public_path() . '/assets/profile-images/example.org/image' ); } + + /** @test */ + public function weGetUrlFromPhotoObjectIfAltTextIsProvided(): void + { + $mock = new MockHandler([ + new Response(200, ['Content-Type' => 'image/jpeg'], 'fake jpeg image'), + ]); + $handler = HandlerStack::create($mock); + $client = new Client(['handler' => $handler]); + $this->app->instance(Client::class, $client); + $mf = ['items' => []]; + $author = [ + 'properties' => [ + 'photo' => [[ + 'value' => 'https://example.org/profile.jpg', + 'alt' => null, + ]], + 'url' => ['https://example.org'], + ], + ]; + $authorship = $this->createMock(Authorship::class); + $authorship->method('findAuthor') + ->willReturn($author); + + $job = new SaveProfileImage($mf); + $job->handle($authorship); + $this->assertFileExists(public_path() . '/assets/profile-images/example.org/image'); + } + + /** @test */ + public function useFirstUrlIfMultipleHomepagesAreProvided(): void + { + $mock = new MockHandler([ + new Response(200, ['Content-Type' => 'image/jpeg'], 'fake jpeg image'), + ]); + $handler = HandlerStack::create($mock); + $client = new Client(['handler' => $handler]); + $this->app->instance(Client::class, $client); + $mf = ['items' => []]; + $author = [ + 'properties' => [ + 'photo' => [[ + 'value' => 'https://example.org/profile.jpg', + 'alt' => null, + ]], + 'url' => [[ + 'https://example.org', + 'https://example.com', + ]], + ], + ]; + $authorship = $this->createMock(Authorship::class); + $authorship->method('findAuthor') + ->willReturn($author); + + $job = new SaveProfileImage($mf); + $job->handle($authorship); + $this->assertFileExists(public_path() . '/assets/profile-images/example.org/image'); + } }