<?php

namespace Tests\Unit;

use App\Domain\Blog\ContentFormat;
use App\Domain\Blog\ContentRenderer;
use Tests\TestCase;

class ContentRendererTest extends TestCase
{
    public function test_markdown_renders_to_html(): void
    {
        $html = app(ContentRenderer::class)->toHtml("# Hello\n\n**world**", ContentFormat::MARKDOWN);

        $this->assertMatchesRegularExpression('/<h1[^>]*>Hello<\/h1>/', $html);
        $this->assertStringContainsString('<strong>world</strong>', $html);
    }

    public function test_html_format_passes_through_purifier(): void
    {
        $html = app(ContentRenderer::class)->toHtml(
            '<p>ok</p><script>alert(1)</script>',
            ContentFormat::HTML,
        );

        $this->assertStringContainsString('<p>ok</p>', $html);
        $this->assertStringNotContainsString('<script>', $html);
    }

    public function test_html_to_markdown_roundtrip_basic(): void
    {
        $md = app(ContentRenderer::class)->htmlToMarkdown('<h2>Title</h2><p>Hello <strong>x</strong></p>');

        $this->assertStringContainsString('Title', $md);
        $this->assertStringContainsString('Hello', $md);
    }
}
