use of org.xwiki.wysiwyg.cleaner.HTMLCleaner in project xwiki-platform by xwiki.
the class DefaultHTMLConverterTest method parseAndRender.
/**
* Unit test for {@link DefaultHTMLConverter#parseAndRender(String, String)}.
*/
@Test
public void parseAndRender() 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);
// Verify the HTML is parsed into XDOM.
XDOM xdom = new XDOM(Collections.<Block>emptyList());
Parser xhtmlParser = mocker.getInstance(Parser.class, "xhtml/1.0");
when(xhtmlParser.parse(any(StringReader.class))).thenReturn(xdom);
Assert.assertEquals("", mocker.getComponentUnderTest().parseAndRender(html, syntaxId));
// Verify that the macro transformations have been executed.
Transformation macroTransformation = mocker.getInstance(Transformation.class, "macro");
RenderingContext renderingContext = mocker.getInstance(RenderingContext.class);
// It's very important to verify that a transformation context id is set as otherwise if the content being
// edited has different velocity macros executing, they'll be executed in isolation and thus what's defined in
// one won't be visible from the other ones (For example see https://jira.xwiki.org/browse/XWIKI-11695).
ArgumentCaptor<TransformationContext> txContextArgument = ArgumentCaptor.forClass(TransformationContext.class);
verify((MutableRenderingContext) renderingContext).transformInContext(same(macroTransformation), txContextArgument.capture(), same(xdom));
assertEquals("wysiwygtxid", txContextArgument.getValue().getId());
// Verify the XDOM is rendered to Annotated XHTML.
BlockRenderer xhtmlRenderer = mocker.getInstance(BlockRenderer.class, "annotatedxhtml/1.0");
verify(xhtmlRenderer).render(same(xdom), any(WikiPrinter.class));
// Verify that the syntax meta data has been set.
Assert.assertEquals(Syntax.valueOf("syntax/x.y"), xdom.getMetaData().getMetaData(MetaData.SYNTAX));
}
use of org.xwiki.wysiwyg.cleaner.HTMLCleaner 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));
}
Aggregations