diff --git a/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/api/Document.java b/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/api/Document.java index 093d1f599483d95c73da28523d2a0d8b74739ed4..773923cd68449a201226ab041ed061901696ba06 100644 --- a/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/api/Document.java +++ b/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/api/Document.java @@ -740,7 +740,8 @@ public String getRenderedContentRestricted(String text, String syntaxId) throws private String getRenderedContent(String text, String syntaxId, boolean restricted) throws XWikiException { // Make sure we keep using current author as passed content author - return this.doc.getRenderedContent(text, syntaxId, restricted, null, getXWikiContext()); + return this.doc.getRenderedContent(text, syntaxId, restricted, getCallerDocument(getXWikiContext()), + getXWikiContext()); } /** @@ -753,8 +754,8 @@ private String getRenderedContent(String text, String syntaxId, boolean restrict public String getRenderedContent(String text, String sourceSyntaxId, String targetSyntaxId) throws XWikiException { // Make sure we keep using current author as passed content author - return this.doc.getRenderedContent(text, sourceSyntaxId, targetSyntaxId, false, getCallerDocument(getXWikiContext()), - getXWikiContext()); + return this.doc.getRenderedContent(text, sourceSyntaxId, targetSyntaxId, false, + getCallerDocument(getXWikiContext()), getXWikiContext()); } private XWikiDocument getCallerDocument(XWikiContext xcontext) @@ -766,7 +767,7 @@ private XWikiDocument getCallerDocument(XWikiContext xcontext) return sdoc; } - + /** * @param targetSyntax the syntax in which to render the document content * @return the rendered content diff --git a/xwiki-platform-core/xwiki-platform-oldcore/src/test/java/com/xpn/xwiki/doc/XWikiDocumentRenderingTest.java b/xwiki-platform-core/xwiki-platform-oldcore/src/test/java/com/xpn/xwiki/doc/XWikiDocumentRenderingTest.java index 66877e5f49a60c6eeac8b82172a5a7ad1ca1a593..9c94c04f8218d6f1935dd1cf9b5516760b0a4e31 100644 --- a/xwiki-platform-core/xwiki-platform-oldcore/src/test/java/com/xpn/xwiki/doc/XWikiDocumentRenderingTest.java +++ b/xwiki-platform-core/xwiki-platform-oldcore/src/test/java/com/xpn/xwiki/doc/XWikiDocumentRenderingTest.java @@ -406,8 +406,14 @@ public void testGetRenderedContentTextWithSourceSyntax() this.document.getRenderedContent("**bold**", "xwiki/2.0", getContext())); } - public void testGetRenderedContentTextRights() + public void testGetRenderedContentTextRights() throws XWikiException { + XWikiDocument otherDocument = new XWikiDocument(new DocumentReference("otherwiki", "otherspace", "otherpage")); + otherDocument.setContentAuthorReference(new DocumentReference("otherwiki", "XWiki", "othercontentauthor")); + XWikiDocument sdoc = new XWikiDocument(new DocumentReference("callerwiki", "callerspace", "callerpage")); + sdoc.setContentAuthorReference(new DocumentReference("callerwiki", "XWiki", "calleruser")); + Document apiDocument = this.document.newDocument(getContext()); + getContext().setDoc(null); String content = @@ -416,41 +422,52 @@ public void testGetRenderedContentTextRights() this.document.setContentAuthorReference(new DocumentReference("authorwiki", "XWiki", "contentauthor")); - assertEquals("<p>authorwiki:XWiki.contentauthor Space.Page authorwiki:XWiki.contentauthor</p>", - this.document.getRenderedContent(content, Syntax.XWIKI_2_1.toIdString(), false, getContext())); + assertEquals("<p>$xcontext.sdoc.contentAuthorReference Space.Page authorwiki:XWiki.contentauthor</p>", + this.document.getRenderedContent(content, Syntax.XWIKI_2_1.toIdString(), getContext())); + + assertEquals("<p>$xcontext.sdoc.contentAuthorReference Space.Page authorwiki:XWiki.contentauthor</p>", + apiDocument.getRenderedContent(content, Syntax.XWIKI_2_1.toIdString())); assertEquals("<p>$xcontext.sdoc.contentAuthorReference Space.Page authorwiki:XWiki.contentauthor</p>", - this.document.getRenderedContent(content, Syntax.XWIKI_2_1.toIdString(), false, null, getContext())); + apiDocument.getRenderedContent(content, Syntax.XWIKI_2_1.toIdString(), Syntax.XHTML_1_0.toIdString())); - XWikiDocument otherDocument = new XWikiDocument(new DocumentReference("otherwiki", "otherspace", "otherpage")); - otherDocument.setContentAuthorReference(new DocumentReference("otherwiki", "XWiki", "othercontentauthor")); + assertEquals("<p>otherwiki:XWiki.othercontentauthor Space.Page authorwiki:XWiki.contentauthor</p>", + this.document.getRenderedContent(content, Syntax.XWIKI_2_1.toIdString(), false, otherDocument, + getContext())); getContext().setDoc(otherDocument); - assertEquals("<p>authorwiki:XWiki.contentauthor Space.Page authorwiki:XWiki.contentauthor</p>", - this.document.getRenderedContent(content, Syntax.XWIKI_2_1.toIdString(), false, getContext())); + assertEquals("<p>$xcontext.sdoc.contentAuthorReference Space.Page authorwiki:XWiki.contentauthor</p>", + this.document.getRenderedContent(content, Syntax.XWIKI_2_1.toIdString(), getContext())); + + assertEquals("<p>otherwiki:XWiki.othercontentauthor Space.Page authorwiki:XWiki.contentauthor</p>", + apiDocument.getRenderedContent(content, Syntax.XWIKI_2_1.toIdString())); assertEquals("<p>otherwiki:XWiki.othercontentauthor Space.Page authorwiki:XWiki.contentauthor</p>", - this.document.getRenderedContent(content, Syntax.XWIKI_2_1.toIdString(), false, null, getContext())); + apiDocument.getRenderedContent(content, Syntax.XWIKI_2_1.toIdString(), Syntax.XHTML_1_0.toIdString())); - XWikiDocument sdoc = new XWikiDocument(new DocumentReference("callerwiki", "callerspace", "callerpage")); - sdoc.setContentAuthorReference(new DocumentReference("callerwiki", "XWiki", "calleruser")); getContext().put("sdoc", sdoc); - getContext().setDoc(this.document); - assertEquals("<p>authorwiki:XWiki.contentauthor Space.Page authorwiki:XWiki.contentauthor</p>", - this.document.getRenderedContent(content, Syntax.XWIKI_2_1.toIdString(), false, getContext())); + assertEquals("<p>callerwiki:XWiki.calleruser Space.Page authorwiki:XWiki.contentauthor</p>", + this.document.getRenderedContent(content, Syntax.XWIKI_2_1.toIdString(), getContext())); + + assertEquals("<p>callerwiki:XWiki.calleruser Space.Page authorwiki:XWiki.contentauthor</p>", + apiDocument.getRenderedContent(content, Syntax.XWIKI_2_1.toIdString())); assertEquals("<p>callerwiki:XWiki.calleruser Space.Page authorwiki:XWiki.contentauthor</p>", - this.document.getRenderedContent(content, Syntax.XWIKI_2_1.toIdString(), false, null, getContext())); + apiDocument.getRenderedContent(content, Syntax.XWIKI_2_1.toIdString(), Syntax.XHTML_1_0.toIdString())); getContext().setDoc(otherDocument); - assertEquals("<p>authorwiki:XWiki.contentauthor Space.Page authorwiki:XWiki.contentauthor</p>", - this.document.getRenderedContent(content, Syntax.XWIKI_2_1.toIdString(), false, getContext())); + assertEquals("<p>$xcontext.sdoc.contentAuthorReference Space.Page authorwiki:XWiki.contentauthor</p>", + this.document.getRenderedContent(content, Syntax.XWIKI_2_1.toIdString(), getContext())); + + assertEquals("<p>callerwiki:XWiki.calleruser Space.Page authorwiki:XWiki.contentauthor</p>", + apiDocument.getRenderedContent(content, Syntax.XWIKI_2_1.toIdString())); assertEquals("<p>callerwiki:XWiki.calleruser Space.Page authorwiki:XWiki.contentauthor</p>", - this.document.getRenderedContent(content, Syntax.XWIKI_2_1.toIdString(), false, null, getContext())); + apiDocument.getRenderedContent(content, Syntax.XWIKI_2_1.toIdString(), Syntax.XHTML_1_0.toIdString())); + } }