use of org.xwiki.rendering.macro.include.IncludeMacroParameters in project xwiki-platform by xwiki.
the class IncludeMacroTest method testIncludeMacroWhenSectionSpecified.
@Test
public void testIncludeMacroWhenSectionSpecified() throws Exception {
String expected = "beginDocument\n" + "beginMetaData [[source]=[wiki:space.document][syntax]=[XWiki 2.0]]\n" + "beginHeader [1, Hsection]\n" + "onWord [section]\n" + "endHeader [1, Hsection]\n" + "beginParagraph\n" + "onWord [content2]\n" + "endParagraph\n" + "endMetaData [[source]=[wiki:space.document][syntax]=[XWiki 2.0]]\n" + "endDocument";
IncludeMacroParameters parameters = new IncludeMacroParameters();
parameters.setReference("document");
parameters.setSection("Hsection");
final MacroTransformationContext macroContext = createMacroTransformationContext("whatever", false);
final DocumentReference resolvedReference = new DocumentReference("wiki", "space", "document");
final DocumentModelBridge mockDocument = getMockery().mock(DocumentModelBridge.class);
getMockery().checking(new Expectations() {
{
oneOf(mockDocumentReferenceResolver).resolve("document", macroContext.getCurrentMacroBlock());
will(returnValue(resolvedReference));
oneOf(mockSetup.bridge).isDocumentViewable(resolvedReference);
will(returnValue(true));
oneOf(mockSetup.bridge).getDocumentInstance(resolvedReference);
will(returnValue(mockDocument));
oneOf(mockSetup.bridge).getTranslatedDocumentInstance(resolvedReference);
will(returnValue(mockDocument));
oneOf(mockSetup.bridge).getCurrentDocumentReference();
will(returnValue(new DocumentReference("wiki", "Space", "IncludingPage")));
oneOf(mockDocument).getDocumentReference();
will(returnValue(resolvedReference));
oneOf(mockDocument).getSyntax();
will(returnValue(Syntax.XWIKI_2_0));
oneOf(mockDocument).getXDOM();
will(returnValue(getXDOM("content1\n\n= section =\ncontent2")));
allowing(mockDocument).getRealLanguage();
will(returnValue(""));
}
});
List<Block> blocks = this.includeMacro.execute(parameters, null, macroContext);
assertBlocks(expected, blocks, this.rendererFactory);
}
use of org.xwiki.rendering.macro.include.IncludeMacroParameters in project xwiki-platform by xwiki.
the class IncludeMacroTest method testIncludeMacroWithNoDocumentSpecified.
@Test
public void testIncludeMacroWithNoDocumentSpecified() throws Exception {
IncludeMacroParameters parameters = new IncludeMacroParameters();
try {
this.includeMacro.execute(parameters, null, createMacroTransformationContext("whatever", false));
Assert.fail("An exception should have been thrown");
} catch (MacroExecutionException expected) {
Assert.assertEquals("You must specify a 'reference' parameter pointing to the entity to include.", expected.getMessage());
}
}
use of org.xwiki.rendering.macro.include.IncludeMacroParameters in project xwiki-platform by xwiki.
the class IncludeMacroTest method testIncludeMacroWhenIncludingDocumentWithRelativeReferences.
/**
* Verify that relative links returned by the Include macro as wrapped with a MetaDataBlock.
*/
@Test
public void testIncludeMacroWhenIncludingDocumentWithRelativeReferences() throws Exception {
String expected = "beginDocument\n" + "beginMetaData [[base]=[includedWiki:includedSpace.includedPage]" + "[source]=[includedWiki:includedSpace.includedPage][syntax]=[XWiki 2.0]]\n" + "beginParagraph\n" + "beginLink [Typed = [false] Type = [doc] Reference = [page]] [false]\n" + "endLink [Typed = [false] Type = [doc] Reference = [page]] [false]\n" + "onSpace\n" + "beginLink [Typed = [true] Type = [attach] Reference = [test.png]] [false]\n" + "endLink [Typed = [true] Type = [attach] Reference = [test.png]] [false]\n" + "onSpace\n" + "onImage [Typed = [false] Type = [attach] Reference = [test.png]] [true]\n" + "endParagraph\n" + "endMetaData [[base]=[includedWiki:includedSpace.includedPage]" + "[source]=[includedWiki:includedSpace.includedPage][syntax]=[XWiki 2.0]]\n" + "endDocument";
final DocumentReference includedDocumentReference = new DocumentReference("includedWiki", "includedSpace", "includedPage");
setUpDocumentMock("includedWiki:includedSpace.includedPage", includedDocumentReference, "[[page]] [[attach:test.png]] image:test.png");
getMockery().checking(new Expectations() {
{
oneOf(mockSetup.bridge).isDocumentViewable(with(any(DocumentReference.class)));
will(returnValue(true));
oneOf(mockSetup.bridge).pushDocumentInContext(with(any(Map.class)), with(any(DocumentModelBridge.class)));
oneOf(mockSetup.bridge).getCurrentDocumentReference();
will(returnValue(includedDocumentReference));
oneOf(mockSetup.bridge).popDocumentFromContext(with(any(Map.class)));
}
});
IncludeMacroParameters parameters = new IncludeMacroParameters();
parameters.setReference("includedWiki:includedSpace.includedPage");
parameters.setContext(Context.NEW);
List<Block> blocks = this.includeMacro.execute(parameters, null, createMacroTransformationContext("whatever", false));
assertBlocks(expected, blocks, this.rendererFactory);
}
Aggregations