Search in sources :

Example 31 with LocalDocumentReference

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);
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) EntityReference(org.xwiki.model.reference.EntityReference) ArrayList(java.util.ArrayList) DocumentCreatedEvent(org.xwiki.bridge.event.DocumentCreatedEvent) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) Event(org.xwiki.observation.event.Event) DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) BaseObject(com.xpn.xwiki.objects.BaseObject) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Example 32 with LocalDocumentReference

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);
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) EntityReference(org.xwiki.model.reference.EntityReference) ArrayList(java.util.ArrayList) DocumentCreatedEvent(org.xwiki.bridge.event.DocumentCreatedEvent) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) Event(org.xwiki.observation.event.Event) DocumentDeletedEvent(org.xwiki.bridge.event.DocumentDeletedEvent) BaseObject(com.xpn.xwiki.objects.BaseObject) DocumentSkinReference(org.xwiki.lesscss.internal.skin.DocumentSkinReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) DocumentReference(org.xwiki.model.reference.DocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Example 33 with LocalDocumentReference

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());
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) EntryEditPage(org.xwiki.appwithinminutes.test.po.EntryEditPage) ClassFieldEditPane(org.xwiki.appwithinminutes.test.po.ClassFieldEditPane) LiveTableElement(org.xwiki.test.ui.po.LiveTableElement) EntryNamePane(org.xwiki.appwithinminutes.test.po.EntryNamePane) ApplicationHomeEditPage(org.xwiki.appwithinminutes.test.po.ApplicationHomeEditPage) ViewPage(org.xwiki.test.ui.po.ViewPage) ApplicationCreatePage(org.xwiki.appwithinminutes.test.po.ApplicationCreatePage) WikiEditPage(org.xwiki.test.ui.po.editor.WikiEditPage) ApplicationHomePage(org.xwiki.appwithinminutes.test.po.ApplicationHomePage) ApplicationClassEditPage(org.xwiki.appwithinminutes.test.po.ApplicationClassEditPage) Test(org.junit.Test) AbstractTest(org.xwiki.test.ui.AbstractTest)

Example 34 with LocalDocumentReference

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();
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiContext(com.xpn.xwiki.XWikiContext) DocumentReference(org.xwiki.model.reference.DocumentReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 35 with LocalDocumentReference

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;
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) DocumentReference(org.xwiki.model.reference.DocumentReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) XWikiException(com.xpn.xwiki.XWikiException) BaseObject(com.xpn.xwiki.objects.BaseObject)

Aggregations

LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)58 Test (org.junit.Test)28 DocumentReference (org.xwiki.model.reference.DocumentReference)25 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)23 BaseObject (com.xpn.xwiki.objects.BaseObject)19 XWikiContext (com.xpn.xwiki.XWikiContext)10 EntityReference (org.xwiki.model.reference.EntityReference)10 ArrayList (java.util.ArrayList)8 ViewPage (org.xwiki.test.ui.po.ViewPage)6 Page (org.xwiki.rest.model.jaxb.Page)5 DocumentCreatedEvent (org.xwiki.bridge.event.DocumentCreatedEvent)4 DocumentDeletedEvent (org.xwiki.bridge.event.DocumentDeletedEvent)4 DocumentUpdatedEvent (org.xwiki.bridge.event.DocumentUpdatedEvent)4 Event (org.xwiki.observation.event.Event)4 XWiki (com.xpn.xwiki.XWiki)3 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)2 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)2 Principal (java.security.Principal)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2