use of org.xwiki.rendering.macro.MacroContentParser in project xwiki-platform by xwiki.
the class ContextMacroTest method executeWithRelativeDocumentReferenceParameter.
@Test
public void executeWithRelativeDocumentReferenceParameter() throws Exception {
MacroBlock macroBlock = new MacroBlock("context", Collections.<String, String>emptyMap(), false);
MacroTransformationContext macroContext = new MacroTransformationContext();
macroContext.setSyntax(Syntax.XWIKI_2_0);
macroContext.setCurrentMacroBlock(macroBlock);
DocumentReferenceResolver<String> resolver = this.mocker.getInstance(DocumentReferenceResolver.TYPE_STRING, "macro");
DocumentReference referencedDocumentReference = new DocumentReference("basewiki", "basespace", "page");
when(resolver.resolve("page", macroBlock)).thenReturn(referencedDocumentReference);
DocumentAccessBridge dab = this.mocker.getInstance(DocumentAccessBridge.class);
DocumentModelBridge dmb = mock(DocumentModelBridge.class);
when(dab.getTranslatedDocumentInstance(referencedDocumentReference)).thenReturn(dmb);
MacroContentParser parser = this.mocker.getInstance(MacroContentParser.class);
when(parser.parse(eq(""), same(macroContext), eq(false), any(MetaData.class), eq(false))).thenReturn(new XDOM(Collections.emptyList()));
ContextMacroParameters parameters = new ContextMacroParameters();
parameters.setDocument("page");
this.mocker.getComponentUnderTest().execute(parameters, "", macroContext);
}
use of org.xwiki.rendering.macro.MacroContentParser in project xwiki-platform by xwiki.
the class AbstractMacroContentTableBlockDataSourceTest method setUpContentExpectation.
protected void setUpContentExpectation(final String macroContent) throws Exception {
final MacroContentParser parser = getComponentManager().getInstance(MacroContentParser.class);
// In order to make it easy to write unit tests, we allow tests to pass a string written in XWiki/2.0 synyax
// which we then parser to generate an XDOM that we use in the expectation.
final XDOM expectedXDOM = getComponentManager().<Parser>getInstance(Parser.class, Syntax.XWIKI_2_0.toIdString()).parse(new StringReader(macroContent));
getMockery().checking(new Expectations() {
{
// Simulate parsing the macro content that returns a XDOM not containing a table
oneOf(parser).parse(macroContent, null, true, false);
will(returnValue(expectedXDOM));
}
});
}
use of org.xwiki.rendering.macro.MacroContentParser in project xwiki-platform by xwiki.
the class ContextMacroTest method executeOk.
@Test
public void executeOk() throws Exception {
MacroBlock macroBlock = new MacroBlock("context", Collections.<String, String>emptyMap(), false);
MacroTransformationContext macroContext = new MacroTransformationContext();
macroContext.setSyntax(Syntax.XWIKI_2_0);
macroContext.setCurrentMacroBlock(macroBlock);
DocumentReferenceResolver<String> resolver = this.mocker.getInstance(DocumentReferenceResolver.TYPE_STRING, "macro");
DocumentReference referencedDocumentReference = new DocumentReference("wiki", "space", "page");
when(resolver.resolve("wiki:space.page", macroBlock)).thenReturn(referencedDocumentReference);
DocumentAccessBridge dab = this.mocker.getInstance(DocumentAccessBridge.class);
DocumentModelBridge dmb = mock(DocumentModelBridge.class);
when(dab.getTranslatedDocumentInstance(referencedDocumentReference)).thenReturn(dmb);
MacroContentParser parser = this.mocker.getInstance(MacroContentParser.class);
XDOM xdom = new XDOM(Arrays.asList((Block) new ParagraphBlock(Arrays.asList((Block) new LinkBlock(Collections.emptyList(), new ResourceReference("", ResourceType.DOCUMENT), false)))));
when(parser.parse(eq(""), same(macroContext), eq(false), any(MetaData.class), eq(false))).thenReturn(xdom);
ContextMacroParameters parameters = new ContextMacroParameters();
parameters.setDocument("wiki:space.page");
// Note: we're not testing the returned value here since this is done in integation tests.
this.mocker.getComponentUnderTest().execute(parameters, "", macroContext);
}
use of org.xwiki.rendering.macro.MacroContentParser in project xwiki-platform by xwiki.
the class ContextMacroTest method executeWithReferencedDocumentHavingProgrammingRightsAndCallingDocumentToo.
@Test
public void executeWithReferencedDocumentHavingProgrammingRightsAndCallingDocumentToo() throws Exception {
MacroBlock macroBlock = new MacroBlock("context", Collections.<String, String>emptyMap(), false);
MacroTransformationContext macroContext = new MacroTransformationContext();
macroContext.setSyntax(Syntax.XWIKI_2_0);
macroContext.setCurrentMacroBlock(macroBlock);
DocumentReferenceResolver<String> resolver = this.mocker.getInstance(DocumentReferenceResolver.TYPE_STRING, "macro");
DocumentReference referencedDocumentReference = new DocumentReference("wiki", "space", "page");
when(resolver.resolve("wiki:space.page", macroBlock)).thenReturn(referencedDocumentReference);
DocumentAccessBridge dab = this.mocker.getInstance(DocumentAccessBridge.class);
when(dab.hasProgrammingRights()).thenReturn(true).thenReturn(true);
DocumentModelBridge dmb = mock(DocumentModelBridge.class);
when(dab.getTranslatedDocumentInstance(referencedDocumentReference)).thenReturn(dmb);
MacroContentParser parser = this.mocker.getInstance(MacroContentParser.class);
when(parser.parse(eq(""), same(macroContext), eq(false), any(MetaData.class), eq(false))).thenReturn(new XDOM(Collections.emptyList()));
ContextMacroParameters parameters = new ContextMacroParameters();
parameters.setDocument("wiki:space.page");
this.mocker.getComponentUnderTest().execute(parameters, "", macroContext);
}
Aggregations