Search in sources :

Example 6 with DocumentDisplayer

use of org.xwiki.display.internal.DocumentDisplayer in project xwiki-platform by xwiki.

the class SheetDocumentDisplayerTest method testPreserveSheetPRWhenDocumentIsOnContext.

/**
 * Tests if the programming rights of the sheet are preserved when the document is already on the context.
 *
 * @throws Exception if something wrong happens
 */
@Test
public void testPreserveSheetPRWhenDocumentIsOnContext() throws Exception {
    DocumentModelBridge document = mockDocument(DOCUMENT_REFERENCE);
    DocumentModelBridge sheet = mockDocument(SHEET_REFERENCE);
    setCurrentDocument(document);
    SheetManager sheetManager = this.mocker.getInstance(SheetManager.class);
    when(sheetManager.getSheets(document, "view")).thenReturn(Collections.singletonList(SHEET_REFERENCE));
    DocumentModelBridge originalSecurityDoc = mock(DocumentModelBridge.class, "sdoc");
    // Required in order to preserve the programming rights of the sheet.
    when(this.modelBridge.setSecurityDocument(sheet)).thenReturn(originalSecurityDoc);
    XDOM output = new XDOM(Collections.<Block>emptyList());
    DocumentDisplayer documentDisplayer = this.mocker.getInstance(DocumentDisplayer.class);
    when(documentDisplayer.display(eq(sheet), any(DocumentDisplayerParameters.class))).thenReturn(output);
    assertSame(output, this.mocker.getComponentUnderTest().display(document, new DocumentDisplayerParameters()));
    // The security document must be reverted.
    verify(this.modelBridge).setSecurityDocument(originalSecurityDoc);
}
Also used : DocumentDisplayerParameters(org.xwiki.display.internal.DocumentDisplayerParameters) DocumentDisplayer(org.xwiki.display.internal.DocumentDisplayer) XDOM(org.xwiki.rendering.block.XDOM) DocumentModelBridge(org.xwiki.bridge.DocumentModelBridge) SheetManager(org.xwiki.sheet.SheetManager) Test(org.junit.Test)

Aggregations

DocumentDisplayer (org.xwiki.display.internal.DocumentDisplayer)6 DocumentDisplayerParameters (org.xwiki.display.internal.DocumentDisplayerParameters)6 DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)5 Test (org.junit.Test)4 DocumentReference (org.xwiki.model.reference.DocumentReference)3 XDOM (org.xwiki.rendering.block.XDOM)3 Expectations (org.jmock.Expectations)2 Invocation (org.jmock.api.Invocation)2 CustomAction (org.jmock.lib.action.CustomAction)2 MacroExecutionException (org.xwiki.rendering.macro.MacroExecutionException)2 MacroTransformationContext (org.xwiki.rendering.transformation.MacroTransformationContext)2 SheetManager (org.xwiki.sheet.SheetManager)2 XWikiException (com.xpn.xwiki.XWikiException)1 InputStreamReader (java.io.InputStreamReader)1 HashMap (java.util.HashMap)1 DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)1 ModelContext (org.xwiki.model.ModelContext)1 WikiReference (org.xwiki.model.reference.WikiReference)1 DisplayMacroParameters (org.xwiki.rendering.macro.display.DisplayMacroParameters)1 IncludeMacroParameters (org.xwiki.rendering.macro.include.IncludeMacroParameters)1