use of org.xwiki.rendering.macro.display.DisplayMacroParameters in project xwiki-platform by xwiki.
the class DisplayMacroTest method testDisplayMacroWithNoDocumentSpecified.
@Test
public void testDisplayMacroWithNoDocumentSpecified() throws Exception {
DisplayMacroParameters parameters = new DisplayMacroParameters();
try {
this.displayMacro.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 display.", expected.getMessage());
}
}
use of org.xwiki.rendering.macro.display.DisplayMacroParameters in project xwiki-platform by xwiki.
the class DisplayMacroTest method testDisplayMacroWhenSectionSpecified.
@Test
public void testDisplayMacroWhenSectionSpecified() throws Exception {
String expected = "beginDocument\n" + "beginMetaData [[base]=[wiki:Space.DisplayedPage][source]=[wiki:Space.DisplayedPage]" + "[syntax]=[XWiki 2.0]]\n" + "beginHeader [1, Hsection]\n" + "onWord [section]\n" + "endHeader [1, Hsection]\n" + "beginParagraph\n" + "onWord [content2]\n" + "endParagraph\n" + "endMetaData [[base]=[wiki:Space.DisplayedPage][source]=[wiki:Space.DisplayedPage]" + "[syntax]=[XWiki 2.0]]\n" + "endDocument";
DisplayMacroParameters parameters = new DisplayMacroParameters();
parameters.setSection("Hsection");
List<Block> blocks = runDisplayMacro(parameters, "content1\n\n= section =\ncontent2");
assertBlocks(expected, blocks, this.rendererFactory);
}
use of org.xwiki.rendering.macro.display.DisplayMacroParameters in project xwiki-platform by xwiki.
the class DisplayMacroTest method testDisplayMacroWhenDisplayingDocumentWithRelativeReferences.
/**
* Verify that relative links returned by the display macro as wrapped with a MetaDataBlock.
*/
@Test
public void testDisplayMacroWhenDisplayingDocumentWithRelativeReferences() throws Exception {
String expected = "beginDocument\n" + "beginMetaData [[base]=[displayedWiki:displayedSpace.displayedPage]" + "[source]=[displayedWiki:displayedSpace.displayedPage][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]=[displayedWiki:displayedSpace.displayedPage]" + "[source]=[displayedWiki:displayedSpace.displayedPage][syntax]=[XWiki 2.0]]\n" + "endDocument";
final DocumentReference displayedDocumentReference = new DocumentReference("displayedWiki", "displayedSpace", "displayedPage");
setUpDocumentMock("displayedWiki:displayedSpace.displayedPage", displayedDocumentReference, "[[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(displayedDocumentReference));
oneOf(mockSetup.bridge).popDocumentFromContext(with(any(Map.class)));
}
});
DisplayMacroParameters parameters = new DisplayMacroParameters();
parameters.setReference("displayedWiki:displayedSpace.displayedPage");
List<Block> blocks = this.displayMacro.execute(parameters, null, createMacroTransformationContext("whatever", false));
assertBlocks(expected, blocks, this.rendererFactory);
}
use of org.xwiki.rendering.macro.display.DisplayMacroParameters in project xwiki-platform by xwiki.
the class DisplayMacroTest method testDisplayMacroWithRecursiveDisplay.
@Test
public void testDisplayMacroWithRecursiveDisplay() throws Exception {
final DocumentDisplayer mockDocumentDisplayer = getMockery().mock(DocumentDisplayer.class);
this.displayMacro.setDocumentAccessBridge(mockSetup.bridge);
FieldUtils.writeField(this.displayMacro, "documentDisplayer", mockDocumentDisplayer, true);
final MacroTransformationContext macroContext = createMacroTransformationContext("wiki:space.page", false);
final DisplayMacroParameters parameters = new DisplayMacroParameters();
parameters.setReference("wiki:space.page");
getMockery().checking(new Expectations() {
{
allowing(mockDocumentReferenceResolver).resolve("wiki:space.page", macroContext.getCurrentMacroBlock());
will(returnValue(new DocumentReference("wiki", "space", "page")));
allowing(mockSetup.bridge).isDocumentViewable(with(any(DocumentReference.class)));
will(returnValue(true));
allowing(mockSetup.bridge).getDocumentInstance(with(any(DocumentReference.class)));
will(returnValue(null));
allowing(mockDocumentDisplayer).display(with(same((DocumentModelBridge) null)), with(any(DocumentDisplayerParameters.class)));
will(new CustomAction("recursively call the include macro again") {
@Override
public Object invoke(Invocation invocation) throws Throwable {
try {
displayMacro.execute(parameters, null, macroContext);
} catch (Exception expected) {
if (expected.getMessage().contains("Found recursive display")) {
throw new ExpectedRecursiveInclusionException();
}
}
return true;
}
});
}
});
try {
this.displayMacro.execute(parameters, null, macroContext);
Assert.fail("The display macro hasn't checked the recursive display");
} catch (MacroExecutionException expected) {
if (!(expected.getCause() instanceof ExpectedRecursiveInclusionException)) {
throw expected;
}
}
}
use of org.xwiki.rendering.macro.display.DisplayMacroParameters in project xwiki-platform by xwiki.
the class DisplayMacroTest method testDisplayMacroWhenInvalidSectionSpecified.
@Test
public void testDisplayMacroWhenInvalidSectionSpecified() throws Exception {
DisplayMacroParameters parameters = new DisplayMacroParameters();
parameters.setSection("unknown");
try {
runDisplayMacro(parameters, "content");
Assert.fail("Should have raised an exception");
} catch (MacroExecutionException expected) {
Assert.assertEquals("Cannot find section [unknown] in document [wiki:Space.DisplayedPage]", expected.getMessage());
}
}
Aggregations