Search in sources :

Example 6 with IncludeMacroParameters

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);
}
Also used : Expectations(org.jmock.Expectations) DocumentModelBridge(org.xwiki.bridge.DocumentModelBridge) IncludeMacroParameters(org.xwiki.rendering.macro.include.IncludeMacroParameters) MacroTransformationContext(org.xwiki.rendering.transformation.MacroTransformationContext) Block(org.xwiki.rendering.block.Block) MacroMarkerBlock(org.xwiki.rendering.block.MacroMarkerBlock) MetaDataBlock(org.xwiki.rendering.block.MetaDataBlock) MacroBlock(org.xwiki.rendering.block.MacroBlock) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 7 with IncludeMacroParameters

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());
    }
}
Also used : IncludeMacroParameters(org.xwiki.rendering.macro.include.IncludeMacroParameters) MacroExecutionException(org.xwiki.rendering.macro.MacroExecutionException) Test(org.junit.Test)

Example 8 with IncludeMacroParameters

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);
}
Also used : Expectations(org.jmock.Expectations) DocumentModelBridge(org.xwiki.bridge.DocumentModelBridge) IncludeMacroParameters(org.xwiki.rendering.macro.include.IncludeMacroParameters) Block(org.xwiki.rendering.block.Block) MacroMarkerBlock(org.xwiki.rendering.block.MacroMarkerBlock) 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) Test(org.junit.Test)

Aggregations

IncludeMacroParameters (org.xwiki.rendering.macro.include.IncludeMacroParameters)8 Expectations (org.jmock.Expectations)7 Test (org.junit.Test)7 DocumentReference (org.xwiki.model.reference.DocumentReference)7 MacroTransformationContext (org.xwiki.rendering.transformation.MacroTransformationContext)6 DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)5 MacroMarkerBlock (org.xwiki.rendering.block.MacroMarkerBlock)4 MacroExecutionException (org.xwiki.rendering.macro.MacroExecutionException)4 Block (org.xwiki.rendering.block.Block)3 MacroBlock (org.xwiki.rendering.block.MacroBlock)3 MetaDataBlock (org.xwiki.rendering.block.MetaDataBlock)3 HashMap (java.util.HashMap)2 Map (java.util.Map)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 MacroTransformation (org.xwiki.rendering.internal.transformation.macro.MacroTransformation)1 MetaData (org.xwiki.rendering.listener.MetaData)1