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

File DeletePageTest.java

 

Code metrics

6
79
8
1
259
154
11
0.14
9.88
8
1.38

Classes

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