Search in sources :

Example 6 with DisplayMacroParameters

use of org.xwiki.rendering.macro.display.DisplayMacroParameters in project xwiki-platform by xwiki.

the class DisplayMacroTest method testDisplayMacroInsideBaseMetaDataBlockAndWithRelativeDocumentReferencePassed.

@Test
public void testDisplayMacroInsideBaseMetaDataBlockAndWithRelativeDocumentReferencePassed() throws Exception {
    String expected = "beginDocument\n" + "beginMetaData [[base]=[wiki:space.relativePage][source]=[wiki:space.relativePage][syntax]=[XWiki 2.0]]\n" + "beginParagraph\n" + "onWord [content]\n" + "endParagraph\n" + "endMetaData [[base]=[wiki:space.relativePage][source]=[wiki:space.relativePage][syntax]=[XWiki 2.0]]\n" + "endDocument";
    DisplayMacroParameters parameters = new DisplayMacroParameters();
    parameters.setReference("relativePage");
    MacroTransformationContext macroContext = createMacroTransformationContext("whatever", false);
    // Add a Source MetaData Block as a parent of the display Macro block.
    new MetaDataBlock(Collections.<Block>singletonList(macroContext.getCurrentMacroBlock()), new MetaData(Collections.<String, Object>singletonMap(MetaData.BASE, "wiki:space.page")));
    final DocumentReference sourceReference = new DocumentReference("wiki", "space", "page");
    final DocumentReference resolvedReference = new DocumentReference("wiki", "space", "relativePage");
    setUpDocumentMock("relativePage", resolvedReference, "content");
    getMockery().checking(new Expectations() {

        {
            allowing(mockDocumentReferenceResolver).resolve(with("wiki:space.page"), with(IsArray.array(any(MacroBlock.class))));
            will(returnValue(sourceReference));
            allowing(mockDocumentReferenceResolver).resolve(with("relativePage"), with(IsArray.array(any(MacroBlock.class))));
            will(returnValue(resolvedReference));
            oneOf(mockSetup.bridge).isDocumentViewable(resolvedReference);
            will(returnValue(true));
            oneOf(mockSetup.bridge).pushDocumentInContext(with(any(Map.class)), with(same(mockDocument)));
            oneOf(mockSetup.bridge).getCurrentDocumentReference();
            will(returnValue(resolvedReference));
            oneOf(mockSetup.bridge).popDocumentFromContext(with(any(Map.class)));
        }
    });
    List<Block> blocks = this.displayMacro.execute(parameters, null, macroContext);
    assertBlocks(expected, blocks, this.rendererFactory);
}
Also used : Expectations(org.jmock.Expectations) MetaData(org.xwiki.rendering.listener.MetaData) MacroTransformationContext(org.xwiki.rendering.transformation.MacroTransformationContext) DisplayMacroParameters(org.xwiki.rendering.macro.display.DisplayMacroParameters) Block(org.xwiki.rendering.block.Block) MetaDataBlock(org.xwiki.rendering.block.MetaDataBlock) MacroBlock(org.xwiki.rendering.block.MacroBlock) HashMap(java.util.HashMap) Map(java.util.Map) DocumentReference(org.xwiki.model.reference.DocumentReference) MetaDataBlock(org.xwiki.rendering.block.MetaDataBlock) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 DisplayMacroParameters (org.xwiki.rendering.macro.display.DisplayMacroParameters)6 Expectations (org.jmock.Expectations)3 DocumentReference (org.xwiki.model.reference.DocumentReference)3 Block (org.xwiki.rendering.block.Block)3 MacroBlock (org.xwiki.rendering.block.MacroBlock)3 MetaDataBlock (org.xwiki.rendering.block.MetaDataBlock)3 MacroExecutionException (org.xwiki.rendering.macro.MacroExecutionException)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)2 MacroTransformationContext (org.xwiki.rendering.transformation.MacroTransformationContext)2 Invocation (org.jmock.api.Invocation)1 CustomAction (org.jmock.lib.action.CustomAction)1 DocumentDisplayer (org.xwiki.display.internal.DocumentDisplayer)1 DocumentDisplayerParameters (org.xwiki.display.internal.DocumentDisplayerParameters)1 MetaData (org.xwiki.rendering.listener.MetaData)1