예제 #1
0
  /**
   * Tests what happens when creating a page when no template is available in the specific space.
   */
  @Test
  @IgnoreBrowsers({
    @IgnoreBrowser(
        value = "internet.*",
        version = "8\\.*",
        reason = "See http://jira.xwiki.org/browse/XE-1146"),
    @IgnoreBrowser(
        value = "internet.*",
        version = "9\\.*",
        reason = "See http://jira.xwiki.org/browse/XE-1177")
  })
  public void testCreatePageWhenNoTemplateAvailable() {
    // prepare the test environment, create a test space and exclude all templates for this space
    String space = this.getClass().getSimpleName();
    // create the home page of this space to make sure the space exists
    getUtil()
        .createPage(
            space,
            "WebHome",
            "You can have fun with templates here",
            "Welcome to the templates test space");
    // we'll create all these pages during this test
    getUtil().deletePage(space, "NewUnexistingPage");
    getUtil().deletePage(space, "NewPage");
    getUtil().deletePage(space, "NewLinkedPage");
    // go through all the templates and make sure they are disabled on this space
    TemplatesAdministrationSectionPage sectionPage = TemplatesAdministrationSectionPage.gotoPage();

    // get the links to existing templates, navigate to each of them and disable the current space
    List<String> spacesToExclude = Collections.singletonList(space);
    List<WebElement> existingTemplatesLinks = sectionPage.getExistingTemplatesLinks();
    for (int i = 0; i < existingTemplatesLinks.size(); i++) {
      WebElement link = existingTemplatesLinks.get(i);
      link.click();
      ViewPage templateViewPage = new ViewPage();
      templateViewPage.editInline();
      TemplateProviderInlinePage providerEditPage = new TemplateProviderInlinePage();

      // FIXME: Temporary until we remove the template provider type altogether and make all
      // providers page
      // template providers.
      if (!providerEditPage.isPageTemplate()) {
        providerEditPage.setPageTemplate(true);
      }

      providerEditPage.excludeSpaces(spacesToExclude);
      providerEditPage.clickSaveAndView();

      // go back to the admin page, to leave this in a valid state
      sectionPage = TemplatesAdministrationSectionPage.gotoPage();
      existingTemplatesLinks = sectionPage.getExistingTemplatesLinks();
    }

    // TODO: should reset these template settings at the end of the test, to leave things in the
    // same state as they
    // were at the beginning of the test

    // and now start testing!

    // 1/ create a page from the link in the page displayed when navigating to a non-existing page
    getUtil().gotoPage(space, "NewUnexistingPage", "view", "spaceRedirect=false");
    ViewPage newUnexistentPage = new ViewPage();
    Assert.assertFalse(newUnexistentPage.exists());
    DocumentDoesNotExistPage nonExistingPage = new DocumentDoesNotExistPage();
    nonExistingPage.clickEditThisPageToCreate();
    // make sure we're not in create mode anymore
    Assert.assertFalse(getUtil().isInCreateMode());
    // make sure we're directly in edit mode
    Assert.assertTrue(getUtil().isInWYSIWYGEditMode());
    // TODO: check that we're indeed in the edit mode of space.NewUnexitingPage
    WYSIWYGEditPage editNewUnexistingPage = new WYSIWYGEditPage();
    Assert.assertEquals(space, editNewUnexistingPage.getMetaDataValue("space"));
    Assert.assertEquals("NewUnexistingPage", editNewUnexistingPage.getMetaDataValue("page"));

    // 2/ create a page from the create menu on an existing page, by filling in space and name
    ViewPage spaceHomePage = getUtil().gotoPage(space, "WebHome");
    CreatePagePage createNewPage = spaceHomePage.createPage();
    // we expect no templates available
    Assert.assertEquals(0, createNewPage.getAvailableTemplateSize());
    // fill in data and create the page
    createNewPage.setSpace(space);
    createNewPage.setPage("NewPage");
    createNewPage.setTerminalPage(true);
    createNewPage.clickCreate();
    // we expect to go to the edit mode of the new page
    Assert.assertFalse(getUtil().isInCreateMode());
    Assert.assertTrue(getUtil().isInWYSIWYGEditMode());
    WYSIWYGEditPage editNewPage = new WYSIWYGEditPage();
    editNewPage.waitUntilPageIsLoaded();
    Assert.assertEquals(space, editNewPage.getMetaDataValue("space"));
    Assert.assertEquals("NewPage", editNewPage.getMetaDataValue("page"));

    // 3/ create a page from a link in another page
    WikiEditPage editNewPageWiki = editNewPage.clickSaveAndView().editWiki();
    // put a link to the new page to create
    editNewPageWiki.setContent("[[NewLinkedPage]]");
    ViewPage newPage = editNewPageWiki.clickSaveAndView();
    // no templates are available, so we don't expect a panel with a list of templates, we just
    // expect it goes
    // directly to edit mode of the new page
    // it would be nice to be able to test here that the create page panel is not displayed, ever.
    // However, we can't
    // since we need to wait for that time, and we don't know how much is never.
    newPage.clickWantedLink(space, "NewLinkedPage", false);
    WYSIWYGEditPage editNewLinkedPage = new WYSIWYGEditPage();
    // since the edit mode loads as a result of a redirect that comes from a async call made by the
    // click, we need
    // to wait for the page to load
    getDriver()
        .waitUntilElementIsVisible(
            By.xpath(
                "//div[@id='mainEditArea']//div[@class='gwt-Label' and contains(text(), 'WYSIWYG')]"));
    // make sure we're in edit mode (of the new page)
    Assert.assertTrue(getUtil().isInWYSIWYGEditMode());
    Assert.assertEquals(space, editNewLinkedPage.getMetaDataValue("space"));
    Assert.assertEquals("NewLinkedPage", editNewLinkedPage.getMetaDataValue("page"));
  }
예제 #2
0
  /** Tests that creating a page or a space that already exists displays an error. */
  @Test
  @IgnoreBrowser(
      value = "internet.*",
      version = "8\\.*",
      reason = "See http://jira.xwiki.org/browse/XE-1146")
  public void testCreateExistingPage() {
    String space = this.getClass().getSimpleName();
    // create a template to make sure that we have a template to create from
    String templateProviderName = TEMPLATE_NAME + "Provider";
    String templateContent = "Templates are fun";
    String templateTitle = "Funny templates";
    createTemplate(templateProviderName, templateContent, templateTitle, false);

    // create a page and a space webhome
    String existingPageName = "ExistingPage";
    getUtil().createPage(space, existingPageName, "Page that already exists", "Existing page");
    String existingSpace = this.getClass().getSimpleName() + ((int) (Math.random() * 1000));
    getUtil().createPage(existingSpace, "WebHome", "{{spaceindex /}}", "New random space");

    // 1/ create an empty page that already exists
    HomePage homePage = HomePage.gotoPage();
    CreatePagePage createPage = homePage.createPage();
    createPage.setSpace(space);
    createPage.setPage(existingPageName);
    createPage.setTerminalPage(true);
    String currentURL = getDriver().getCurrentUrl();
    createPage.clickCreate();
    // make sure that we stay on the same page and that an error is displayed to the user. Maybe we
    // should check the
    // error
    Assert.assertEquals(currentURL, getDriver().getCurrentUrl());
    createPage.waitForErrorMessage();

    // 2/ create a page from template that already exists
    // restart everything to make sure it's not the error before
    homePage = HomePage.gotoPage();
    createPage = homePage.createPage();
    createPage.setSpace(space);
    createPage.setPage(existingPageName);
    createPage.setTemplate(space + "." + templateProviderName);
    createPage.setTerminalPage(true);
    currentURL = getDriver().getCurrentUrl();
    createPage.clickCreate();
    // make sure that we stay on the same page and that an error is displayed to the user. Maybe we
    // should check the
    // error
    Assert.assertEquals(currentURL, getDriver().getCurrentUrl());
    createPage.waitForErrorMessage();

    // 3/ create a space that already exists
    homePage = HomePage.gotoPage();
    CreateSpacePage createSpace = homePage.createSpace();
    currentURL = getDriver().getCurrentUrl();
    // strip the parameters out of this URL
    currentURL =
        currentURL.substring(
            0, currentURL.indexOf('?') > 0 ? currentURL.indexOf('?') : currentURL.length());
    createSpace.createSpace(existingSpace);
    String urlAfterSubmit = getDriver().getCurrentUrl();
    urlAfterSubmit =
        urlAfterSubmit.substring(
            0,
            urlAfterSubmit.indexOf('?') > 0
                ? urlAfterSubmit.indexOf('?')
                : urlAfterSubmit.length());
    // make sure that we stay on the same page and that an error is displayed to the user. Maybe we
    // should check the
    // error
    Assert.assertEquals(currentURL, urlAfterSubmit);
    Assert.assertTrue(createSpace.hasError());
  }