use of org.xwiki.rendering.block.MacroBlock in project xwiki-platform by xwiki.
the class ContextMacroTest method executeWithReferencedDocumentHavingProgrammingRightsButNotTheCallingDocument.
@Test
public void executeWithReferencedDocumentHavingProgrammingRightsButNotTheCallingDocument() throws Exception {
MacroTransformationContext macroContext = new MacroTransformationContext();
MacroBlock macroBlock = new MacroBlock("context", Collections.emptyMap(), false);
macroContext.setCurrentMacroBlock(macroBlock);
DocumentReferenceResolver<String> resolver = this.mocker.getInstance(DocumentReferenceResolver.TYPE_STRING, "macro");
when(resolver.resolve("wiki:space.page", macroBlock)).thenReturn(new DocumentReference("wiki", "space", "page"));
DocumentAccessBridge dab = this.mocker.getInstance(DocumentAccessBridge.class);
when(dab.hasProgrammingRights()).thenReturn(false).thenReturn(true);
ContextMacroParameters parameters = new ContextMacroParameters();
parameters.setDocument("wiki:space.page");
try {
this.mocker.getComponentUnderTest().execute(parameters, "", macroContext);
fail("Should have thrown an exception");
} catch (MacroExecutionException expected) {
assertEquals("Current document must have programming rights since the context document provided [" + "wiki:space.page] has programming rights.", expected.getMessage());
}
}
use of org.xwiki.rendering.block.MacroBlock 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);
}
use of org.xwiki.rendering.block.MacroBlock in project xwiki-platform by xwiki.
the class DocumentTableBlockDataSourceTest method isDefinedChartSourceTheCurrentDocumentWhenReferenceNotNullAndMatching.
@Test
public void isDefinedChartSourceTheCurrentDocumentWhenReferenceNotNullAndMatching() throws Exception {
DocumentAccessBridge dab = this.componentManager.getInstance(DocumentAccessBridge.class);
DocumentReference currentReference = new DocumentReference("currentwiki", "currentspace", "currentpage");
when(dab.getCurrentDocumentReference()).thenReturn(currentReference);
DocumentReferenceResolver<String> resolver = this.componentManager.getInstance(DocumentReferenceResolver.TYPE_STRING);
DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
when(resolver.resolve("wiki:space.page", currentReference)).thenReturn(documentReference);
MacroBlock currentMacroBlock = mock(MacroBlock.class);
MetaDataBlock metaDataBlock = new MetaDataBlock(Collections.EMPTY_LIST, new MetaData(Collections.singletonMap(MetaData.SOURCE, (Object) "wiki:space.page")));
when(currentMacroBlock.getFirstBlock(any(BlockMatcher.class), any(Block.Axes.class))).thenReturn(metaDataBlock);
DocumentTableBlockDataSource source = this.componentManager.getComponentUnderTest();
source.setParameter("document", "wiki:space.page");
Assert.assertTrue(source.isDefinedChartSourceTheCurrentDocument(currentMacroBlock));
}
use of org.xwiki.rendering.block.MacroBlock in project xwiki-platform by xwiki.
the class MacroBlockDumper method dump.
/**
* {@inheritDoc}
*
* The dump contains all the macro parameters and the content of the macro.
* The source MetaData is also included if available.
*/
@Override
public void dump(OutputStream out, Block block) throws IOException {
if (block instanceof MacroBlock) {
MacroBlock b = (MacroBlock) block;
dump(out, b.getId(), b.getParameters(), b.getContent());
} else if (block instanceof MacroMarkerBlock) {
MacroMarkerBlock b = (MacroMarkerBlock) block;
dump(out, b.getId(), b.getParameters(), b.getContent());
} else {
throw new IllegalArgumentException("Unsupported block [" + block.getClass().getName() + "].");
}
String source = getSourceReference(block);
if (source != null) {
out.write(toBytes(source));
}
out.write(0x00);
}
use of org.xwiki.rendering.block.MacroBlock in project xwiki-platform by xwiki.
the class MacroBlockDumperTest method testDumpMacroBlockWithSource.
@Test
public void testDumpMacroBlockWithSource() throws Exception {
Block macro1 = new MacroBlock("macro", params, "content", false);
Block macro2 = new MacroBlock("macro", params, "content", false);
XDOM xdom1 = new XDOM(Collections.singletonList(macro1));
XDOM xdom2 = new XDOM(Collections.singletonList(macro2));
xdom1.getMetaData().addMetaData(MetaData.SOURCE, "source");
xdom2.getMetaData().addMetaData(MetaData.SOURCE, "source");
byte[] dump1 = dumper.dump(macro1);
byte[] dump2 = dumper.dump(macro2);
assertThat(dump1, equalTo(dump2));
dump2 = dumper.dump(new MacroBlock("macro", params, "content", false));
assertThat(dump1, not(equalTo(dump2)));
xdom2.getMetaData().addMetaData(MetaData.SOURCE, "other");
dump2 = dumper.dump(macro2);
assertThat(dump1, not(equalTo(dump2)));
xdom2.getMetaData().addMetaData(MetaData.SOURCE, null);
dump1 = dumper.dump(new MacroBlock("macro", params, "content", false));
dump2 = dumper.dump(macro2);
assertThat(dump1, equalTo(dump2));
}
Aggregations