# test_html_generator.py
import pytest

# 使用实际实现的 HTMLGenerator
from app.services.content.html_generator import HTMLGenerator

def test_filter_banned_tags_zhihu():
    """知乎HTML标签过滤"""
    generator = HTMLGenerator()
    html = generator.generate(
        content="<script>alert(1)</script><p>这是内容</p>",
        platform="zhihu"
    )
    assert "<script>" not in html
    assert "<p>这是内容</p>" in html

def test_filter_banned_tags_wechat():
    """微信公众号HTML过滤"""
    generator = HTMLGenerator()
    html = generator.generate(
        content="<a href='http://baidu.com'>外部链接</a><p>内容</p>",
        platform="wechat"
    )
    # 微信公众号禁止外部链接
    assert "http://baidu.com" not in html

def test_convert_to_markdown():
    """Markdown转换"""
    generator = HTMLGenerator()
    md = generator.to_markdown("<h1>标题</h1><p>段落</p>")
    assert "# 标题" in md
    assert "段落" in md

def test_convert_to_plain():
    """纯文本转换"""
    generator = HTMLGenerator()
    plain = generator.to_plain("<h1>标题</h1><p>段落<b>加粗</b></p>")
    assert "标题" in plain
    assert "段落" in plain
    assert "<" not in plain  # 不应包含HTML标签

def test_multi_format_output():
    """多格式同时输出"""
    generator = HTMLGenerator()
    html = generator.generate("<p>内容</p>", "zhihu", "html")
    md = generator.to_markdown("<p>内容</p>")
    plain = generator.to_plain("<p>内容</p>")
    
    assert html is not None
    assert md is not None
    assert plain is not None
    assert len(html) > 0
    assert len(md) > 0
    assert len(plain) > 0
