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

File RenamePageTest.java

 

Code metrics

0
35
2
1
115
60
2
0.06
17.5
2
1

Classes

Class Line # Actions
RenamePageTest 34 35 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   
21    package org.xwiki.flamingo.test.ui;
22   
23    import static org.junit.Assert.*;
24   
25    import org.junit.Rule;
26    import java.util.Arrays;
27    import org.junit.Test;
28    import org.xwiki.test.ui.AbstractTest;
29    import org.xwiki.test.ui.SuperAdminAuthenticationRule;
30    import org.xwiki.test.ui.po.CopyOrRenameStatusPage;
31    import org.xwiki.test.ui.po.RenamePage;
32    import org.xwiki.test.ui.po.ViewPage;
33   
 
34    public class RenamePageTest extends AbstractTest
35    {
36    @Rule
37    public SuperAdminAuthenticationRule authenticationRule = new SuperAdminAuthenticationRule(getUtil());
38   
39    private static final String RENAME_SUCCESSFUL = "Done.";
40   
41    // Convert a nested page to a terminal page
 
42  1 toggle @Test
43    public void convertNestedPageToTerminalPage() throws Exception
44    {
45    // Clean-up: delete the pages that will be used in this test
46  1 getUtil().rest().deletePage("1", "2");
47  1 getUtil().rest().delete(getUtil().resolveDocumentReference("1.2.WebHome"));
48   
49    // Create 1.2.WebHome
50  1 getUtil().createPage(Arrays.asList("1", "2"), "WebHome", "", "");
51   
52    // Go to 1.2.WebHome to start the test
53  1 getUtil().gotoPage(Arrays.asList("1", "2"), "WebHome", "", "");
54   
55  1 ViewPage vp = new ViewPage();
56   
57    // Go to the Rename page view for 1.2.WebHome and check the Terminal checkbox. We also need to uncheck the Auto
58    // Redirect checkbox so the page 1.2.WebHome will not appear as existing after the Rename operation.
59  1 RenamePage renamePage = vp.rename();
60  1 renamePage.setTerminal(true);
61  1 renamePage.setAutoRedirect(false);
62  1 renamePage.clickRenameButton().waitUntilFinished();
63   
64    // Test if 1.2.WebHome has been renamed to 1.2 (1.2.WebHome doesn't exist while 1.2 exists)
65  1 assertTrue("Page 1.2 doesn't exist!", getUtil().pageExists(Arrays.asList("1"), "2"));
66  1 assertFalse("Page 1.2.WebHome exists!", getUtil().pageExists(Arrays.asList("1", "2"), "WebHome"));
67    }
68   
69    // Rename a page with children, update the backlinks and test the Auto Redirect feature
 
70  1 toggle @Test
71    public void renamePageCheckConfirmationPreserveChildrenUpdateLinksSetAutoRedirect() throws Exception
72    {
73    // Clean-up: delete the pages that will be used in this test
74  1 getUtil().rest().deletePage("My", "Page");
75  1 getUtil().rest().delete(getUtil().resolveDocumentReference("1.2.WebHome"));
76  1 getUtil().rest().delete(getUtil().resolveDocumentReference("1.2.3.WebHome"));
77  1 getUtil().rest().delete(getUtil().resolveDocumentReference("A.B.2.WebHome"));
78  1 getUtil().rest().delete(getUtil().resolveDocumentReference("A.B.2.3.WebHome"));
79   
80    // Create the needed pages
81  1 getUtil().createPage(Arrays.asList("1", "2"), "WebHome", "", "");
82  1 getUtil().createPage(Arrays.asList("1", "2", "3"), "WebHome", "", "");
83    // We set the content to "[[1.2.WebHome]]" to test the "Update Links" feature
84  1 getUtil().createPage("My", "Page", "[[1.2.WebHome]]", "");
85   
86    // Go to 1.2.WebHome to start the test
87  1 getUtil().gotoPage(Arrays.asList("1", "2"), "WebHome", "", "");
88   
89  1 ViewPage vp = new ViewPage();
90   
91    // Go to the Rename page view for 1.2.WebHome.
92  1 RenamePage renamePage = vp.rename();
93    // Check the "Preserve Children", "Update Links" & "Auto Redirect" checkboxes.
94  1 renamePage.setPreserveChildren(true);
95  1 renamePage.setUpdateLinks(true);
96  1 renamePage.setAutoRedirect(true);
97    // Set the new parent as "A.B"
98  1 renamePage.getDocumentPicker().setParent("A.B");
99  1 CopyOrRenameStatusPage renameStatusPage = renamePage.clickRenameButton().waitUntilFinished();
100   
101    // Check successful Rename confirmation
102  1 assertEquals(RENAME_SUCCESSFUL, renameStatusPage.getInfoMessage());
103    // Test the Rename operation: we need to have 2.WebHome and 2.3.WebHome under A.B
104  1 assertTrue("Page A.B.2.WebHome doesn't exist!", getUtil().pageExists(Arrays.asList("A", "B", "2"), "WebHome"));
105  1 assertTrue("Page A.B.2.3.WebHome doesn't exist!",
106    getUtil().pageExists(Arrays.asList("A", "B", "2", "3"), "WebHome"));
107    // Test the Auto Redirect: when visiting the original pages you need to be redirected to the new locations
108  1 getUtil().gotoPage(Arrays.asList("1", "2"), "WebHome", "view", "");
109  1 assertEquals("/A/B/2", vp.getBreadcrumbContent());
110  1 getUtil().gotoPage(Arrays.asList("1", "2", "3"), "WebHome", "view", "");
111  1 assertEquals("/A/B/2/3", vp.getBreadcrumbContent());
112    // Test the Update Links feature: the content of the page needs to point to the new location
113  1 assertEquals("[[A.B.2.WebHome]]", getUtil().gotoPage("My", "Page").editWiki().getContent());
114    }
115    }