Skip to content
Snippets Groups Projects
Commit 514e0898 authored by Michael Hamann's avatar Michael Hamann
Browse files

XWIKI-21553: Do not override existing documents on user action

* Remove mock() call not available in 14.10.x
* Use constants for user and document reference in the test

(cherry picked from commit f1401025)
parent 56f5d8aa
No related branches found
No related tags found
No related merge requests found
...@@ -46,39 +46,39 @@ ...@@ -46,39 +46,39 @@
@ComponentList({ DefaultObservationManager.class, DocumentOverrideListener.class }) @ComponentList({ DefaultObservationManager.class, DocumentOverrideListener.class })
class DocumentOverrideListenerTest class DocumentOverrideListenerTest
{ {
private static final DocumentReference DOCUMENT_REFERENCE = new DocumentReference("wiki", "space", "page");
private static final DocumentReference USER_REFERENCE = new DocumentReference("wiki", "XWiki", "user");
@InjectMockitoOldcore @InjectMockitoOldcore
private MockitoOldcore oldcore; private MockitoOldcore oldcore;
@Test @Test
void savingNewDocument() throws Exception void savingNewDocument() throws Exception
{ {
DocumentReference documentReference = new DocumentReference("wiki", "space", "page"); XWikiDocument document = new XWikiDocument(DOCUMENT_REFERENCE);
XWikiDocument document = new XWikiDocument(documentReference); this.oldcore.getSpyXWiki().checkSavingDocument(USER_REFERENCE, document, this.oldcore.getXWikiContext());
this.oldcore.getSpyXWiki().checkSavingDocument(mock(), document, this.oldcore.getXWikiContext());
} }
@Test @Test
void savingExistingDocument() throws Exception void savingExistingDocument() throws Exception
{ {
DocumentReference documentReference = new DocumentReference("wiki", "space", "page"); XWikiDocument document = new XWikiDocument(DOCUMENT_REFERENCE);
XWikiDocument document = new XWikiDocument(documentReference);
this.oldcore.getSpyXWiki().saveDocument(document, this.oldcore.getXWikiContext()); this.oldcore.getSpyXWiki().saveDocument(document, this.oldcore.getXWikiContext());
document = this.oldcore.getSpyXWiki().getDocument(documentReference, this.oldcore.getXWikiContext()); document = this.oldcore.getSpyXWiki().getDocument(DOCUMENT_REFERENCE, this.oldcore.getXWikiContext());
assertFalse(document.isNew()); assertFalse(document.isNew());
this.oldcore.getSpyXWiki().checkSavingDocument(mock(), document, this.oldcore.getXWikiContext()); this.oldcore.getSpyXWiki().checkSavingDocument(USER_REFERENCE, document, this.oldcore.getXWikiContext());
} }
@Test @Test
void savingOverridingExistingDocument() throws Exception void savingOverridingExistingDocument() throws Exception
{ {
DocumentReference documentReference = new DocumentReference("wiki", "space", "page"); XWikiDocument document = new XWikiDocument(DOCUMENT_REFERENCE);
DocumentReference userReference = new DocumentReference("wiki", "XWiki", "user");
XWikiDocument document = new XWikiDocument(documentReference);
this.oldcore.getSpyXWiki().saveDocument(document, this.oldcore.getXWikiContext()); this.oldcore.getSpyXWiki().saveDocument(document, this.oldcore.getXWikiContext());
XWikiDocument newDocument = new XWikiDocument(documentReference); XWikiDocument newDocument = new XWikiDocument(DOCUMENT_REFERENCE);
XWikiException exception = assertThrows(XWikiException.class, XWikiException exception = assertThrows(XWikiException.class,
() -> this.oldcore.getSpyXWiki() () -> this.oldcore.getSpyXWiki()
.checkSavingDocument(userReference, newDocument, this.oldcore.getXWikiContext())); .checkSavingDocument(USER_REFERENCE, newDocument, this.oldcore.getXWikiContext()));
assertEquals("Error number 9001 in 9: User [wiki:XWiki.user] has been denied the right to save the " assertEquals("Error number 9001 in 9: User [wiki:XWiki.user] has been denied the right to save the "
+ "document [wiki:space.page]. Reason: [The document already exists but the document to be saved is marked " + "document [wiki:space.page]. Reason: [The document already exists but the document to be saved is marked "
+ "as new.]", exception.getMessage()); + "as new.]", exception.getMessage());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment