Search in sources :

Example 1 with EditPage

use of org.xwiki.test.ui.po.editor.EditPage 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 EditPage

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

the class CreatePageIT method createPageWithSaveAndEditTemplate.

/**
 * Tests the creation of a page from a save and edit template, tests that the page is indeed saved.
 */
@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 createPageWithSaveAndEditTemplate() throws Exception {
    // Cleanup of the test space for any leftovers from previous tests.
    getUtil().deleteSpace(getTestClassName());
    // Create a template
    String templateProviderName = TEMPLATE_NAME + "Provider";
    String templateContent = "Templates are fun";
    String templateTitle = "Funny templates";
    String templateProviderFullName = getTestClassName() + "." + templateProviderName;
    ViewPage templatePage = createTemplateAndTemplateProvider(templateProviderName, templateContent, templateTitle, true);
    // create the page
    CreatePagePage createPage = templatePage.createPage();
    createPage.getDocumentPicker().toggleLocationAdvancedEdit();
    EditPage editCreatedPage = createPage.createPageFromTemplate(getTestClassName(), "NewPage", templateProviderFullName);
    // and now cancel it
    ViewPage newPage = editCreatedPage.clickCancel();
    // make sure we're not in unexisting page
    assertTrue(newPage.exists());
    // we should be in view mode (useless check since the impl of isNonExisting page calls it anyway)
    assertTrue(getUtil().isInViewMode());
    // make sure it's the page we want
    assertEquals(getTestClassName() + ".NewPage", newPage.getMetaDataValue("space"));
    assertEquals("WebHome", newPage.getMetaDataValue("page"));
    // and now test the title is the name of the page and the content is the one from the template
    assertEquals("NewPage", newPage.getDocumentTitle());
    assertEquals(templateContent, newPage.getContent());
    // and the parent, it should be the template provider, since that's where we created it from
    assertEquals("/" + getTestClassName() + "/NewPage", newPage.getBreadcrumbContent());
}
Also used : CreatePagePage(org.xwiki.test.ui.po.CreatePagePage) ViewPage(org.xwiki.test.ui.po.ViewPage) WikiEditPage(org.xwiki.test.ui.po.editor.WikiEditPage) EditPage(org.xwiki.test.ui.po.editor.EditPage) IgnoreBrowsers(org.xwiki.test.ui.browser.IgnoreBrowsers) Test(org.junit.Test) AbstractTest(org.xwiki.test.ui.AbstractTest)

Example 3 with EditPage

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

the class CreatePageAndSpaceTest method createSpaceAndPage.

@Test
public void createSpaceAndPage() {
    // Test 1:  Test Space creation when on an existing page (i.e. the space creation UI will open to ask for the
    // space name.
    // Clean up before the test starts
    // Note that we introduce a special character to verify we support non-ASCII characters in page and space names
    String existingPageName = getTestMethodName() + "\u0219";
    String spaceName = getTestClassName() + "\u0219";
    getUtil().deleteSpace(spaceName);
    getUtil().deletePage(spaceName, existingPageName);
    // Create the page that's supposed to exist.
    getUtil().createPage(spaceName, existingPageName, "Dummy", "Dummy Title");
    // 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[] { spaceName, existingPageName }, "tocreate=space"));
    CreatePagePage cpp = new CreatePagePage();
    EditPage editSpaceWebhomePage = cpp.createPage("", spaceName);
    assertEquals(spaceName, editSpaceWebhomePage.getMetaDataValue("space"));
    assertEquals("WebHome", editSpaceWebhomePage.getMetaDataValue("page"));
    // The parent is the current document from where the space was created.
    assertEquals(spaceName + "." + existingPageName, editSpaceWebhomePage.getParent());
    // and the title the name of the space
    assertEquals(spaceName, editSpaceWebhomePage.getDocumentTitle());
    // Test 2:  Test Space creation when on an non-existing page (i.e. the create action will lead to editing the
    // current document - No space name will be asked).
    // 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. This time on a non-exsiting page.
    getUtil().gotoPage(getUtil().getURL("create", new String[] { spaceName, "NonExistingPage" }, "tocreate=space&type=blank"));
    EditPage editPage = new EditPage();
    assertEquals(spaceName, editPage.getMetaDataValue("space"));
    assertEquals("NonExistingPage", editPage.getMetaDataValue("page"));
    // The default parent is the home page of the current wiki (XWIKI-7572).
    assertEquals("Main.WebHome", editPage.getParent());
    // and the title the name of the space
    assertEquals("NonExistingPage", editPage.getDocumentTitle());
    // Test 3:  Test Terminal Page creation when on an existing page (i.e. the space creation UI will open to ask
    // for the space + page names.
    // Note that we introduce a special character to verify we support non-ASCII characters in page names
    String newPageName = getTestMethodName() + "2" + "\u0219";
    getUtil().deletePage(spaceName, newPageName);
    // Navigate to an existing page before clicking on the Add button
    ViewPage vp = getUtil().gotoPage(spaceName, existingPageName);
    cpp = vp.createPage();
    editPage = cpp.createPage(spaceName, newPageName, true);
    // Verify the title field
    assertEquals(newPageName, editPage.getDocumentTitle());
    // Verify the document name in the metadata
    assertEquals(newPageName, editPage.getMetaDataValue("page"));
    // Save the page to verify it can be saved with a non-ascii name
    ViewPage savedPage = editPage.clickSaveAndView();
    assertEquals(newPageName, savedPage.getMetaDataValue("page"));
}
Also used : CreatePagePage(org.xwiki.test.ui.po.CreatePagePage) ViewPage(org.xwiki.test.ui.po.ViewPage) EditPage(org.xwiki.test.ui.po.editor.EditPage) AbstractTest(org.xwiki.test.ui.AbstractTest) Test(org.junit.Test)

Example 4 with EditPage

use of org.xwiki.test.ui.po.editor.EditPage 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)

Example 5 with EditPage

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

the class CreatePageNestedDocumentsTest method createNestedDocumentsFromUI.

@Test
public void createNestedDocumentsFromUI() {
    // Create the homepage if it does not exist and start the test from there.
    DocumentReference homepage = new DocumentReference("xwiki", "Main", "WebHome");
    ViewPage viewPage = getUtil().createPage(homepage, "", "Home Page");
    // Create and assert each nested document.
    for (DocumentReference pageReference : nestedDocuments) {
        SpaceReference spaceReference = pageReference.getLastSpaceReference();
        // Click the create button from the previous page.
        CreatePagePage createPage = viewPage.createPage();
        // Determine the values to fill in the form.
        WikiReference wikiReference = spaceReference.getWikiReference();
        EntityReference localParentSpaceReference = spaceReference.removeParent(wikiReference).getParent();
        String spaceReferenceString = getUtil().serializeReference(localParentSpaceReference);
        String pageName = spaceReference.getName();
        // Fill in the form and submit it, using the space name as title.
        EditPage editPage = createPage.createPage(pageName, spaceReferenceString, null, false);
        // Save the page.
        viewPage = editPage.clickSaveAndView();
        // Check that we created the right page
        assertCreatedNestedDocument(pageReference, viewPage);
    }
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) CreatePagePage(org.xwiki.test.ui.po.CreatePagePage) EntityReference(org.xwiki.model.reference.EntityReference) ViewPage(org.xwiki.test.ui.po.ViewPage) WikiReference(org.xwiki.model.reference.WikiReference) 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)6 AbstractTest (org.xwiki.test.ui.AbstractTest)6 ViewPage (org.xwiki.test.ui.po.ViewPage)6 EditPage (org.xwiki.test.ui.po.editor.EditPage)6 CreatePagePage (org.xwiki.test.ui.po.CreatePagePage)5 DocumentReference (org.xwiki.model.reference.DocumentReference)2 EntityReference (org.xwiki.model.reference.EntityReference)2 SpaceReference (org.xwiki.model.reference.SpaceReference)2 IgnoreBrowsers (org.xwiki.test.ui.browser.IgnoreBrowsers)2 DocumentDoesNotExistPage (org.xwiki.test.ui.po.DocumentDoesNotExistPage)2 WikiEditPage (org.xwiki.test.ui.po.editor.WikiEditPage)2 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 WebElement (org.openqa.selenium.WebElement)1 TemplateProviderInlinePage (org.xwiki.administration.test.po.TemplateProviderInlinePage)1 WikiReference (org.xwiki.model.reference.WikiReference)1