1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.flamingo.test.ui

File DeletePageTest.java

 

Code metrics

6
75
8
1
258
150
11
0.15
9.38
8
1.38

Classes

Class Line # Actions
DeletePageTest 45 75 0% 11 0
1.0100%
 

Contributing tests

This file is covered by 7 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 java.util.Arrays;
23   
24    import org.junit.Before;
25    import org.junit.Rule;
26    import org.junit.Test;
27    import org.xwiki.model.reference.DocumentReference;
28    import org.xwiki.test.ui.AbstractTest;
29    import org.xwiki.test.ui.SuperAdminAuthenticationRule;
30    import org.xwiki.test.ui.browser.IgnoreBrowser;
31    import org.xwiki.test.ui.po.ConfirmationPage;
32    import org.xwiki.test.ui.po.CopyOrRenameOrDeleteStatusPage;
33    import org.xwiki.test.ui.po.DeletePageOutcomePage;
34    import org.xwiki.test.ui.po.DeletingPage;
35    import org.xwiki.test.ui.po.ViewPage;
36   
37    import static org.junit.Assert.*;
38   
39    /**
40    * Tests the Delete Page feature.
41    *
42    * @version $Id: d6fa81c377b01bfc1eb6d728f698cbe8e61091f7 $
43    * @since 3.0M3
44    */
 
45    public class DeletePageTest extends AbstractTest
46    {
47    @Rule
48    public SuperAdminAuthenticationRule adminAuthenticationRule = new SuperAdminAuthenticationRule(getUtil());
49   
50    private ViewPage viewPage;
51   
52    private static final String LOGGED_USERNAME = "superadmin";
53   
54    private static final String CONFIRMATION = "The page has been deleted.";
55   
56    private static final String DOCUMENT_NOT_FOUND = "The requested page could not be found.";
57   
58    private static final String DELETE_ACTION = "delete";
59   
60    private static final String SPACE_VALUE = "Test";
61   
62    private static final String PAGE_VALUE = "DeletePageTest";
63   
64    private static final String PAGE_CONTENT = "This page is used for testing delete functionality";
65   
66    private static final String PAGE_TITLE = "Page title that will be deleted";
67   
68    private static final String DELETE_SUCCESSFUL = "Done.";
69   
 
70  7 toggle @Before
71    public void setUp() throws Exception
72    {
73    // Create a new Page that will be deleted
74  7 this.viewPage = getUtil().createPage(SPACE_VALUE, PAGE_VALUE, PAGE_CONTENT, PAGE_TITLE);
75    }
76   
 
77  1 toggle @Test
78    public void deleteOkWhenConfirming()
79    {
80  1 ConfirmationPage confirmationPage = this.viewPage.delete();
81    // This tests for regression of XWIKI-1388
82  1 assertNotNull("The interface should not show the user as logged out while deleting page",
83    confirmationPage.getCurrentUser());
84  1 confirmationPage.clickYes();
85  1 DeletingPage deletingPage = new DeletingPage();
86  1 deletingPage.waitUntilFinished();
87    // Note: it's better to wait instead of using isSuccess() since there could be some timeframe between
88    // the hiding of the progress UI and the display of the success message.
89  1 assertEquals(DELETE_SUCCESSFUL, deletingPage.getInfoMessage());
90  1 DeletePageOutcomePage deleteOutcome = deletingPage.getDeletePageOutcomePage();
91  1 assertEquals(LOGGED_USERNAME, deleteOutcome.getPageDeleter());
92  1 assertEquals(DOCUMENT_NOT_FOUND, deleteOutcome.getMessage());
93    }
94   
95    /**
96    * Verify that we can delete a page without showing the confirmation dialog box and that we can redirect to any page
97    * we want when the delete is done.
98    */
 
99  1 toggle @Test
100    public void deletePageCanSkipConfirmationAndDoARedirect()
101    {
102  1 String pageURL = getUtil().getURL(SPACE_VALUE, PAGE_VALUE + "Whatever");
103  1 getUtil().gotoPage(SPACE_VALUE, PAGE_VALUE, DELETE_ACTION, "confirm=1&xredirect=" + pageURL);
104  1 ViewPage vp = new ViewPage();
105    // Since the page PAGE_VALUE + "Whatever" doesn't exist the View Action will redirect to the Nested Document
106    // SPACE_VALUE + "." + PAGE_VALUE + "Whatever + ".WebHome".
107  1 assertEquals(SPACE_VALUE + "." + PAGE_VALUE + "Whatever", vp.getMetaDataValue("space"));
108  1 assertEquals("WebHome", vp.getMetaDataValue("page"));
109    }
110   
111    /**
112    * Verify that we can skip the default delete result page and instead redirect to any page we want.
113    */
 
114  1 toggle @Test
115    public void deletePageCanDoRedirect()
116    {
117    // Set the current page to be any page (doesn't matter if it exists or not)
118  1 String pageURL = getUtil().getURL(SPACE_VALUE, PAGE_VALUE + "Whatever");
119  1 getUtil().gotoPage(SPACE_VALUE, PAGE_VALUE, DELETE_ACTION, "xredirect=" + pageURL);
120  1 ConfirmationPage confirmation = new ConfirmationPage();
121  1 confirmation.clickYes();
122  1 ViewPage vp = new ViewPage();
123    // Since the page PAGE_VALUE + "Whatever" doesn't exist the View Action will redirect to the Nested Document
124    // SPACE_VALUE + "." + PAGE_VALUE + "Whatever + ".WebHome".
125  1 assertEquals(SPACE_VALUE + "." + PAGE_VALUE + "Whatever", vp.getMetaDataValue("space"));
126  1 assertEquals("WebHome", vp.getMetaDataValue("page"));
127    }
128   
129    /**
130    * Verify that hitting cancel on the delete confirmation dialog box goes back to the page being deleted.
131    */
 
132  1 toggle @Test
133    public void deletePageGoesToOriginalPageWhenCancelled()
134    {
135  1 this.viewPage.delete().clickNo();
136  1 assertEquals(getUtil().getURL(SPACE_VALUE, PAGE_VALUE), getDriver().getCurrentUrl());
137    }
138   
 
139  1 toggle @Test
140    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See https://jira.xwiki.org/browse/XE-1177")
141    public void deletePageIsImpossibleWhenNoDeleteRights()
142    {
143    // Logs out to be guest and not have the right to delete
144  1 this.viewPage.logout();
145  1 assertFalse(this.viewPage.canDelete());
146    }
147   
148    /**
149    * Verify that when you delete a terminal and a non terminal page sharing the same location, both deleted versions
150    * are present in the recycle bin list when you hit the location afterwards.
151    * @see: "XWIKI-12563: Cannot restore a terminal page from its location"
152    * @since 7.2RC1
153    */
 
154  1 toggle @Test
155    public void deleteTerminalAndNonTerminalPages()
156    {
157  1 DocumentReference terminalPageRef = new DocumentReference("xwiki",
158    Arrays.asList(getTestClassName()),
159    getTestMethodName());
160   
161  1 DocumentReference nonTerminalPageRef = new DocumentReference("xwiki",
162    Arrays.asList(getTestClassName(), getTestMethodName()),
163    "WebHome");
164   
165    // Clean up.
166  1 getUtil().deletePage(terminalPageRef);
167  1 getUtil().deletePage(nonTerminalPageRef);
168   
169    // Create the non terminal page.
170  1 ViewPage nonTerminalPage = getUtil().createPage(nonTerminalPageRef, "Content", "Title");
171    // Delete it
172  1 nonTerminalPage.delete().clickYes();
173  1 DeletingPage deletingPage = new DeletingPage();
174  1 deletingPage.waitUntilFinished();
175   
176    // Look at the recycle bin
177  1 DeletePageOutcomePage deletePageOutcomePage = deletingPage.getDeletePageOutcomePage();
178  1 assertFalse(deletePageOutcomePage.hasTerminalPagesInRecycleBin());
179   
180    // Create the terminal page.
181  1 ViewPage terminalPage = getUtil().createPage(terminalPageRef, "Content", "Title");
182    // Delete it
183  1 terminalPage.delete().clickYes();
184  1 deletingPage.waitUntilFinished();
185   
186    // Look at the recycle bin
187  1 deletePageOutcomePage = deletingPage.getDeletePageOutcomePage();
188  1 assertTrue(deletePageOutcomePage.hasTerminalPagesInRecycleBin());
189   
190    // Delete both version in the recycle bin
191  1 deletePageOutcomePage.clickDeletePage();
192  1 deletePageOutcomePage.clickDeleteTerminalPage();
193    }
194   
195    /**
196    * Test that when you delete a page and you select "affect children", it delete children properly. It also test
197    * the opposite.
198    *
199    * @since 7.2RC1
200    */
 
201  1 toggle @Test
202    public void deleteChildren()
203    {
204    // Initialize the parent
205  1 DocumentReference parentReference = new DocumentReference("xwiki",
206    Arrays.asList(getTestClassName(), getTestMethodName()),
207    "WebHome");
208  1 ViewPage parentPage = getUtil().createPage(parentReference, "Content", "Parent");
209   
210    // Test 1: Try to delete it to make sure we don't have the "affect children" option yet
211  1 ConfirmationPage confirmationPage = parentPage.delete();
212  1 assertFalse(confirmationPage.hasAffectChildrenOption());
213   
214    // Initialize the children pages
215  1 final int NB_CHILDREN = 3;
216  1 DocumentReference[] childrenReferences = new DocumentReference[NB_CHILDREN];
217  4 for (int i = 0; i < NB_CHILDREN; ++i) {
218  3 childrenReferences[i] = new DocumentReference("xwiki",
219    Arrays.asList(getTestClassName(), getTestMethodName(), "Child_" + (i + 1)),
220    "WebHome");
221  3 getUtil().createPage(childrenReferences[i], "Content", "Child " + (i + 1));
222    }
223   
224    // Test 2: when you don't select "affect children", the children are not deleted
225  1 parentPage = getUtil().gotoPage(parentReference);
226  1 confirmationPage = parentPage.delete();
227  1 assertTrue(confirmationPage.hasAffectChildrenOption());
228  1 confirmationPage.setAffectChildren(false);
229  1 DeletingPage deletingPage = confirmationPage.confirmDeletePage();
230  1 deletingPage.waitUntilFinished();
231  1 assertEquals(DELETE_SUCCESSFUL, deletingPage.getInfoMessage());
232    // Check the page have been effectively removed
233  1 ViewPage page = getUtil().gotoPage(parentReference);
234  1 assertFalse(page.exists());
235    // But not the children
236  4 for (int i = 0; i < NB_CHILDREN; ++i) {
237  3 page = getUtil().gotoPage(childrenReferences[i]);
238  3 assertTrue(page.exists());
239    }
240   
241    // Test 3: when you select "affect children", the children are deleted too
242  1 parentPage = getUtil().createPage(parentReference, "Content", "Parent");
243  1 confirmationPage = parentPage.delete();
244  1 assertTrue(confirmationPage.hasAffectChildrenOption());
245  1 confirmationPage.setAffectChildren(true);
246  1 deletingPage = confirmationPage.confirmDeletePage();
247  1 deletingPage.waitUntilFinished();
248    // Check the page have been effectively removed
249  1 page = getUtil().gotoPage(parentReference);
250  1 assertFalse(page.exists());
251    // And also the children
252  4 for (int i = 0; i < NB_CHILDREN; ++i) {
253  3 page = getUtil().gotoPage(childrenReferences[i]);
254  3 assertFalse(page.exists());
255    }
256   
257    }
258    }