test(tiktok): cover MediaItem dimensions and platform max-width helpers
Direct unit tests for the new MediaItem::width()/height() accessors and MediaOptimizer::maxWidthForPlatform(), plus drop a redundant inline comment.
This commit is contained in:
parent
c5fca040a9
commit
13e4d88b71
3 changed files with 56 additions and 3 deletions
|
|
@ -276,9 +276,6 @@ private function publishPhotos(PostPlatform $postPlatform, $mediaCollection, ?st
|
|||
'url' => $this->buildTikTokUrl($postPlatform->socialAccount, $postId),
|
||||
];
|
||||
} finally {
|
||||
// TikTok pulls the images during the synchronous status poll above,
|
||||
// so by the time we reach here the fetch is finished and the
|
||||
// temporary derivatives can be safely removed.
|
||||
if ($derivatives !== []) {
|
||||
Storage::delete($derivatives);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,3 +34,43 @@
|
|||
|
||||
expect($item->isImage())->toBeTrue();
|
||||
});
|
||||
|
||||
test('fromArray reads pixel dimensions from the meta block', function () {
|
||||
$item = MediaItem::fromArray([
|
||||
'path' => 'photo.jpg',
|
||||
'url' => 'https://x/photo.jpg',
|
||||
'meta' => ['width' => 1254, 'height' => 836],
|
||||
]);
|
||||
|
||||
expect($item->width())->toBe(1254)
|
||||
->and($item->height())->toBe(836);
|
||||
});
|
||||
|
||||
test('width and height are null when no meta is present', function () {
|
||||
$item = MediaItem::fromArray(['path' => 'photo.jpg', 'url' => 'https://x/photo.jpg']);
|
||||
|
||||
expect($item->width())->toBeNull()
|
||||
->and($item->height())->toBeNull();
|
||||
});
|
||||
|
||||
test('width and height ignore non-numeric meta values', function () {
|
||||
$item = MediaItem::fromArray([
|
||||
'path' => 'photo.jpg',
|
||||
'url' => 'https://x/photo.jpg',
|
||||
'meta' => ['width' => 'wide', 'height' => null],
|
||||
]);
|
||||
|
||||
expect($item->width())->toBeNull()
|
||||
->and($item->height())->toBeNull();
|
||||
});
|
||||
|
||||
test('numeric string dimensions are coerced to integers', function () {
|
||||
$item = MediaItem::fromArray([
|
||||
'path' => 'photo.jpg',
|
||||
'url' => 'https://x/photo.jpg',
|
||||
'meta' => ['width' => '1080', 'height' => '1920'],
|
||||
]);
|
||||
|
||||
expect($item->width())->toBe(1080)
|
||||
->and($item->height())->toBe(1920);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -111,6 +111,22 @@ function createTestImage(int $width, int $height, string $format = 'image/jpeg')
|
|||
expect($optimized->width())->toBeLessThanOrEqual(1000);
|
||||
});
|
||||
|
||||
it('exposes the configured max width per platform', function () {
|
||||
$optimizer = new MediaOptimizer;
|
||||
|
||||
expect($optimizer->maxWidthForPlatform(Platform::TikTok))->toBe(1080)
|
||||
->and($optimizer->maxWidthForPlatform(Platform::Instagram))->toBe(1440)
|
||||
->and($optimizer->maxWidthForPlatform(Platform::Pinterest))->toBe(1000);
|
||||
});
|
||||
|
||||
it('reports a max width for every platform', function () {
|
||||
$optimizer = new MediaOptimizer;
|
||||
|
||||
foreach (Platform::cases() as $platform) {
|
||||
expect($optimizer->maxWidthForPlatform($platform))->toBeInt()->toBeGreaterThan(0);
|
||||
}
|
||||
});
|
||||
|
||||
it('handles all platforms without error', function () use (&$tempFiles) {
|
||||
$source = createTestImage(1000, 800);
|
||||
$tempFiles[] = $source;
|
||||
|
|
|
|||
Loading…
Reference in a new issue