Search in sources :

Example 1 with StreamParser

use of org.xwiki.rendering.parser.StreamParser in project xwiki-platform by xwiki.

the class DefaultHTMLConverterTest method fromHTML.

/**
 * Unit test for {@link DefaultHTMLConverter#fromHTML(String, String)}.
 */
@Test
public void fromHTML() throws Exception {
    String html = "some HTML";
    String syntaxId = "syntax/x.y";
    // Verify the HTML is cleaned.
    HTMLCleaner cleaner = mocker.getInstance(HTMLCleaner.class);
    when(cleaner.clean(html)).thenReturn(html);
    PrintRendererFactory printRendererFactory = this.mocker.registerMockComponent(PrintRendererFactory.class, syntaxId);
    PrintRenderer printRenderer = mock(PrintRenderer.class);
    when(printRendererFactory.createRenderer(any(WikiPrinter.class))).thenReturn(printRenderer);
    Assert.assertEquals("", mocker.getComponentUnderTest().fromHTML(html, syntaxId));
    // Verify the HTML is converted to the specified syntax.
    StreamParser xhtmlStreamParser = mocker.getInstance(StreamParser.class, "xhtml/1.0");
    verify(xhtmlStreamParser).parse(any(StringReader.class), same(printRenderer));
}
Also used : PrintRenderer(org.xwiki.rendering.renderer.PrintRenderer) StreamParser(org.xwiki.rendering.parser.StreamParser) StringReader(java.io.StringReader) PrintRendererFactory(org.xwiki.rendering.renderer.PrintRendererFactory) WikiPrinter(org.xwiki.rendering.renderer.printer.WikiPrinter) HTMLCleaner(org.xwiki.wysiwyg.cleaner.HTMLCleaner) Test(org.junit.Test)

Aggregations

StringReader (java.io.StringReader)1 Test (org.junit.Test)1 StreamParser (org.xwiki.rendering.parser.StreamParser)1 PrintRenderer (org.xwiki.rendering.renderer.PrintRenderer)1 PrintRendererFactory (org.xwiki.rendering.renderer.PrintRendererFactory)1 WikiPrinter (org.xwiki.rendering.renderer.printer.WikiPrinter)1 HTMLCleaner (org.xwiki.wysiwyg.cleaner.HTMLCleaner)1