refactor: Refactor and add tests for SaveProfileImage feature
- Add error handling checks for photo and home - Add 3 new tests and modify an existing test for SaveProfileImageJob - Test getting URL from photo object if alt text is provided - Test using the first URL if multiple homepages are provided
This commit is contained in:
parent
58ee36c932
commit
dabd03f556
2 changed files with 67 additions and 0 deletions
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue