1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.flamingo.test.ui

File CreatePageAndSpaceTest.java

 

Code metrics

0
55
2
1
165
78
2
0.04
27.5
2
1

Classes

Class Line # Actions
CreatePageAndSpaceTest 38 55 0% 2 0
1.0100%
 

Contributing tests

This file is covered by 2 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.flamingo.test.ui;
21   
22    import org.junit.Rule;
23    import org.junit.Test;
24    import org.xwiki.test.ui.AbstractTest;
25    import org.xwiki.test.ui.SuperAdminAuthenticationRule;
26    import org.xwiki.test.ui.po.CreatePagePage;
27    import org.xwiki.test.ui.po.ViewPage;
28    import org.xwiki.test.ui.po.editor.EditPage;
29   
30    import static org.junit.Assert.assertEquals;
31   
32    /**
33    * Tests basic page and space creation.
34    *
35    * @version $Id: 2e1ae47dc0a0e205ebd4b23af5afab470bac554c $
36    * @since 7.2M2
37    */
 
38    public class CreatePageAndSpaceTest extends AbstractTest
39    {
40    @Rule
41    public SuperAdminAuthenticationRule authenticationRule = new SuperAdminAuthenticationRule(getUtil());
42   
 
43  1 toggle @Test
44    public void createSpaceAndPage()
45    {
46    // Test 1: Test Space creation when on an existing page (i.e. the space creation UI will open to ask for the
47    // space name.
48   
49    // Clean up before the test starts
50    // Note that we introduce a special character to verify we support non-ASCII characters in page and space names
51  1 String existingPageName = getTestMethodName() + "\u0219";
52  1 String spaceName = getTestClassName() + "\u0219";
53  1 getUtil().deleteSpace(spaceName);
54  1 getUtil().deletePage(spaceName, existingPageName);
55   
56    // Create the page that's supposed to exist.
57  1 getUtil().createPage(spaceName, existingPageName, "Dummy", "Dummy Title");
58   
59    // Since the Flamingo skin no longer supports creating a space from the UI, trigger the Space creation UI
60    // by using directly the direct action URL for it.
61  1 getUtil().gotoPage(getUtil().getURL("create", new String[] {spaceName, existingPageName}, "tocreate=space"));
62  1 CreatePagePage cpp = new CreatePagePage();
63  1 EditPage editSpaceWebhomePage = cpp.createPage("", spaceName);
64   
65  1 assertEquals(spaceName, editSpaceWebhomePage.getMetaDataValue("space"));
66  1 assertEquals("WebHome", editSpaceWebhomePage.getMetaDataValue("page"));
67    // The parent is the current document from where the space was created.
68  1 assertEquals(spaceName + "." + existingPageName, editSpaceWebhomePage.getParent());
69    // and the title the name of the space
70  1 assertEquals(spaceName, editSpaceWebhomePage.getDocumentTitle());
71   
72    // Test 2: Test Space creation when on an non-existing page (i.e. the create action will lead to editing the
73    // current document - No space name will be asked).
74   
75    // Since the Flamingo skin no longer supports creating a space from the UI, trigger the Space creation UI
76    // by using directly the direct action URL for it. This time on a non-exsiting page.
77  1 getUtil().gotoPage(getUtil().getURL("create", new String[]{ spaceName, "NonExistingPage" },
78    "tocreate=space&type=blank"));
79  1 EditPage editPage = new EditPage();
80   
81  1 assertEquals(spaceName, editPage.getMetaDataValue("space"));
82  1 assertEquals("NonExistingPage", editPage.getMetaDataValue("page"));
83    // The default parent is the home page of the current wiki (XWIKI-7572).
84  1 assertEquals("Main.WebHome", editPage.getParent());
85    // and the title the name of the space
86  1 assertEquals("NonExistingPage", editPage.getDocumentTitle());
87   
88    // Test 3: Test Terminal Page creation when on an existing page (i.e. the space creation UI will open to ask
89    // for the space + page names.
90   
91    // Note that we introduce a special character to verify we support non-ASCII characters in page names
92  1 String newPageName = getTestMethodName() + "2" + "\u0219";
93  1 getUtil().deletePage(spaceName, newPageName);
94   
95    // Navigate to an existing page before clicking on the Add button
96  1 ViewPage vp = getUtil().gotoPage(spaceName, existingPageName);
97  1 cpp = vp.createPage();
98  1 editPage = cpp.createPage(spaceName, newPageName, true);
99   
100    // Verify the title field
101  1 assertEquals(newPageName, editPage.getDocumentTitle());
102    // Verify the document name in the metadata
103  1 assertEquals(newPageName, editPage.getMetaDataValue("page"));
104    // Save the page to verify it can be saved with a non-ascii name
105  1 ViewPage savedPage = editPage.clickSaveAndView();
106  1 assertEquals(newPageName, savedPage.getMetaDataValue("page"));
107    }
108   
109    /**
110    * Test that the inputs in the create UI are updated, depending on the case.
111    */
 
112  1 toggle @Test
113    public void testCreateUIInteraction()
114    {
115    // Cleanup of the test space for any leftovers from previous tests.
116  1 getUtil().deleteSpace(getTestClassName());
117   
118    // Create an existent page that will also be the parent of our documents.
119  1 String existingPageTitle = "Test Area";
120  1 getUtil().createPage(getTestClassName(), "WebHome", "", existingPageTitle);
121   
122  1 CreatePagePage createPage = new ViewPage().createPage();
123    // Check that by default we have an empty title and name and the parent is the current document's space.
124  1 assertEquals("", createPage.getDocumentPicker().getTitle());
125  1 assertEquals("", createPage.getDocumentPicker().getName());
126  1 assertEquals(getTestClassName(), createPage.getDocumentPicker().getParent());
127    // Check the initial state of the breadcrumb.
128  1 createPage.waitForLocationPreviewContent("/" + existingPageTitle + "/");
129   
130    // Set a new title and check that the page name and the breadcrumb are also updated.
131  1 String newTitle = "New Title";
132  1 createPage.getDocumentPicker().setTitle(newTitle);
133  1 assertEquals(newTitle, createPage.getDocumentPicker().getName());
134  1 createPage.waitForLocationPreviewContent("/" + existingPageTitle + "/" + newTitle);
135   
136    // Set a new page name and check that the breadcrumb is not updated, since we have a title specified.
137  1 String newName = "SomeNewName";
138  1 createPage.getDocumentPicker().setName(newName);
139  1 createPage.waitForLocationPreviewContent("/" + existingPageTitle + "/" + newTitle);
140   
141    // Clear the title, set a page name and check that the breadcrumb now uses the page name as a fallback.
142  1 createPage.getDocumentPicker().setTitle("");
143  1 assertEquals("", createPage.getDocumentPicker().getName());
144  1 createPage.getDocumentPicker().setName(newName);
145  1 createPage.waitForLocationPreviewContent("/" + existingPageTitle + "/" + newName);
146   
147    // Set a new parent space and check that the breadcrumb is updated.
148    // Before that, reset the title, just for completeness.
149  1 createPage.getDocumentPicker().setTitle(newTitle);
150  1 String newSpace = "SomeNewSpace";
151  1 createPage.getDocumentPicker().setParent(newSpace);
152  1 createPage.waitForLocationPreviewContent("/" + newSpace + "/" + newTitle);
153   
154    // Set a new parent in nested spaces and check that the breadcrumb is updated.
155  1 String newSpaceLevel2 = "Level2";
156  1 createPage.getDocumentPicker().setParent(newSpace + "." + newSpaceLevel2);
157  1 createPage.waitForLocationPreviewContent("/" + newSpace + "/" + newSpaceLevel2 + "/" + newTitle);
158   
159    // Clear the parent and check that the breadcrumb is updated, since we are creating a top level document.
160  1 createPage.getDocumentPicker().setParent("");
161  1 createPage.waitForLocationPreviewContent("/" + newTitle);
162    }
163   
164    // TODO: Add a test for the input validation.
165    }