Search in sources :

Example 16 with LocalDocumentReference

use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.

the class DefaultContextualAuthorizationManagerTest method checkAccess.

// Tests
@Test
public void checkAccess() throws Exception {
    LocalDocumentReference localReference = new LocalDocumentReference("space", "page");
    this.mocker.getComponentUnderTest().checkAccess(Right.VIEW, localReference);
    verify(this.authorizationManager).checkAccess(same(Right.VIEW), isNull(DocumentReference.class), eq(new DocumentReference(localReference, this.currentWikiReference)));
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) DocumentReference(org.xwiki.model.reference.DocumentReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) Test(org.junit.Test)

Example 17 with LocalDocumentReference

use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.

the class UIExtensionTest method setUp.

@Before
public void setUp() throws Exception {
    // Delete pages that we create in the test
    getUtil().rest().delete(new LocalDocumentReference(getTestClassName(), HELLOWORLD_UIX_PAGE));
    getUtil().rest().delete(new LocalDocumentReference(getTestClassName(), HELLOWIKIWORLD_UIX_PAGE));
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) Before(org.junit.Before)

Example 18 with LocalDocumentReference

use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.

the class CopyPageTest method testCopyOverwritePage.

@Test
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason = "See https://jira.xwiki.org/browse/XE-1146")
public void testCopyOverwritePage() throws Exception {
    String sourceSpaceName = getTestClassName();
    String sourcePageName = getTestMethodName();
    String targetSpaceName = getTestClassName() + "Copy";
    String targetPageName = getTestMethodName() + "Copy";
    // Delete page that may already exist
    getUtil().rest().deletePage(sourceSpaceName, sourcePageName);
    getUtil().rest().deletePage(targetSpaceName, targetPageName);
    // Create a new page that will be overwritten.
    getUtil().rest().savePage(new LocalDocumentReference(targetSpaceName, targetPageName), OVERWRITTEN_PAGE_CONTENT, targetPageName);
    // Create a new page that will be copied.
    ViewPage viewPage = getUtil().createPage(sourceSpaceName, sourcePageName, PAGE_CONTENT, sourcePageName);
    // Click on Copy from the Page top menu.
    viewPage.copy();
    CopyPage copyPage = new CopyPage();
    // Fill the target destination the page to be copied to.
    DocumentPicker documentPicker = copyPage.getDocumentPicker();
    documentPicker.setTitle(targetPageName);
    documentPicker.browseDocuments();
    DocumentPickerModal documentPickerModal = new DocumentPickerModal();
    documentPickerModal.waitForDocumentSelected(sourceSpaceName, "WebHome").selectDocument(targetSpaceName, "WebHome");
    documentPicker.waitForLocation(Arrays.asList("", targetSpaceName, targetPageName));
    Assert.assertEquals(targetSpaceName, copyPage.getTargetSpaceName());
    // Click copy button
    CopyOverwritePromptPage copyOverwritePrompt = copyPage.clickCopyButtonExpectingOverwritePrompt();
    // Check overwrite warning
    Assert.assertEquals(OVERWRITE_PROMPT1 + targetSpaceName + '.' + targetPageName + OVERWRITE_PROMPT2, copyOverwritePrompt.getWarningMessage());
    // Cancel the copy
    viewPage = copyOverwritePrompt.clickCancelButton();
    // Verify that we have been sent back to the original page
    Assert.assertEquals(sourcePageName, viewPage.getDocumentTitle());
    // Click on Copy from the Page top menu.
    viewPage.copy();
    copyPage = new CopyPage();
    // Fill the target destination the page to be copied to.
    copyPage.getDocumentPicker().toggleLocationAdvancedEdit().setParent(targetSpaceName).setName(targetPageName);
    // Click copy button
    copyOverwritePrompt = copyPage.clickCopyButtonExpectingOverwritePrompt();
    // Click change target
    copyOverwritePrompt.clickChangeTargetButton();
    copyPage = new CopyPage();
    // Check the source document
    Assert.assertEquals(Arrays.asList("", sourceSpaceName, sourcePageName), copyPage.getSourceLocation().getPath());
    Assert.assertEquals(sourceSpaceName, copyPage.getSourceSpaceName());
    Assert.assertEquals(sourcePageName, copyPage.getSourcePageName());
    // Check the default target document.
    documentPicker = copyPage.getDocumentPicker();
    Assert.assertEquals(sourcePageName, documentPicker.getTitle());
    Assert.assertEquals(Arrays.asList("", sourceSpaceName, sourcePageName), documentPicker.getLocation().getPath());
    Assert.assertEquals(sourceSpaceName, copyPage.getTargetSpaceName());
    Assert.assertEquals(sourcePageName, copyPage.getTargetPageName());
    // Fill the target destination the page to be copied to.
    documentPicker.setTitle("My copy").toggleLocationAdvancedEdit().setParent(targetSpaceName).setName(targetPageName);
    // Copy and confirm overwrite
    copyOverwritePrompt = copyPage.clickCopyButtonExpectingOverwritePrompt();
    CopyOrRenameStatusPage copyStatusPage = copyOverwritePrompt.clickCopyButton().waitUntilFinished();
    // Check successful copy confirmation
    Assert.assertEquals(COPY_SUCCESSFUL, copyStatusPage.getInfoMessage());
    viewPage = copyStatusPage.gotoNewPage();
    // Verify that the title of the copy has been updated (independent from the name of the copy).
    Assert.assertEquals("My copy", viewPage.getDocumentTitle());
    Assert.assertEquals(PAGE_CONTENT, viewPage.getContent());
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) CopyOrRenameStatusPage(org.xwiki.test.ui.po.CopyOrRenameStatusPage) CopyPage(org.xwiki.index.test.po.CopyPage) DocumentPickerModal(org.xwiki.index.tree.test.po.DocumentPickerModal) CopyOverwritePromptPage(org.xwiki.test.ui.po.CopyOverwritePromptPage) ViewPage(org.xwiki.test.ui.po.ViewPage) DocumentPicker(org.xwiki.test.ui.po.DocumentPicker) Test(org.junit.Test) IgnoreBrowser(org.xwiki.test.ui.browser.IgnoreBrowser)

Example 19 with LocalDocumentReference

use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.

the class XarPackage method readDescriptorFiles.

private void readDescriptorFiles(Element files) {
    NodeList children = files.getChildNodes();
    for (int i = 0; i < children.getLength(); ++i) {
        Node node = children.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            Element element = (Element) node;
            if (element.getTagName().equals(XarModel.ELEMENT_FILES_FILE)) {
                String localeString = element.getAttribute(XarModel.ATTRIBUTE_LOCALE);
                String defaultActionString = element.getAttribute(XarModel.ATTRIBUTE_DEFAULTACTION);
                String referenceString = element.getTextContent();
                // Parse reference
                LocalDocumentReference reference = new LocalDocumentReference(XarUtils.RESOLVER.resolve(referenceString, EntityType.DOCUMENT), LocaleUtils.toLocale(localeString));
                // Parse default action
                int defaultAction = Integer.valueOf(defaultActionString);
                // Get entry name associated to the document
                String entryName = getEntryName(reference);
                // Create entry
                XarEntry packageFile = new XarEntry(reference, entryName, defaultAction);
                // Register package file entry
                this.packageFiles.put(packageFile, packageFile);
                // Update existing entry default action
                updateEntryDefaultAction(packageFile);
            }
        }
    }
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element)

Example 20 with LocalDocumentReference

use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.

the class AdministrationTest method testCodeToExecutionAndAutoSandboxing.

/*
     * If CodeToExecute is defined in a configurable app, then it should be evaluated.
     * Also header should be evaluated and not just printed.
     * If XWiki.ConfigurableClass is saved with programming rights, it should resave itself so that it doesn't have them.
     */
@Test
public void testCodeToExecutionAndAutoSandboxing() throws Exception {
    String space = "Main";
    String page = "TestConfigurable";
    String codeToExecute = "#set($code = 's sh')" + "Thi${code}ould be displayed." + "#if($xcontext.hasProgrammingRights())" + "This should not be displayed." + "#end";
    String heading = "#set($code = 'his sho')" + "T${code}uld also be displayed.";
    createConfigurableApplication(space, page, "TestSection6", true);
    open(space, page, "edit", "editor=object");
    expandObject("XWiki.ConfigurableClass", 0);
    setFieldValue("XWiki.ConfigurableClass_0_codeToExecute", codeToExecute);
    setFieldValue("XWiki.ConfigurableClass_0_heading", heading);
    setFieldValue("XWiki.ConfigurableClass_0_configurationClass", "");
    clickEditSaveAndView();
    Page restPage = getUtil().rest().get(new LocalDocumentReference("XWiki", "ConfigurableClass"));
    String standardContent = restPage.getContent();
    try {
        // Modify content
        restPage.setContent(standardContent + "\n\n{{velocity}}Has Programming permission: $xcontext.hasProgrammingRights(){{/velocity}}");
        // Our admin will foolishly save XWiki.ConfigurableClass, giving it programming rights.
        getUtil().setDefaultCredentials(TestUtils.ADMIN_CREDENTIALS);
        getUtil().rest().save(restPage);
        // Now we look at the section for our configurable.
        open("XWiki", "ConfigurableClass", "view", "editor=globaladmin&section=TestSection6");
        assertTextPresent("This should be displayed.");
        assertTextPresent("This should also be displayed.");
        assertTextNotPresent("This should not be displayed.");
        assertTextPresent("Has Programming permission: false");
        // Make sure javascript has not added a Save button.
        assertElementNotPresent("//div/div/p/span/input[@type='submit'][@value='Save']");
    } finally {
        // Restore initial content
        restPage.setContent(standardContent);
        // Save
        getUtil().rest().save(restPage);
    }
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) Page(org.xwiki.rest.model.jaxb.Page) Test(org.junit.Test)

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