Skip to content
Snippets Groups Projects
Commit 97caaaf9 authored by tmortagne's avatar tmortagne
Browse files

XWIKI-8276: Pages with attachment imported with the Distribution Wizard are missing the creator

parent 63432231
No related merge requests found
......@@ -272,7 +272,7 @@ private void saveDocument(XWikiDocument document, String comment, boolean setCre
if (document.isNew()) {
currentDocument.apply(document);
if (setCreator) {
currentDocument.setAuthorReference(document.getCreatorReference());
currentDocument.setCreatorReference(document.getCreatorReference());
}
currentDocument.setAuthorReference(document.getAuthorReference());
currentDocument.setContentAuthorReference(document.getContentAuthorReference());
......
......@@ -284,16 +284,20 @@ public Object invoke(org.jmock.api.Invocation invocation) throws Throwable
"RegisterMacrosOnImportListener");
}
private XarInstalledExtension install(ExtensionId extensionId, String wiki) throws Throwable
private XarInstalledExtension install(ExtensionId extensionId, String wiki, DocumentReference user)
throws Throwable
{
return installOnNamespace(extensionId, wiki != null ? "wiki:" + wiki : null);
return installOnNamespace(extensionId, wiki != null ? "wiki:" + wiki : null, user);
}
private XarInstalledExtension installOnNamespace(ExtensionId extensionId, String namespace) throws Throwable
private XarInstalledExtension installOnNamespace(ExtensionId extensionId, String namespace, DocumentReference user)
throws Throwable
{
InstallRequest installRequest = new InstallRequest();
installRequest.setProperty("user.reference", getContext().getUserReference());
installRequest.setProperty("checkrights", true);
if (user != null) {
installRequest.setProperty("user.reference", getContext().getUserReference());
installRequest.setProperty("checkrights", true);
}
installRequest.addExtension(extensionId);
if (namespace != null) {
installRequest.addNamespace(namespace);
......@@ -348,7 +352,7 @@ public void testInstallOnWiki() throws Throwable
// install
install(this.localXarExtensiontId1, "wiki");
install(this.localXarExtensiontId1, "wiki", this.contextUser);
// validate
......@@ -449,6 +453,123 @@ public void testInstallOnWiki() throws Throwable
Assert.assertTrue("Document is not hidden", hiddenpage.isHidden());
}
@Test
public void testInstallOnWikiWithoutAuthor() throws Throwable
{
XWikiDocument existingDocument = new XWikiDocument(new DocumentReference("wiki", "space", "page"));
BaseObject object = new BaseObject();
object.setXClassReference(new DocumentReference("wiki", "space", "class"));
existingDocument.addXObject(object);
existingDocument.setCreatorReference(new DocumentReference("wiki", "space", "existingcreator"));
this.mockXWiki.saveDocument(existingDocument, "", getContext());
// install
install(this.localXarExtensiontId1, "wiki", null);
// validate
DocumentReference authorReference = new DocumentReference("wiki", "XWiki", "author");
DocumentReference creatorReference = new DocumentReference("wiki", "XWiki", "creator");
DocumentReference contentAuthorReference = new DocumentReference("wiki", "XWiki", "contentAuthor");
// space.page
XWikiDocument page = this.mockXWiki.getDocument(existingDocument.getDocumentReference(), getContext());
Assert.assertFalse("Document wiki:space.page has not been saved in the database", page.isNew());
Assert.assertNull(page.getXObject(object.getXClassReference()));
Assert.assertEquals("Wrong content", "content", page.getContent());
Assert.assertEquals("Wrong creator", new DocumentReference("wiki", "space", "existingcreator"),
page.getCreatorReference());
Assert.assertEquals("Wrong author", authorReference, page.getAuthorReference());
Assert.assertEquals("Wrong content author", contentAuthorReference, page.getContentAuthorReference());
Assert.assertEquals("Wrong version", "2.1", page.getVersion());
Assert.assertFalse("Document is hidden", page.isHidden());
BaseClass baseClass = page.getXClass();
Assert.assertNotNull(baseClass.getField("property"));
Assert.assertEquals("property", baseClass.getField("property").getName());
Assert.assertSame(NumberClass.class, baseClass.getField("property").getClass());
// space.pagewithattachment
XWikiDocument pagewithattachment =
this.mockXWiki.getDocument(new DocumentReference("wiki", "space", "pagewithattachment"), getContext());
Assert.assertFalse(pagewithattachment.isNew());
Assert.assertEquals("Wrong version", "2.1", pagewithattachment.getVersion());
Assert.assertEquals("Wrong creator", creatorReference, pagewithattachment.getCreatorReference());
Assert.assertEquals("Wrong author", authorReference, pagewithattachment.getAuthorReference());
Assert.assertEquals("Wrong content author", contentAuthorReference, pagewithattachment.getContentAuthorReference());
XWikiAttachment attachment = pagewithattachment.getAttachment("attachment.txt");
Assert.assertNotNull(attachment);
Assert.assertEquals("attachment.txt", attachment.getFilename());
Assert.assertEquals(18, attachment.getContentSize(getContext()));
Assert.assertEquals("attachment content", IOUtils.toString(attachment.getContentInputStream(getContext())));
// space1.page1
XWikiDocument page1 =
this.mockXWiki.getDocument(new DocumentReference("wiki", "space1", "page1"), getContext());
Assert.assertFalse("Document wiki:space1.page1 has not been saved in the database", page1.isNew());
// translated.translated
DocumentReference translatedReference = new DocumentReference("wiki", "translated", "translated");
XWikiDocument defaultTranslated = this.mockXWiki.getDocument(translatedReference, getContext());
Assert.assertNotNull("Document wiki:translated.translated has not been saved in the database",
defaultTranslated);
Assert.assertFalse("Document wiki:translated.translated has not been saved in the database",
defaultTranslated.isNew());
Assert.assertEquals("Wrong content", "default content", defaultTranslated.getContent());
Assert.assertEquals("Wrong creator", creatorReference, defaultTranslated.getCreatorReference());
Assert.assertEquals("Wrong author", authorReference, defaultTranslated.getAuthorReference());
Assert.assertEquals("Wrong content author", contentAuthorReference, defaultTranslated.getContentAuthorReference());
Assert.assertEquals("Wrong version", "1.1", defaultTranslated.getVersion());
// translated.translated.tr
XWikiDocument translated = this.documents.get(translatedReference).get("tr");
Assert.assertNotNull("Document wiki:translated.translated in langauge tr has not been saved in the database",
translated);
Assert.assertFalse("Document wiki:translated.translated in langauge tr has not been saved in the database",
translated.isNew());
Assert.assertEquals("Wrong content", "tr content", translated.getContent());
Assert.assertEquals("Wrong creator", creatorReference, translated.getCreatorReference());
Assert.assertEquals("Wrong author", authorReference, translated.getAuthorReference());
Assert.assertEquals("Wrong content author", contentAuthorReference, translated.getContentAuthorReference());
Assert.assertEquals("Wrong version", "1.1", translated.getVersion());
// translated.translated.fr
XWikiDocument translated2 = this.documents.get(translatedReference).get("fr");
Assert.assertNotNull("Document wiki:translated.translated in language fr has not been saved in the database",
translated2);
Assert.assertFalse("Document wiki:translated.translated in langauge fr has not been saved in the database",
translated2.isNew());
Assert.assertEquals("Wrong content", "fr content", translated2.getContent());
Assert.assertEquals("Wrong creator", creatorReference, translated2.getCreatorReference());
Assert.assertEquals("Wrong author", authorReference, translated2.getAuthorReference());
Assert.assertEquals("Wrong content author", contentAuthorReference, translated2.getContentAuthorReference());
Assert.assertEquals("Wrong version", "1.1", translated2.getVersion());
// space.hiddenpage
XWikiDocument hiddenpage =
this.mockXWiki.getDocument(new DocumentReference("wiki", "space", "hiddenpage"), getContext());
Assert.assertNotNull("Document wiki:space.hiddenpage has not been saved in the database", hiddenpage);
Assert.assertFalse("Document wiki:space.hiddenpage has not been saved in the database", hiddenpage.isNew());
Assert.assertTrue("Document is not hidden", hiddenpage.isHidden());
}
@Test
public void testUpgradeOnWiki() throws Throwable
{
......@@ -462,11 +583,11 @@ public void testUpgradeOnWiki() throws Throwable
}
});
install(this.localXarExtensiontId1, "wiki");
install(this.localXarExtensiontId1, "wiki", this.contextUser);
// upgrade
install(this.localXarExtensiontId2, "wiki");
install(this.localXarExtensiontId2, "wiki", this.contextUser);
// validate
......@@ -513,7 +634,7 @@ public void testUninstallFromWiki() throws Throwable
}
});
install(this.localXarExtensiontId1, "wiki");
install(this.localXarExtensiontId1, "wiki", this.contextUser);
// uninstall
......@@ -557,7 +678,7 @@ public void testInstallOnRoot() throws Throwable
// install
install(this.localXarExtensiontId1, null);
install(this.localXarExtensiontId1, null, this.contextUser);
// validate
......@@ -682,7 +803,7 @@ public void testInstallOnRootWithoutAdminRights() throws Throwable
}
});
install(this.localXarExtensiontId1, null);
install(this.localXarExtensiontId1, null, this.contextUser);
}
// uninstall
......@@ -699,13 +820,13 @@ public void testInstallOnWikiWithoutAdminRights() throws Throwable
}
});
install(this.localXarExtensiontId1, "wiki");
install(this.localXarExtensiontId1, "wiki", this.contextUser);
}
@Test(expected = InstallException.class)
public void testInstallOnUnsupportedNamespace() throws Throwable
{
installOnNamespace(this.localXarExtensiontId1, "unsupportednamespace");
installOnNamespace(this.localXarExtensiontId1, "unsupportednamespace", this.contextUser);
}
// uninstall
......@@ -725,7 +846,7 @@ public void testUninstallOnRootWithoutAdminRights() throws Throwable
}
});
install(this.localXarExtensiontId1, null);
install(this.localXarExtensiontId1, null, this.contextUser);
getMockery().checking(new Expectations()
{
......@@ -751,7 +872,7 @@ public void testUninstallOnWikiWithoutAdminRights() throws Throwable
}
});
install(this.localXarExtensiontId1, "wiki");
install(this.localXarExtensiontId1, "wiki", this.contextUser);
getMockery().checking(new Expectations()
{
......
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