Search in sources :

Example 1 with MacroTransformation

use of org.xwiki.rendering.internal.transformation.macro.MacroTransformation in project xwiki-platform by xwiki.

the class CacheMacroTest method createMacroTransformationContext.

private MacroTransformationContext createMacroTransformationContext() throws Exception {
    MacroTransformation macroTransformation = getComponentManager().getInstance(Transformation.class, "macro");
    MacroTransformationContext context = new MacroTransformationContext();
    context.setTransformation(macroTransformation);
    context.setSyntax(Syntax.XWIKI_2_0);
    return context;
}
Also used : MacroTransformationContext(org.xwiki.rendering.transformation.MacroTransformationContext) MacroTransformation(org.xwiki.rendering.internal.transformation.macro.MacroTransformation)

Example 2 with MacroTransformation

use of org.xwiki.rendering.internal.transformation.macro.MacroTransformation in project xwiki-platform by xwiki.

the class IncludeMacroTest method runIncludeMacro.

private List<Block> runIncludeMacro(final Context context, String includedContent, boolean restricted) throws Exception {
    final DocumentReference includedDocumentReference = new DocumentReference("wiki", "Space", "IncludedPage");
    String includedDocStringRef = "wiki:space.page";
    setUpDocumentMock(includedDocStringRef, includedDocumentReference, includedContent);
    getMockery().checking(new Expectations() {

        {
            allowing(mockSetup.bridge).isDocumentViewable(with(same(includedDocumentReference)));
            will(returnValue(true));
            // Verify that push/pop are called when context is NEW
            if (context == Context.NEW) {
                oneOf(mockSetup.bridge).pushDocumentInContext(with(any(Map.class)), with(same(mockDocument)));
                oneOf(mockSetup.bridge).getCurrentDocumentReference();
                will(returnValue(includedDocumentReference));
                oneOf(mockSetup.bridge).popDocumentFromContext(with(any(Map.class)));
            } else {
                oneOf(mockSetup.bridge).getCurrentDocumentReference();
                will(returnValue(new DocumentReference("wiki", "Space", "IncludingPage")));
            }
        }
    });
    this.includeMacro.setDocumentAccessBridge(this.mockSetup.bridge);
    IncludeMacroParameters parameters = new IncludeMacroParameters();
    parameters.setReference(includedDocStringRef);
    parameters.setContext(context);
    // Create a Macro transformation context with the Macro transformation object defined so that the include
    // macro can transform included page which is using a new context.
    MacroTransformation macroTransformation = getComponentManager().getInstance(Transformation.class, "macro");
    MacroTransformationContext macroContext = createMacroTransformationContext(includedDocStringRef, false);
    macroContext.setId("wiki:Space.IncludingPage");
    macroContext.setTransformation(macroTransformation);
    macroContext.getTransformationContext().setRestricted(restricted);
    return this.includeMacro.execute(parameters, null, macroContext);
}
Also used : Expectations(org.jmock.Expectations) IncludeMacroParameters(org.xwiki.rendering.macro.include.IncludeMacroParameters) MacroTransformationContext(org.xwiki.rendering.transformation.MacroTransformationContext) HashMap(java.util.HashMap) Map(java.util.Map) DocumentReference(org.xwiki.model.reference.DocumentReference) MacroTransformation(org.xwiki.rendering.internal.transformation.macro.MacroTransformation)

Example 3 with MacroTransformation

use of org.xwiki.rendering.internal.transformation.macro.MacroTransformation in project xwiki-platform by xwiki.

the class DisplayMacroTest method runDisplayMacro.

private List<Block> runDisplayMacro(DisplayMacroParameters parameters, String displayedContent) throws Exception {
    final DocumentReference displayedDocumentReference = new DocumentReference("wiki", "Space", "DisplayedPage");
    String displayedDocStringRef = "wiki:space.page";
    setUpDocumentMock(displayedDocStringRef, displayedDocumentReference, displayedContent);
    getMockery().checking(new Expectations() {

        {
            allowing(mockSetup.bridge).isDocumentViewable(with(same(displayedDocumentReference)));
            will(returnValue(true));
            oneOf(mockSetup.bridge).pushDocumentInContext(with(any(Map.class)), with(same(mockDocument)));
            atMost(1).of(mockSetup.bridge).getCurrentDocumentReference();
            will(returnValue(displayedDocumentReference));
            oneOf(mockSetup.bridge).popDocumentFromContext(with(any(Map.class)));
        }
    });
    this.displayMacro.setDocumentAccessBridge(this.mockSetup.bridge);
    parameters.setReference(displayedDocStringRef);
    // Create a Macro transformation context with the Macro transformation object defined so that the display
    // macro can transform displayed page which is using a new context.
    MacroTransformation macroTransformation = (MacroTransformation) getComponentManager().getInstance(Transformation.class, "macro");
    MacroTransformationContext macroContext = createMacroTransformationContext(displayedDocStringRef, false);
    macroContext.setId("wiki:Space.DisplayingPage");
    macroContext.setTransformation(macroTransformation);
    return this.displayMacro.execute(parameters, null, macroContext);
}
Also used : Expectations(org.jmock.Expectations) MacroTransformation(org.xwiki.rendering.internal.transformation.macro.MacroTransformation) Transformation(org.xwiki.rendering.transformation.Transformation) MacroTransformationContext(org.xwiki.rendering.transformation.MacroTransformationContext) HashMap(java.util.HashMap) Map(java.util.Map) DocumentReference(org.xwiki.model.reference.DocumentReference) MacroTransformation(org.xwiki.rendering.internal.transformation.macro.MacroTransformation)

Aggregations

MacroTransformation (org.xwiki.rendering.internal.transformation.macro.MacroTransformation)3 MacroTransformationContext (org.xwiki.rendering.transformation.MacroTransformationContext)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Expectations (org.jmock.Expectations)2 DocumentReference (org.xwiki.model.reference.DocumentReference)2 IncludeMacroParameters (org.xwiki.rendering.macro.include.IncludeMacroParameters)1 Transformation (org.xwiki.rendering.transformation.Transformation)1