Search in sources :

Example 1 with MacroContentParser

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

the class ContextMacroTest method executeWithRelativeDocumentReferenceParameter.

@Test
public void executeWithRelativeDocumentReferenceParameter() throws Exception {
    MacroBlock macroBlock = new MacroBlock("context", Collections.<String, String>emptyMap(), false);
    MacroTransformationContext macroContext = new MacroTransformationContext();
    macroContext.setSyntax(Syntax.XWIKI_2_0);
    macroContext.setCurrentMacroBlock(macroBlock);
    DocumentReferenceResolver<String> resolver = this.mocker.getInstance(DocumentReferenceResolver.TYPE_STRING, "macro");
    DocumentReference referencedDocumentReference = new DocumentReference("basewiki", "basespace", "page");
    when(resolver.resolve("page", macroBlock)).thenReturn(referencedDocumentReference);
    DocumentAccessBridge dab = this.mocker.getInstance(DocumentAccessBridge.class);
    DocumentModelBridge dmb = mock(DocumentModelBridge.class);
    when(dab.getTranslatedDocumentInstance(referencedDocumentReference)).thenReturn(dmb);
    MacroContentParser parser = this.mocker.getInstance(MacroContentParser.class);
    when(parser.parse(eq(""), same(macroContext), eq(false), any(MetaData.class), eq(false))).thenReturn(new XDOM(Collections.emptyList()));
    ContextMacroParameters parameters = new ContextMacroParameters();
    parameters.setDocument("page");
    this.mocker.getComponentUnderTest().execute(parameters, "", macroContext);
}
Also used : XDOM(org.xwiki.rendering.block.XDOM) DocumentModelBridge(org.xwiki.bridge.DocumentModelBridge) MacroContentParser(org.xwiki.rendering.macro.MacroContentParser) MetaData(org.xwiki.rendering.listener.MetaData) MacroTransformationContext(org.xwiki.rendering.transformation.MacroTransformationContext) DocumentAccessBridge(org.xwiki.bridge.DocumentAccessBridge) ContextMacroParameters(org.xwiki.rendering.macro.context.ContextMacroParameters) DocumentReference(org.xwiki.model.reference.DocumentReference) MacroBlock(org.xwiki.rendering.block.MacroBlock) Test(org.junit.Test)

Example 2 with MacroContentParser

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

the class AbstractMacroContentTableBlockDataSourceTest method setUpContentExpectation.

protected void setUpContentExpectation(final String macroContent) throws Exception {
    final MacroContentParser parser = getComponentManager().getInstance(MacroContentParser.class);
    // In order to make it easy to write unit tests, we allow tests to pass a string written in XWiki/2.0 synyax
    // which we then parser to generate an XDOM that we use in the expectation.
    final XDOM expectedXDOM = getComponentManager().<Parser>getInstance(Parser.class, Syntax.XWIKI_2_0.toIdString()).parse(new StringReader(macroContent));
    getMockery().checking(new Expectations() {

        {
            // Simulate parsing the macro content that returns a XDOM not containing a table
            oneOf(parser).parse(macroContent, null, true, false);
            will(returnValue(expectedXDOM));
        }
    });
}
Also used : Expectations(org.jmock.Expectations) XDOM(org.xwiki.rendering.block.XDOM) MacroContentParser(org.xwiki.rendering.macro.MacroContentParser) StringReader(java.io.StringReader) URLResourceReferenceTypeParser(org.xwiki.rendering.internal.parser.reference.type.URLResourceReferenceTypeParser) DocumentResourceReferenceTypeParser(org.xwiki.rendering.internal.parser.reference.type.DocumentResourceReferenceTypeParser) XWiki20Parser(org.xwiki.rendering.internal.parser.xwiki20.XWiki20Parser) Parser(org.xwiki.rendering.parser.Parser) XWiki20ImageReferenceParser(org.xwiki.rendering.internal.parser.xwiki20.XWiki20ImageReferenceParser) XWiki20LinkReferenceParser(org.xwiki.rendering.internal.parser.xwiki20.XWiki20LinkReferenceParser) SpaceResourceReferenceTypeParser(org.xwiki.rendering.internal.parser.reference.type.SpaceResourceReferenceTypeParser) DefaultUntypedLinkReferenceParser(org.xwiki.rendering.internal.parser.reference.DefaultUntypedLinkReferenceParser) MacroContentParser(org.xwiki.rendering.macro.MacroContentParser) AttachmentResourceReferenceTypeParser(org.xwiki.rendering.internal.parser.reference.type.AttachmentResourceReferenceTypeParser)

Example 3 with MacroContentParser

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

the class ContextMacroTest method executeOk.

@Test
public void executeOk() throws Exception {
    MacroBlock macroBlock = new MacroBlock("context", Collections.<String, String>emptyMap(), false);
    MacroTransformationContext macroContext = new MacroTransformationContext();
    macroContext.setSyntax(Syntax.XWIKI_2_0);
    macroContext.setCurrentMacroBlock(macroBlock);
    DocumentReferenceResolver<String> resolver = this.mocker.getInstance(DocumentReferenceResolver.TYPE_STRING, "macro");
    DocumentReference referencedDocumentReference = new DocumentReference("wiki", "space", "page");
    when(resolver.resolve("wiki:space.page", macroBlock)).thenReturn(referencedDocumentReference);
    DocumentAccessBridge dab = this.mocker.getInstance(DocumentAccessBridge.class);
    DocumentModelBridge dmb = mock(DocumentModelBridge.class);
    when(dab.getTranslatedDocumentInstance(referencedDocumentReference)).thenReturn(dmb);
    MacroContentParser parser = this.mocker.getInstance(MacroContentParser.class);
    XDOM xdom = new XDOM(Arrays.asList((Block) new ParagraphBlock(Arrays.asList((Block) new LinkBlock(Collections.emptyList(), new ResourceReference("", ResourceType.DOCUMENT), false)))));
    when(parser.parse(eq(""), same(macroContext), eq(false), any(MetaData.class), eq(false))).thenReturn(xdom);
    ContextMacroParameters parameters = new ContextMacroParameters();
    parameters.setDocument("wiki:space.page");
    // Note: we're not testing the returned value here since this is done in integation tests.
    this.mocker.getComponentUnderTest().execute(parameters, "", macroContext);
}
Also used : XDOM(org.xwiki.rendering.block.XDOM) MacroContentParser(org.xwiki.rendering.macro.MacroContentParser) DocumentAccessBridge(org.xwiki.bridge.DocumentAccessBridge) ParagraphBlock(org.xwiki.rendering.block.ParagraphBlock) DocumentModelBridge(org.xwiki.bridge.DocumentModelBridge) LinkBlock(org.xwiki.rendering.block.LinkBlock) MetaData(org.xwiki.rendering.listener.MetaData) MacroTransformationContext(org.xwiki.rendering.transformation.MacroTransformationContext) LinkBlock(org.xwiki.rendering.block.LinkBlock) Block(org.xwiki.rendering.block.Block) MacroBlock(org.xwiki.rendering.block.MacroBlock) ParagraphBlock(org.xwiki.rendering.block.ParagraphBlock) ResourceReference(org.xwiki.rendering.listener.reference.ResourceReference) ContextMacroParameters(org.xwiki.rendering.macro.context.ContextMacroParameters) DocumentReference(org.xwiki.model.reference.DocumentReference) MacroBlock(org.xwiki.rendering.block.MacroBlock) Test(org.junit.Test)

Example 4 with MacroContentParser

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

the class ContextMacroTest method executeWithReferencedDocumentHavingProgrammingRightsAndCallingDocumentToo.

@Test
public void executeWithReferencedDocumentHavingProgrammingRightsAndCallingDocumentToo() throws Exception {
    MacroBlock macroBlock = new MacroBlock("context", Collections.<String, String>emptyMap(), false);
    MacroTransformationContext macroContext = new MacroTransformationContext();
    macroContext.setSyntax(Syntax.XWIKI_2_0);
    macroContext.setCurrentMacroBlock(macroBlock);
    DocumentReferenceResolver<String> resolver = this.mocker.getInstance(DocumentReferenceResolver.TYPE_STRING, "macro");
    DocumentReference referencedDocumentReference = new DocumentReference("wiki", "space", "page");
    when(resolver.resolve("wiki:space.page", macroBlock)).thenReturn(referencedDocumentReference);
    DocumentAccessBridge dab = this.mocker.getInstance(DocumentAccessBridge.class);
    when(dab.hasProgrammingRights()).thenReturn(true).thenReturn(true);
    DocumentModelBridge dmb = mock(DocumentModelBridge.class);
    when(dab.getTranslatedDocumentInstance(referencedDocumentReference)).thenReturn(dmb);
    MacroContentParser parser = this.mocker.getInstance(MacroContentParser.class);
    when(parser.parse(eq(""), same(macroContext), eq(false), any(MetaData.class), eq(false))).thenReturn(new XDOM(Collections.emptyList()));
    ContextMacroParameters parameters = new ContextMacroParameters();
    parameters.setDocument("wiki:space.page");
    this.mocker.getComponentUnderTest().execute(parameters, "", macroContext);
}
Also used : XDOM(org.xwiki.rendering.block.XDOM) DocumentModelBridge(org.xwiki.bridge.DocumentModelBridge) MacroContentParser(org.xwiki.rendering.macro.MacroContentParser) MetaData(org.xwiki.rendering.listener.MetaData) MacroTransformationContext(org.xwiki.rendering.transformation.MacroTransformationContext) DocumentAccessBridge(org.xwiki.bridge.DocumentAccessBridge) ContextMacroParameters(org.xwiki.rendering.macro.context.ContextMacroParameters) DocumentReference(org.xwiki.model.reference.DocumentReference) MacroBlock(org.xwiki.rendering.block.MacroBlock) Test(org.junit.Test)

Aggregations

XDOM (org.xwiki.rendering.block.XDOM)4 MacroContentParser (org.xwiki.rendering.macro.MacroContentParser)4 Test (org.junit.Test)3 DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)3 DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)3 DocumentReference (org.xwiki.model.reference.DocumentReference)3 MacroBlock (org.xwiki.rendering.block.MacroBlock)3 MetaData (org.xwiki.rendering.listener.MetaData)3 ContextMacroParameters (org.xwiki.rendering.macro.context.ContextMacroParameters)3 MacroTransformationContext (org.xwiki.rendering.transformation.MacroTransformationContext)3 StringReader (java.io.StringReader)1 Expectations (org.jmock.Expectations)1 Block (org.xwiki.rendering.block.Block)1 LinkBlock (org.xwiki.rendering.block.LinkBlock)1 ParagraphBlock (org.xwiki.rendering.block.ParagraphBlock)1 DefaultUntypedLinkReferenceParser (org.xwiki.rendering.internal.parser.reference.DefaultUntypedLinkReferenceParser)1 AttachmentResourceReferenceTypeParser (org.xwiki.rendering.internal.parser.reference.type.AttachmentResourceReferenceTypeParser)1 DocumentResourceReferenceTypeParser (org.xwiki.rendering.internal.parser.reference.type.DocumentResourceReferenceTypeParser)1 SpaceResourceReferenceTypeParser (org.xwiki.rendering.internal.parser.reference.type.SpaceResourceReferenceTypeParser)1 URLResourceReferenceTypeParser (org.xwiki.rendering.internal.parser.reference.type.URLResourceReferenceTypeParser)1