use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.
the class XarUtilsTest method getReference.
@Test
public void getReference() throws XarException {
LocalDocumentReference documentReference = new LocalDocumentReference("space.nestedspace", "page", Locale.ENGLISH);
LocalDocumentReference nestedDocumentReference = new LocalDocumentReference(new EntityReference("page", EntityType.DOCUMENT, new EntityReference("nestedspace", EntityType.SPACE, new EntityReference("space", EntityType.SPACE))), Locale.ENGLISH);
assertEquals(nestedDocumentReference, XarUtils.getReference(getClass().getResourceAsStream("/document/document.xml")));
assertEquals(nestedDocumentReference, XarUtils.getReference(getClass().getResourceAsStream("/document/newdocument.xml")));
assertEquals(documentReference, XarUtils.getReference(getClass().getResourceAsStream("/document/legacydocument.xml")));
}
use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.
the class CreatePageIT method createExistingPageAndSpace.
/**
* Tests that creating a page or a space that already exists displays an error.
*/
@Test
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason = "See https://jira.xwiki.org/browse/XE-1146")
public void createExistingPageAndSpace() throws Exception {
// Step 0: Setup the correct environment for the test
EntityReference existingPageReference = getUtil().resolveDocumentReference(getTestClassName() + ".ExistingPage.WebHome");
String existingSpaceName = getTestClassName() + "Existing";
// All these pages are created during this test
getUtil().rest().delete(existingPageReference);
getUtil().rest().deletePage(existingSpaceName, "WebHome");
// create a template to make sure that we have a template to create from
String templateProviderName = TEMPLATE_NAME + "Provider";
String templateContent = "Templates are fun";
String templateTitle = "Funny templates";
createTemplateAndTemplateProvider(templateProviderName, templateContent, templateTitle, false);
// create a page and a space webhome
getUtil().rest().savePage(existingPageReference, "Page that already exists", "Existing page");
getUtil().rest().savePage(new LocalDocumentReference(existingSpaceName, "WebHome"), "Some content", "Existing space");
// Step 1: Create an empty page for a page that already exists
// First we must click on create from a page that already exists as otherwise we won't get the create UI
ViewPage vp = getUtil().gotoPage(existingPageReference);
CreatePagePage createPage = vp.createPage();
createPage.getDocumentPicker().toggleLocationAdvancedEdit();
createPage.getDocumentPicker().setParent(getTestClassName());
createPage.getDocumentPicker().setName("ExistingPage");
String currentURL = getDriver().getCurrentUrl();
createPage.clickCreate();
// make sure that we stay on the same page and that an error is displayed to the user. Maybe we should check the
// error
assertEquals(currentURL, getDriver().getCurrentUrl());
createPage.waitForErrorMessage();
// Step 2: Create a page from Template for a page that already exists
// restart everything to make sure it's not the error before
vp = getUtil().gotoPage(existingPageReference);
createPage = vp.createPage();
createPage.getDocumentPicker().toggleLocationAdvancedEdit();
createPage.getDocumentPicker().setParent(getTestClassName());
createPage.getDocumentPicker().setName("ExistingPage");
createPage.setTemplate(getTestClassName() + "." + templateProviderName);
currentURL = getDriver().getCurrentUrl();
createPage.clickCreate();
// make sure that we stay on the same page and that an error is displayed to the user. Maybe we should check the
// error
assertEquals(currentURL, getDriver().getCurrentUrl());
createPage.waitForErrorMessage();
// Step 3: Create a space that already exists
// Since the Flamingo skin no longer supports creating a space from the UI, trigger the Space creation UI
// by using directly the direct action URL for it.
getUtil().gotoPage(getUtil().getURL("create", new String[] { getTestClassName(), "ExistingPage", "WebHome" }, "tocreate=space"));
CreatePagePage createSpace = new CreatePagePage();
// Check that the terminal choice is not displayed in this mode.
assertFalse(createSpace.isTerminalOptionDisplayed());
currentURL = getDriver().getCurrentUrl();
// strip the parameters out of this URL
currentURL = currentURL.substring(0, currentURL.indexOf('?') > 0 ? currentURL.indexOf('?') : currentURL.length());
// Try to create the a space (non-terminal document) that already exist.
createSpace.getDocumentPicker().toggleLocationAdvancedEdit();
createSpace.fillForm(existingSpaceName, "", null, false);
createSpace.clickCreate();
String urlAfterSubmit = getDriver().getCurrentUrl();
urlAfterSubmit = urlAfterSubmit.substring(0, urlAfterSubmit.indexOf('?') > 0 ? urlAfterSubmit.indexOf('?') : urlAfterSubmit.length());
// make sure that we stay on the same page and that an error is displayed to the user. Maybe we should check the
// error
assertEquals(currentURL, urlAfterSubmit);
createSpace.waitForErrorMessage();
}
use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.
the class IconThemeListenerTest method onEventWhenEmptyListObjects.
@Test
public void onEventWhenEmptyListObjects() throws Exception {
// Mocks
XWikiDocument doc = mock(XWikiDocument.class);
List<BaseObject> list = new ArrayList<BaseObject>();
LocalDocumentReference iconThemeClassRef = new LocalDocumentReference("IconThemesCode", "IconThemeClass");
when(doc.getXObjects(eq(iconThemeClassRef))).thenReturn(list);
// Tests
mocker.getComponentUnderTest().onEvent(null, doc, null);
// Verify
verify(iconSetCache, never()).clear(any(DocumentReference.class));
}
use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.
the class AbstractMandatoryDocumentInitializer method updateDocumentFields.
// Helpers
/**
* Set the fields of the document passed as parameter. Can generate content for both XWiki Syntax 1.0 and XWiki
* Syntax 2.0. If new documents are set to be created in XWiki Syntax 1.0 then generate XWiki 1.0 Syntax otherwise
* generate XWiki Syntax 2.0.
*
* @param document the document
* @param title the page title to set (if null or blank the title won't be set)
* @return true if the document has been modified, false otherwise
*/
protected boolean updateDocumentFields(XWikiDocument document, String title) {
boolean needsUpdate = false;
if (document.getCreatorReference() == null) {
document.setCreator(XWikiRightService.SUPERADMIN_USER);
needsUpdate = true;
}
if (document.getAuthorReference() == null) {
document.setAuthorReference(document.getCreatorReference());
needsUpdate = true;
}
if (document.getParentReference() == null) {
// Use the current document's space homepage and default document name.
EntityReference spaceReference = getDocumentReference().extractReference(EntityType.SPACE);
DocumentReference fullReference = this.resolver.resolve(null, spaceReference);
EntityReference localReference = new LocalDocumentReference(fullReference);
document.setParentReference(localReference);
needsUpdate = true;
}
if (StringUtils.isNotEmpty(title) && StringUtils.isBlank(document.getTitle())) {
document.setTitle(title);
needsUpdate = true;
}
if (!document.isHidden()) {
document.setHidden(true);
needsUpdate = true;
}
return needsUpdate;
}
use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.
the class AbstractTestDocumentConfigurationSource method setStringProperty.
protected void setStringProperty(DocumentReference documentReference, String propertyName, String propertyValue) throws XWikiException {
XWikiContext xcontext = this.oldcore.getXWikiContext();
XWikiDocument document = this.oldcore.getXWikiContext().getWiki().getDocument(documentReference, xcontext);
LocalDocumentReference classReference = getClassReference();
BaseObject baseOject = document.getXObject(classReference);
if (baseOject == null) {
baseOject = new BaseObject();
baseOject.setDocumentReference(documentReference);
baseOject.setXClassReference(classReference);
document.addXObject(baseOject);
}
baseOject.setStringValue(propertyName, propertyValue);
xcontext.getWiki().saveDocument(document, xcontext);
}
Aggregations