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);
}
Aggregations