Search in sources :

Example 1 with DisplayMacroParameters

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

Example 2 with DisplayMacroParameters

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);
}
Also used : 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) Test(org.junit.Test)

Example 3 with DisplayMacroParameters

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);
}
Also used : Expectations(org.jmock.Expectations) DocumentModelBridge(org.xwiki.bridge.DocumentModelBridge) 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) Test(org.junit.Test)

Example 4 with DisplayMacroParameters

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;
        }
    }
}
Also used : Expectations(org.jmock.Expectations) DocumentDisplayerParameters(org.xwiki.display.internal.DocumentDisplayerParameters) DocumentDisplayer(org.xwiki.display.internal.DocumentDisplayer) DocumentModelBridge(org.xwiki.bridge.DocumentModelBridge) Invocation(org.jmock.api.Invocation) CustomAction(org.jmock.lib.action.CustomAction) MacroTransformationContext(org.xwiki.rendering.transformation.MacroTransformationContext) MacroExecutionException(org.xwiki.rendering.macro.MacroExecutionException) DisplayMacroParameters(org.xwiki.rendering.macro.display.DisplayMacroParameters) DocumentReference(org.xwiki.model.reference.DocumentReference) MacroExecutionException(org.xwiki.rendering.macro.MacroExecutionException) Test(org.junit.Test)

Example 5 with DisplayMacroParameters

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());
    }
}
Also used : MacroExecutionException(org.xwiki.rendering.macro.MacroExecutionException) DisplayMacroParameters(org.xwiki.rendering.macro.display.DisplayMacroParameters) 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