feat: use xpier media library for uploads and markdown embeds
Store media:ID in post bodies instead of CDN URLs, and keep sablog attach tokens as a fallback. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use App\Blog\Support\MarkdownMediaEmbed;
|
||||
use Tests\TestCase;
|
||||
use Xpier\FilamentMediaLibrary\Models\MediaLibrary;
|
||||
|
||||
class MarkdownMediaEmbedTest extends TestCase
|
||||
{
|
||||
public function test_markdown_image_snippet_uses_media_protocol_not_url(): void
|
||||
{
|
||||
$media = new MediaLibrary([
|
||||
'alt_text' => 'Hero shot',
|
||||
'type' => MediaLibrary::TYPE_IMAGE,
|
||||
'mime_type' => 'image/jpeg',
|
||||
'original_name' => 'hero.jpg',
|
||||
'path' => 'media/library/articles/hero.jpg',
|
||||
]);
|
||||
$media->id = 12;
|
||||
|
||||
$snippet = app(MarkdownMediaEmbed::class)->snippet($media, 'markdown');
|
||||
|
||||
$this->assertSame('', $snippet);
|
||||
$this->assertStringNotContainsString('http', $snippet);
|
||||
$this->assertStringNotContainsString('/storage/', $snippet);
|
||||
}
|
||||
|
||||
public function test_markdown_file_snippet_is_a_link_reference(): void
|
||||
{
|
||||
$media = new MediaLibrary([
|
||||
'alt_text' => '',
|
||||
'type' => MediaLibrary::TYPE_FILE,
|
||||
'mime_type' => 'application/pdf',
|
||||
'original_name' => 'notes.pdf',
|
||||
'path' => 'media/library/articles/notes.pdf',
|
||||
]);
|
||||
$media->id = 8;
|
||||
|
||||
$this->assertSame('[notes.pdf](media:8)', app(MarkdownMediaEmbed::class)->snippet($media, 'markdown'));
|
||||
}
|
||||
|
||||
public function test_html_snippet_uses_shortcode(): void
|
||||
{
|
||||
$media = new MediaLibrary([
|
||||
'type' => MediaLibrary::TYPE_IMAGE,
|
||||
'mime_type' => 'image/png',
|
||||
'original_name' => 'pic.png',
|
||||
'path' => 'pic.png',
|
||||
]);
|
||||
$media->id = 3;
|
||||
|
||||
$this->assertSame('[media=3]', app(MarkdownMediaEmbed::class)->snippet($media, 'html'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user