use of org.xwiki.rendering.macro.script.ScriptMockSetup in project xwiki-platform by xwiki.
the class ClassLoadingTest method registerComponents.
@Override
protected void registerComponents() throws Exception {
super.registerComponents();
this.mockSetup = new ScriptMockSetup(getComponentManager());
this.macro = getComponentManager().getInstance(Macro.class, "groovy");
this.context = new MacroTransformationContext();
// The script macro checks the current block (which is a macro block) to see what engine to use
this.context.setCurrentMacroBlock(new MacroBlock("groovy", Collections.<String, String>emptyMap(), false));
// Set the syntax since the script macro needs it to parse the script result using that syntax
this.context.setSyntax(Syntax.XWIKI_2_0);
}
use of org.xwiki.rendering.macro.script.ScriptMockSetup in project xwiki-platform by xwiki.
the class DefaultWikiMacroTest method setUp.
@Override
@Before
public void setUp() throws Exception {
super.setUp();
// Script setup.
ScriptMockSetup scriptMockSetup = new ScriptMockSetup(getMockery(), getComponentManager());
final DocumentAccessBridge mockDocBridge = scriptMockSetup.bridge;
this.mockWikiModel = scriptMockSetup.wikiModel;
this.wikiMacroDocumentReference = new DocumentReference("wiki", "space", "macroPage");
this.wikiMacroManager = getComponentManager().getInstance(WikiMacroManager.class);
// Make sure the old XWiki Context is set up in the Execution Context since it's used in
// DefaultWikiMacro.execute().
this.xcontext = new HashMap<String, Object>();
Execution execution = getComponentManager().getInstance(Execution.class);
execution.getContext().setProperty("xwikicontext", this.xcontext);
ScriptContextManager scm = getComponentManager().getInstance(ScriptContextManager.class);
scm.getCurrentScriptContext().setAttribute("xcontext", this.xcontext, ScriptContext.ENGINE_SCOPE);
getMockery().checking(new Expectations() {
{
allowing(mockWikiDescriptorManager).getCurrentWikiId();
will(returnValue("wiki"));
allowing(mockCurrentDocumentReferenceProvider).get();
will(returnValue(new DocumentReference("wiki", "space", "document")));
allowing(mockCurrentSpaceReferenceProvider).get();
will(returnValue(new SpaceReference("space", new WikiReference("wiki"))));
allowing(mockDocBridge).getCurrentUser();
will(returnValue("dummy"));
allowing(mockDocBridge).setCurrentUser(with(any(String.class)));
allowing(mockDocBridge).getCurrentUserReference();
will(returnValue(new DocumentReference("wiki", "XWiki", "dummy")));
allowing(mockWikiMacroFactory).isAllowed(with(any(DocumentReference.class)), with(any(WikiMacroVisibility.class)));
will(returnValue(true));
// This is the document containing the wiki macro that will be put in the context available in the macro
// Since we're not testing it here, it can be null.
allowing(mockDocBridge).getDocumentInstance(wikiMacroDocumentReference);
will(returnValue(null));
}
});
}
use of org.xwiki.rendering.macro.script.ScriptMockSetup in project xwiki-platform by xwiki.
the class DisplayMacroTest method registerComponents.
@Override
protected void registerComponents() throws Exception {
super.registerComponents();
this.mockSetup = new ScriptMockSetup(getMockery(), getComponentManager());
this.mockDocumentReferenceResolver = registerMockComponent(DocumentReferenceResolver.TYPE_STRING, "macro", "macroDocumentReferenceResolver");
this.mockAuthorization = registerMockComponent(AuthorizationManager.class);
this.displayMacro = (DisplayMacro) getComponentManager().getInstance(Macro.class, "display");
this.rendererFactory = getComponentManager().getInstance(PrintRendererFactory.class, "event/1.0");
}
use of org.xwiki.rendering.macro.script.ScriptMockSetup in project xwiki-platform by xwiki.
the class IncludeMacroTest method registerComponents.
@Override
protected void registerComponents() throws Exception {
super.registerComponents();
this.mockSetup = new ScriptMockSetup(getMockery(), getComponentManager());
this.mockDocumentReferenceResolver = registerMockComponent(DocumentReferenceResolver.TYPE_STRING, "macro", "macroDocumentReferenceResolver");
this.mockAuthorization = registerMockComponent(AuthorizationManager.class);
this.includeMacro = getComponentManager().getInstance(Macro.class, "include");
this.rendererFactory = getComponentManager().getInstance(PrintRendererFactory.class, "event/1.0");
}
use of org.xwiki.rendering.macro.script.ScriptMockSetup in project xwiki-platform by xwiki.
the class IntegrationTests method initialize.
@RenderingTestSuite.Initialized
public void initialize(MockingComponentManager cm) throws Exception {
Mockery mockery = new JUnit4Mockery();
new ScriptMockSetup(mockery, cm);
// Script Context Mock
final ScriptContextManager scm = cm.registerMockComponent(mockery, ScriptContextManager.class);
final SimpleScriptContext scriptContext = new SimpleScriptContext();
scriptContext.setAttribute("var", "value", ScriptContext.ENGINE_SCOPE);
mockery.checking(new Expectations() {
{
allowing(scm).getScriptContext();
will(returnValue(scriptContext));
}
});
}
Aggregations