use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.
the class SkinListenerTest method onEventWhenNoObject.
@Test
public void onEventWhenNoObject() throws Exception {
// Mocks
Event event = mock(Event.class);
XWikiDocument doc = mock(XWikiDocument.class);
Object data = new Object();
EntityReference classReference = new LocalDocumentReference("XWiki", "XWikiSkins");
List<BaseObject> objects = new ArrayList<>();
when(doc.getXObjects(classReference)).thenReturn(objects);
// Test
mocker.getComponentUnderTest().onEvent(event, doc, data);
// Verify
verifyZeroInteractions(lessResourcesCache);
verifyZeroInteractions(colorThemeCache);
}
use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.
the class SkinListenerTest method onEventWhenSkinIsChanged.
@Test
public void onEventWhenSkinIsChanged() throws Exception {
// Mocks
Event event = mock(Event.class);
XWikiDocument doc = mock(XWikiDocument.class);
Object data = new Object();
EntityReference classReference = new LocalDocumentReference("XWiki", "XWikiSkins");
List<BaseObject> objects = new ArrayList<>();
BaseObject object = mock(BaseObject.class);
objects.add(object);
when(doc.getXObjects(classReference)).thenReturn(objects);
DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
when(doc.getDocumentReference()).thenReturn(documentReference);
DocumentSkinReference skinReference = new DocumentSkinReference(documentReference, null);
when(skinReferenceFactory.createReference(documentReference)).thenReturn(skinReference);
// Test
mocker.getComponentUnderTest().onEvent(event, doc, data);
// Verify
verify(lessResourcesCache).clearFromSkin(skinReference);
verify(colorThemeCache).clearFromSkin(skinReference);
}
use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.
the class DocumentFieldsTest method titleAndContent.
@Test
public void titleAndContent() {
// Create a new application.
String appName = RandomStringUtils.randomAlphabetic(6);
ApplicationCreatePage appCreatePage = ApplicationCreatePage.gotoPage();
appCreatePage.setApplicationName(appName);
appCreatePage.waitForApplicationNamePreview();
ApplicationClassEditPage classEditPage = appCreatePage.clickNextStep();
// Add a standard field.
ClassFieldEditPane numberField = classEditPage.addField("Number");
// Add the Title and Content fields.
ClassFieldEditPane titleField = classEditPage.addField("Title");
ClassFieldEditPane contentField = classEditPage.addField("Content");
// Change the default field pretty names.
// See XWIKI-9154: The application live table uses the standard 'Page title' heading instead of the pretty name
// set for the Title field
titleField.setPrettyName("My Title");
contentField.setPrettyName("My Content");
// Set the default values that will be saved in the template.
numberField.setDefaultValue("13");
String defaultTitle = "Enter title here";
titleField.setDefaultValue(defaultTitle);
String defaultContent = "Enter content here";
contentField.setDefaultValue(defaultContent);
// Add live table columns for Title and Content.
ApplicationHomeEditPage homeEditPage = classEditPage.clickNextStep().clickNextStep().waitUntilPageIsLoaded();
homeEditPage.addLiveTableColumn("My Title");
homeEditPage.addLiveTableColumn("My Content");
// Add an application entry.
EntryNamePane entryNamePane = homeEditPage.clickFinish().clickAddNewEntry();
entryNamePane.setName("Test");
EntryEditPage entryEditPage = entryNamePane.clickAdd();
Assert.assertEquals("13", entryEditPage.getValue("number1"));
// The page name is used as the default value for the title field.
Assert.assertEquals("Test", entryEditPage.getDocumentTitle());
Assert.assertEquals("Test", entryEditPage.getTitle());
entryEditPage.setTitle("Foo");
Assert.assertEquals(defaultContent, entryEditPage.getContent());
entryEditPage.setContent("Bar");
// Check that the title and the content of the entry have been updated.
ViewPage entryViewPage = entryEditPage.clickSaveAndView();
Assert.assertEquals("Foo", entryViewPage.getDocumentTitle());
Assert.assertTrue(entryViewPage.getContent().contains("Bar"));
entryViewPage.clickBreadcrumbLink(appName);
// Check the entries live table.
LiveTableElement liveTable = new ApplicationHomePage().getEntriesLiveTable();
liveTable.waitUntilReady();
Assert.assertEquals(1, liveTable.getRowCount());
Assert.assertTrue(liveTable.hasRow("My Title", "Foo"));
Assert.assertTrue(liveTable.hasRow("My Content", "Bar"));
// Check that the title and the content of the class have not been changed.
getUtil().gotoPage(new LocalDocumentReference(Arrays.asList(appName, "Code"), appName + "Class"), "edit", "editor=wiki");
WikiEditPage editPage = new WikiEditPage();
Assert.assertEquals(appName + " Class", editPage.getTitle());
Assert.assertEquals("", editPage.getContent());
// Now edit the class and check if the default values for title and content are taken from the template.
editPage.editInline();
Assert.assertEquals(defaultTitle, new ClassFieldEditPane("title1").getDefaultValue());
Assert.assertEquals(defaultContent, new ClassFieldEditPane("content1").getDefaultValue());
}
use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.
the class AbstractEditorBindingsSource method getBaseObjects.
private List<BaseObject> getBaseObjects() throws XWikiException {
DocumentReference documentReference = getFailsafeDocumentReference();
LocalDocumentReference classReference = getFailsafeClassReference();
if (documentReference != null && classReference != null) {
XWikiContext xcontext = this.xcontextProvider.get();
XWikiDocument document = xcontext.getWiki().getDocument(getDocumentReference(), xcontext);
List<BaseObject> objects = document.getXObjects(classReference);
if (objects != null) {
return objects;
}
}
return Collections.emptyList();
}
use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.
the class XWikiAllGroupDocumentInitializer method updateDocument.
@Override
public boolean updateDocument(XWikiDocument document) {
boolean needsUpdate = false;
// Create the reference to the parent of the current document which is also the class of the object to create
LocalDocumentReference classReference = new LocalDocumentReference(XWiki.SYSTEM_SPACE, CLASS_NAME);
// Ensure the document has a creator
if (document.getCreatorReference() == null) {
document.setCreatorReference(new DocumentReference(wikiDescriptorManager.getMainWikiId(), XWiki.SYSTEM_SPACE, "superadmin"));
needsUpdate = true;
}
// Ensure the document has an author
if (document.getAuthorReference() == null) {
document.setAuthorReference(document.getCreatorReference());
needsUpdate = true;
}
// Ensure the document has a parent
if (document.getParentReference() == null) {
document.setParentReference(classReference);
needsUpdate = true;
}
// Ensure the document is hidden, like every technical document
if (!document.isHidden()) {
document.setHidden(true);
needsUpdate = true;
}
// Ensure the document has an XWikiGroups object
if (document.getXObject(classReference) == null) {
try {
BaseObject obj = document.newXObject(classReference, xcontextProvider.get());
obj.setStringValue("member", "");
needsUpdate = true;
} catch (XWikiException e) {
logger.error(String.format("Impossible to add an object to the document XWiki.XWikiAllGroups in the wiki [%s].", document.getDocumentReference().getWikiReference().getName()), e);
}
}
return needsUpdate;
}
Aggregations