Centralize the per-platform mb_substr truncation that every publisher was repeating into MediaItem::altTextFor(Platform), delete each publisher's private altFor() helper, and clarify the Platform::altTextMaxLength() docblock so it doesn't imply Instagram's documented 1000-char cap is a guess. Add the assertions review flagged as missing: LinkedInPage/ InstagramFacebook alt-text caps, non-string and literal-"0" alt_text normalization, altTextFor() truncation/unsupported-platform behavior, Mastodon's no-description-part case, and the public API's accept/reject path for media.*.meta.alt_text.
32 lines
1.5 KiB
PHP
32 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Enums\SocialAccount\Platform;
|
|
|
|
test('altTextMaxLength returns the documented cap for supporting platforms', function () {
|
|
expect(Platform::Bluesky->altTextMaxLength())->toBe(2000)
|
|
->and(Platform::X->altTextMaxLength())->toBe(1000)
|
|
->and(Platform::Mastodon->altTextMaxLength())->toBe(1500)
|
|
->and(Platform::LinkedIn->altTextMaxLength())->toBe(4086)
|
|
->and(Platform::LinkedInPage->altTextMaxLength())->toBe(4086)
|
|
->and(Platform::Instagram->altTextMaxLength())->toBe(1000)
|
|
->and(Platform::InstagramFacebook->altTextMaxLength())->toBe(1000)
|
|
->and(Platform::Pinterest->altTextMaxLength())->toBe(500)
|
|
->and(Platform::Discord->altTextMaxLength())->toBe(1024)
|
|
->and(Platform::Facebook->altTextMaxLength())->toBe(1000)
|
|
->and(Platform::Threads->altTextMaxLength())->toBe(1000);
|
|
});
|
|
|
|
test('altTextMaxLength is null for platforms without alt-text support', function () {
|
|
expect(Platform::TikTok->altTextMaxLength())->toBeNull()
|
|
->and(Platform::Telegram->altTextMaxLength())->toBeNull()
|
|
->and(Platform::YouTube->altTextMaxLength())->toBeNull();
|
|
});
|
|
|
|
test('supportsAltText mirrors altTextMaxLength', function () {
|
|
expect(Platform::Bluesky->supportsAltText())->toBeTrue()
|
|
->and(Platform::LinkedInPage->supportsAltText())->toBeTrue()
|
|
->and(Platform::InstagramFacebook->supportsAltText())->toBeTrue()
|
|
->and(Platform::TikTok->supportsAltText())->toBeFalse();
|
|
});
|