Search in sources :

Example 1 with DocumentDoesNotExistPage

use of org.xwiki.test.ui.po.DocumentDoesNotExistPage in project xwiki-platform by xwiki.

the class CreatePageIT method createPagesFromTemplate.

/**
 * Tests if a new page can be created from a template.
 */
@Test
@IgnoreBrowsers({ @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason = "See https://jira.xwiki.org/browse/XE-1146"), @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason = "See https://jira.xwiki.org/browse/XE-1177") })
public void createPagesFromTemplate() throws Exception {
    // Step 0: Setup the correct environment for the test
    // All these pages are created during this test
    getUtil().deleteSpace(getTestClassName());
    getUtil().rest().deletePage(getTestClassName(), getTestMethodName());
    EntityReference templateInstanceReference = getUtil().resolveDocumentReference(getTestClassName() + "." + TEMPLATE_NAME + "Instance" + ".WebHome");
    getUtil().rest().delete(templateInstanceReference);
    getUtil().rest().deletePage(getTestClassName(), "NewPage");
    getUtil().rest().deletePage(getTestClassName(), TEMPLATE_NAME + "UnexistingInstance");
    getUtil().rest().deletePage(getTestClassName(), "EmptyPage");
    String templateContent = "Test Template Content";
    String templateTitle = "Test Template Title";
    String templateProviderName = TEMPLATE_NAME + "Provider";
    String templateProviderFullName = getTestClassName() + "." + templateProviderName;
    // Step 1: Create a Template and a Template Provider and try to create a new page by using the Add Menu and
    // using the created Template
    ViewPage templateProviderView = createTemplateAndTemplateProvider(templateProviderName, templateContent, templateTitle, false);
    // Create the new document from template
    CreatePagePage createPagePage = templateProviderView.createPage();
    // Save the number of available templates so that we can make some checks later on.
    int availableTemplateSize = createPagePage.getAvailableTemplateSize();
    String templateInstanceName = TEMPLATE_NAME + "Instance";
    createPagePage.getDocumentPicker().toggleLocationAdvancedEdit();
    EditPage templateInstanceEditWysiwyg = createPagePage.createPageFromTemplate(templateInstanceName, getTestClassName(), null, templateProviderFullName);
    WikiEditPage templateInstanceEdit = templateInstanceEditWysiwyg.clickSaveAndView().editWiki();
    // Verify template instance location and content
    assertEquals(templateInstanceName, templateInstanceEdit.getTitle());
    assertEquals(getTestClassName() + "." + templateInstanceName, templateInstanceEdit.getMetaDataValue("space"));
    assertEquals("WebHome", templateInstanceEdit.getMetaDataValue("page"));
    assertEquals(templateContent, templateInstanceEdit.getContent());
    // check the parent of the template instance
    assertEquals(templateProviderFullName, templateInstanceEdit.getParent());
    // Step 2: Create a wanted link and verify that clicking it displays the Template and that we can use it.
    // Put a wanted link in the template instance
    templateInstanceEdit.setContent("[[doc:NewPage]]");
    ViewPage vp = templateInstanceEdit.clickSaveAndView();
    // Verify that clicking on the wanted link pops up a box to choose the template.
    EntityReference wantedLinkReference = getUtil().resolveDocumentReference(getTestClassName() + "." + TEMPLATE_NAME + "Instance" + ".NewPage");
    vp.clickWantedLink(wantedLinkReference, true);
    // TODO: a page object should be better here
    List<WebElement> templates = getDriver().findElements(By.xpath("//input[@name='type' and @data-type='template']"));
    // Note: We need to remove 1 to exclude the "Empty Page" template entry
    assertEquals(availableTemplateSize, templates.size());
    assertTrue(createPagePage.getAvailableTemplates().contains(templateProviderFullName));
    // Step 3: Create a new page when located on a non-existing page
    getUtil().gotoPage(getTestClassName(), TEMPLATE_NAME + "UnexistingInstance", "view", "spaceRedirect=false");
    vp = new ViewPage();
    assertFalse(vp.exists());
    DocumentDoesNotExistPage unexistingPage = new DocumentDoesNotExistPage();
    unexistingPage.clickEditThisPageToCreate();
    CreatePagePage createUnexistingPage = new CreatePagePage();
    // Make sure we're in create mode.
    assertTrue(getUtil().isInCreateMode());
    // count the available templates, make sure they're as many as before and that our template is among them
    assertEquals(availableTemplateSize, createUnexistingPage.getAvailableTemplateSize());
    assertTrue(createUnexistingPage.getAvailableTemplates().contains(templateProviderFullName));
    // select it
    createUnexistingPage.setTemplate(templateProviderFullName);
    createUnexistingPage.setTerminalPage(true);
    // and create
    createUnexistingPage.clickCreate();
    EditPage ep = new EditPage();
    WikiEditPage unexistingPageEdit = ep.clickSaveAndView().editWiki();
    // Verify template instance location and content
    assertEquals(getTestClassName(), templateInstanceEdit.getMetaDataValue("space"));
    assertEquals(TEMPLATE_NAME + "UnexistingInstance", templateInstanceEdit.getMetaDataValue("page"));
    assertEquals(TEMPLATE_NAME + "UnexistingInstance", unexistingPageEdit.getTitle());
    assertEquals(templateContent, unexistingPageEdit.getContent());
    // test that this page has no parent
    assertEquals("Main.WebHome", unexistingPageEdit.getParent());
    // Step 4: Create an empty new page when there are Templates available
    // Make sure we are on a page that exists so that Add > Page will show the space and page fields
    CreatePagePage createEmptyPage = unexistingPageEdit.clickCancel().createPage();
    assertTrue(createEmptyPage.getAvailableTemplateSize() > 0);
    createEmptyPage.getDocumentPicker().toggleLocationAdvancedEdit();
    EditPage editEmptyPage = createEmptyPage.createPage(getTestClassName(), "EmptyPage");
    ViewPage emptyPage = editEmptyPage.clickSaveAndView();
    // make sure it's empty
    assertEquals("", emptyPage.getContent());
    // make sure parent is the right one
    assertEquals("/" + getTestClassName() + "/EmptyPage", emptyPage.getBreadcrumbContent());
    // mare sure title is the right one
    assertEquals("EmptyPage", emptyPage.getDocumentTitle());
    // Step 5: Verify that restricting a Template to a space works
    // Restrict the template to its own space
    templateProviderView = getUtil().gotoPage(getTestClassName(), TEMPLATE_NAME + "Provider");
    templateProviderView.editInline();
    TemplateProviderInlinePage templateProviderInline = new TemplateProviderInlinePage();
    List<String> allowedSpaces = new ArrayList<String>();
    allowedSpaces.add(getTestClassName());
    templateProviderInline.setVisibilityRestrictions(allowedSpaces);
    templateProviderInline.setCreationRestrictions(allowedSpaces);
    templateProviderView = templateProviderInline.clickSaveAndView();
    // Verify we can still create a page from template in the test space
    createPagePage = templateProviderView.createPage();
    // Make sure we get in create mode.
    assertTrue(getUtil().isInCreateMode());
    assertEquals(availableTemplateSize, createPagePage.getAvailableTemplateSize());
    assertTrue(createPagePage.getAvailableTemplates().contains(templateProviderFullName));
    // Modify the target space and verify the form can't be submitted
    createPagePage.setTemplate(templateProviderFullName);
    createPagePage.getDocumentPicker().toggleLocationAdvancedEdit();
    createPagePage.getDocumentPicker().setParent("Foo");
    createPagePage.getDocumentPicker().setName("Bar");
    String currentURL = getDriver().getCurrentUrl();
    createPagePage.clickCreate();
    assertEquals(currentURL, getDriver().getCurrentUrl());
    // and check that an error is displayed to the user
    createPagePage.waitForFieldErrorMessage();
    // Verify the template we have removed is no longer available.
    CreatePagePage.gotoPage();
    // make sure that the template provider is not in the list of templates
    assertFalse(createPagePage.getAvailableTemplates().contains(templateProviderFullName));
}
Also used : CreatePagePage(org.xwiki.test.ui.po.CreatePagePage) ArrayList(java.util.ArrayList) ViewPage(org.xwiki.test.ui.po.ViewPage) WikiEditPage(org.xwiki.test.ui.po.editor.WikiEditPage) EditPage(org.xwiki.test.ui.po.editor.EditPage) WikiEditPage(org.xwiki.test.ui.po.editor.WikiEditPage) WebElement(org.openqa.selenium.WebElement) DocumentDoesNotExistPage(org.xwiki.test.ui.po.DocumentDoesNotExistPage) EntityReference(org.xwiki.model.reference.EntityReference) TemplateProviderInlinePage(org.xwiki.administration.test.po.TemplateProviderInlinePage) IgnoreBrowsers(org.xwiki.test.ui.browser.IgnoreBrowsers) Test(org.junit.Test) AbstractTest(org.xwiki.test.ui.AbstractTest)

Example 2 with DocumentDoesNotExistPage

use of org.xwiki.test.ui.po.DocumentDoesNotExistPage in project xwiki-platform by xwiki.

the class CreatePageNestedDocumentsTest method createNestedDocumentsFromURL.

@Test
public void createNestedDocumentsFromURL() {
    // Create and assert each nested document.
    for (DocumentReference pageReference : nestedDocuments) {
        // Navigate from URL to the page in view mode, using the no-WebHome URL, e.g. /A instead of /A/WebHome
        SpaceReference spaceReference = pageReference.getLastSpaceReference();
        ViewPage viewPage = getUtil().gotoPage(spaceReference);
        // It should not exist and we will create it.
        assertFalse(String.format("Document [%s] already exists", pageReference), viewPage.exists());
        new DocumentDoesNotExistPage().clickEditThisPageToCreate();
        new CreatePagePage().clickCreate();
        EditPage editPage = new EditPage();
        viewPage = editPage.clickSaveAndView();
        // Check that we created the right page
        assertCreatedNestedDocument(pageReference, viewPage);
    }
}
Also used : DocumentDoesNotExistPage(org.xwiki.test.ui.po.DocumentDoesNotExistPage) SpaceReference(org.xwiki.model.reference.SpaceReference) CreatePagePage(org.xwiki.test.ui.po.CreatePagePage) ViewPage(org.xwiki.test.ui.po.ViewPage) EditPage(org.xwiki.test.ui.po.editor.EditPage) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test) AbstractTest(org.xwiki.test.ui.AbstractTest)

Aggregations

Test (org.junit.Test)2 AbstractTest (org.xwiki.test.ui.AbstractTest)2 CreatePagePage (org.xwiki.test.ui.po.CreatePagePage)2 DocumentDoesNotExistPage (org.xwiki.test.ui.po.DocumentDoesNotExistPage)2 ViewPage (org.xwiki.test.ui.po.ViewPage)2 EditPage (org.xwiki.test.ui.po.editor.EditPage)2 ArrayList (java.util.ArrayList)1 WebElement (org.openqa.selenium.WebElement)1 TemplateProviderInlinePage (org.xwiki.administration.test.po.TemplateProviderInlinePage)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 EntityReference (org.xwiki.model.reference.EntityReference)1 SpaceReference (org.xwiki.model.reference.SpaceReference)1 IgnoreBrowsers (org.xwiki.test.ui.browser.IgnoreBrowsers)1 WikiEditPage (org.xwiki.test.ui.po.editor.WikiEditPage)1