Skip to content

Commit

Permalink
XWIKI-5027: Improve included content transformation
Browse files Browse the repository at this point in the history
* add missing translation keys
* add more tests

(cherry picked from commit d1a84a3)
  • Loading branch information
tmortagne committed Dec 13, 2022
1 parent 339373a commit 0a4f9b0
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ rendering.macro.include.parameter.author.description=The author to use to execut

org.xwiki.rendering.macro.include.IncludeMacroParameters$Context.NEW=New
org.xwiki.rendering.macro.include.IncludeMacroParameters$Context.CURRENT=Current
org.xwiki.rendering.macro.include.IncludeMacroParameters$Author.AUTO=Auto
org.xwiki.rendering.macro.include.IncludeMacroParameters$Author.CURRENT=Current
org.xwiki.rendering.macro.include.IncludeMacroParameters$Author.TARGET=Target

###############################################################################
## Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,42 @@ void executeWithCURRENTAuthor() throws Exception
assertBlocks(expected, blocks, this.rendererFactory);
}

@Test
void executeWithNoPRAuthor() throws Exception
{
// @formatter:off
String expected = "beginDocument\n"
+ "beginMetaData [[source]=[wiki:Space.IncludedPage][syntax]=[XWiki 2.0]]\n"
+ "beginParagraph\n"
+ "onWord [word]\n"
+ "endParagraph\n"
+ "endMetaData [[source]=[wiki:Space.IncludedPage][syntax]=[XWiki 2.0]]\n"
+ "endDocument";
// @formatter:on

List<Block> blocks = runIncludeMacro(Context.CURRENT, Author.AUTO, "word", false);

assertBlocks(expected, blocks, this.rendererFactory);
}

@Test
void executeWithTARGETAuthor() throws Exception
{
// @formatter:off
String expected = "beginDocument\n"
+ "beginMetaData [[source]=[wiki:Space.IncludedPage][syntax]=[XWiki 2.0]]\n"
+ "beginParagraph\n"
+ "onWord [word]\n"
+ "endParagraph\n"
+ "endMetaData [[source]=[wiki:Space.IncludedPage][syntax]=[XWiki 2.0]]\n"
+ "endDocument";
// @formatter:on

List<Block> blocks = runIncludeMacro(Context.CURRENT, Author.TARGET, "word", false);

assertBlocks(expected, blocks, this.rendererFactory);
}

@Test
void executeWithCurrentUserNoView() throws Exception
{
Expand Down Expand Up @@ -669,7 +705,10 @@ private MacroTransformationContext createMacroTransformationContext(String docum
MacroTransformationContext context = new MacroTransformationContext();
MacroBlock includeMacro =
new MacroBlock("include", Collections.singletonMap("reference", documentName), isInline);
XDOM xdom = new XDOM(List.of(includeMacro));
context.setCurrentMacroBlock(includeMacro);
context.setXDOM(xdom);

return context;
}

Expand Down Expand Up @@ -760,7 +799,8 @@ private List<Block> runIncludeMacro(final Context context, final Author author,
verify(this.dab).pushDocumentInContext(any(Map.class), same(this.includedDocument));
verify(this.dab).popDocumentFromContext(any(Map.class));
} else {
if (author == Author.CURRENT || this.authorizationManager.hasAccess(Right.PROGRAM, INCLUDED_AUHOR, null)) {
if (parameters.getAuthor() == Author.CURRENT || (parameters.getAuthor() == Author.AUTO
&& this.authorizationManager.hasAccess(Right.PROGRAM, INCLUDED_AUHOR, null))) {
verifyNoInteractions(this.authorExecutor);
} else {
DocumentReference includedReference = this.includedDocument.getDocumentReference();
Expand Down

0 comments on commit 0a4f9b0

Please sign in to comment.