use of org.xwiki.rendering.parser.Parser 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));
}
});
}
use of org.xwiki.rendering.parser.Parser in project xwiki-platform by xwiki.
the class DefaultWikiComponentBridgeTest method getHandledMethods.
@Test
public void getHandledMethods() throws Exception {
final ComponentManager componentManager = getComponentManager().getInstance(ComponentManager.class);
final ContentParser contentParser = getComponentManager().getInstance(ContentParser.class);
final Parser parser = getMockery().mock(Parser.class);
final XDOM xdom = new XDOM(new ArrayList<Block>());
final BaseObject methodObject = getMockery().mock(BaseObject.class, "method");
final Vector<BaseObject> methodObjects = new Vector<BaseObject>();
methodObjects.add(methodObject);
getMockery().checking(new Expectations() {
{
oneOf(componentDoc).getObjectNumbers(METHOD_CLASS);
will(returnValue(1));
oneOf(componentDoc).getObjects(METHOD_CLASS);
will(returnValue(methodObjects));
allowing(methodObject).getStringValue(METHOD_NAME_FIELD);
will(returnValue("test"));
allowing(methodObject).getStringValue(METHOD_CODE_FIELD);
will(returnValue("test"));
oneOf(componentDoc).getSyntax();
will(returnValue(Syntax.XWIKI_2_1));
oneOf(contentParser).parse("test", Syntax.XWIKI_2_1, DOC_REFERENCE);
will(returnValue(xdom));
}
});
Assert.assertEquals(1, bridge.getHandledMethods(DOC_REFERENCE).size());
}
use of org.xwiki.rendering.parser.Parser in project xwiki-platform by xwiki.
the class RenderingScriptService method parse.
/**
* Parses a text written in the passed syntax.
*
* @param text the text to parse
* @param syntaxId the id of the syntax in which the text is written in
* @return the XDOM representing the AST of the parsed text or null if an error occurred
* @since 3.2M3
*/
public XDOM parse(String text, String syntaxId) {
XDOM result;
try {
Parser parser = this.componentManagerProvider.get().getInstance(Parser.class, syntaxId);
result = parser.parse(new StringReader(text));
} catch (Exception e) {
result = null;
}
return result;
}
use of org.xwiki.rendering.parser.Parser in project xwiki-platform by xwiki.
the class DefaultWikiMacroTest method registerWikiMacro.
private void registerWikiMacro(String macroId, String macroContent, Syntax syntax, List<WikiMacroParameterDescriptor> parameterDescriptors) throws Exception {
WikiMacroDescriptor descriptor = new WikiMacroDescriptor(new MacroId(macroId), "Wiki Macro", "Description", "Test", WikiMacroVisibility.GLOBAL, new DefaultContentDescriptor(false), parameterDescriptors);
Parser parser = getComponentManager().getInstance(Parser.class, syntax.toIdString());
DefaultWikiMacro wikiMacro = new DefaultWikiMacro(wikiMacroDocumentReference, null, true, descriptor, parser.parse(new StringReader(macroContent)), syntax, getComponentManager());
this.wikiMacroManager.registerWikiMacro(wikiMacroDocumentReference, wikiMacro);
}
use of org.xwiki.rendering.parser.Parser in project xwiki-platform by xwiki.
the class IntegrationTests method initialize.
@RenderingTestSuite.Initialized
public void initialize(MockitoComponentManager componentManager) throws Exception {
ModelContext modelContext = componentManager.registerMockComponent(ModelContext.class);
when(modelContext.getCurrentEntityReference()).thenReturn(new WikiReference("currentWiki"));
// Document Access Bridge mock
DocumentAccessBridge dab = componentManager.registerMockComponent(DocumentAccessBridge.class);
DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
DocumentReference currentDocumentReference = new DocumentReference("currentwiki", "currentspace", "currentpage");
DocumentModelBridge document = Mockito.mock(DocumentModelBridge.class);
when(dab.getDocumentURL(new DocumentReference("currentWiki", "space", "page"), "temp", null, null)).thenReturn("temppath");
when(dab.getCurrentDocumentReference()).thenReturn(currentDocumentReference);
when(dab.exists(documentReference)).thenReturn(true);
when(dab.getDocumentInstance(documentReference)).thenReturn(document);
when(dab.getCurrentUserReference()).thenReturn(null);
DocumentDisplayer displayer = componentManager.registerMockComponent(DocumentDisplayer.class);
Parser parser = componentManager.getInstance(Parser.class, Syntax.XWIKI_2_0.toIdString());
final XDOM xdom = parser.parse(new InputStreamReader(getClass().getClassLoader().getResourceAsStream(WIKI_CONTENT_FILE)));
when(displayer.display(eq(document), any(DocumentDisplayerParameters.class))).thenReturn(xdom);
AuthorizationManager authorizationManager = componentManager.registerMockComponent(AuthorizationManager.class);
when(authorizationManager.hasAccess(Right.VIEW, null, documentReference)).thenReturn(true);
componentManager.registerMockComponent(DocumentReferenceResolver.TYPE_STRING, "current");
componentManager.registerMockComponent(SpaceReferenceResolver.TYPE_STRING, "current");
}
Aggregations