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

File CopyPageTest.java

 

Code metrics

0
78
2
1
217
117
2
0.03
39
2
1

Classes

Class Line # Actions
CopyPageTest 43 78 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.test.ui;
21   
22    import java.util.Arrays;
23   
24    import org.junit.Assert;
25    import org.junit.Rule;
26    import org.junit.Test;
27    import org.xwiki.index.test.po.CopyPage;
28    import org.xwiki.index.tree.test.po.DocumentPickerModal;
29    import org.xwiki.model.reference.LocalDocumentReference;
30    import org.xwiki.test.ui.browser.IgnoreBrowser;
31    import org.xwiki.test.ui.po.AttachmentsPane;
32    import org.xwiki.test.ui.po.CopyOrRenameOrDeleteStatusPage;
33    import org.xwiki.test.ui.po.CopyOverwritePromptPage;
34    import org.xwiki.test.ui.po.DocumentPicker;
35    import org.xwiki.test.ui.po.ViewPage;
36   
37    /**
38    * Test the Copy menu action to copy one page to another location.
39    *
40    * @version $Id: 362214fe57c320fc5656b558901d4dabd376715b $
41    * @since 3.0M2
42    */
 
43    public class CopyPageTest extends AbstractTest
44    {
45    @Rule
46    public AdminAuthenticationRule adminAuthenticationRule = new AdminAuthenticationRule(true, getUtil());
47   
48    private static final String PAGE_CONTENT = "This page is used for copying purposes";
49   
50    private static final String OVERWRITTEN_PAGE_CONTENT = "This page is used for overwritten copy purposes";
51   
52    private static final String COPY_SUCCESSFUL = "Done.";
53   
54    private static final String OVERWRITE_PROMPT1 = "Warning: The page ";
55   
56    private static final String OVERWRITE_PROMPT2 =
57    " already exists. Are you sure you want to overwrite it (all its content would be lost)?";
58   
 
59  1 toggle @Test
60    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason = "See https://jira.xwiki.org/browse/XE-1146")
61    public void testCopyPage() throws Exception
62    {
63  1 String sourceSpaceName = getTestClassName();
64  1 String sourcePageName = getTestMethodName();
65  1 String targetSpaceName = getTestClassName() + "Copy";
66  1 String targetPageName = getTestMethodName() + "Copy";
67   
68    // Delete page that may already exist
69  1 getUtil().rest().deletePage(sourceSpaceName, sourcePageName);
70  1 getUtil().rest().deletePage(targetSpaceName, targetPageName);
71   
72    // Create a new page that will be copied.
73  1 ViewPage viewPage = getUtil().createPage(sourceSpaceName, sourcePageName, PAGE_CONTENT, sourcePageName);
74   
75    // Add an attachment to verify that it's version is not incremented in the target document (XWIKI-8157).
76    // FIXME: Remove the following wait when XWIKI-6688 is fixed.
77  1 viewPage.waitForDocExtraPaneActive("comments");
78  1 AttachmentsPane attachmentsPane = viewPage.openAttachmentsDocExtraPane();
79  1 attachmentsPane.setFileToUpload(getClass().getResource("/image.gif").getPath());
80  1 attachmentsPane.waitForUploadToFinish("image.gif");
81  1 Assert.assertEquals("1.1", attachmentsPane.getLatestVersionOfAttachment("image.gif"));
82   
83    // Click on Copy from the Page top menu.
84  1 viewPage.copy();
85  1 CopyPage copyPage = new CopyPage();
86   
87    // Check the source document
88  1 Assert.assertEquals(Arrays.asList("", sourceSpaceName, sourcePageName), copyPage.getSourceLocation().getPath());
89  1 Assert.assertEquals(sourceSpaceName, copyPage.getSourceSpaceName());
90  1 Assert.assertEquals(sourcePageName, copyPage.getSourcePageName());
91   
92    // Check the default target document.
93  1 DocumentPicker documentPicker = copyPage.getDocumentPicker();
94  1 Assert.assertEquals(sourcePageName, documentPicker.getTitle());
95  1 Assert.assertEquals(Arrays.asList("", sourceSpaceName, sourcePageName), documentPicker.getLocation().getPath());
96  1 Assert.assertEquals(sourceSpaceName, copyPage.getTargetSpaceName());
97  1 Assert.assertEquals(sourcePageName, copyPage.getTargetPageName());
98   
99    // Fill the target destination the page to be copied to.
100  1 documentPicker.setTitle(targetPageName);
101    // The target page name is updated based on the entered title.
102  1 Assert.assertEquals(targetPageName, copyPage.getTargetPageName());
103  1 documentPicker.waitForLocation(Arrays.asList("", sourceSpaceName, targetPageName));
104    // Select a new parent document.
105  1 documentPicker.toggleLocationAdvancedEdit().setParent(targetSpaceName);
106  1 documentPicker.waitForLocation(Arrays.asList("", targetSpaceName, targetPageName));
107   
108    // Click copy button
109  1 CopyOrRenameOrDeleteStatusPage copyStatusPage = copyPage.clickCopyButton().waitUntilFinished();
110   
111    // Check successful copy confirmation
112  1 Assert.assertEquals(COPY_SUCCESSFUL, copyStatusPage.getInfoMessage());
113  1 viewPage = copyStatusPage.gotoNewPage();
114   
115  1 Assert.assertEquals(Arrays.asList("", targetSpaceName, targetPageName), viewPage.getBreadcrumb().getPath());
116    // Verify that the copied title is modified to be the new page name since it was set to be the page name
117    // originally.
118  1 Assert.assertEquals(targetPageName, viewPage.getDocumentTitle());
119  1 Assert.assertEquals(PAGE_CONTENT, viewPage.getContent());
120   
121    // Verify the attachment version is the same (XWIKI-8157).
122    // FIXME: Remove the following wait when XWIKI-6688 is fixed.
123  1 viewPage.waitForDocExtraPaneActive("comments");
124  1 attachmentsPane = viewPage.openAttachmentsDocExtraPane();
125  1 Assert.assertEquals("1.1", attachmentsPane.getLatestVersionOfAttachment("image.gif"));
126    }
127   
 
128  1 toggle @Test
129    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason = "See https://jira.xwiki.org/browse/XE-1146")
130    public void testCopyOverwritePage() throws Exception
131    {
132  1 String sourceSpaceName = getTestClassName();
133  1 String sourcePageName = getTestMethodName();
134  1 String targetSpaceName = getTestClassName() + "Copy";
135  1 String targetPageName = getTestMethodName() + "Copy";
136   
137    // Delete page that may already exist
138  1 getUtil().rest().deletePage(sourceSpaceName, sourcePageName);
139  1 getUtil().rest().deletePage(targetSpaceName, targetPageName);
140   
141    // Create a new page that will be overwritten.
142  1 getUtil().rest().savePage(new LocalDocumentReference(targetSpaceName, targetPageName),
143    OVERWRITTEN_PAGE_CONTENT, targetPageName);
144   
145    // Create a new page that will be copied.
146  1 ViewPage viewPage = getUtil().createPage(sourceSpaceName, sourcePageName, PAGE_CONTENT, sourcePageName);
147   
148    // Click on Copy from the Page top menu.
149  1 viewPage.copy();
150  1 CopyPage copyPage = new CopyPage();
151   
152    // Fill the target destination the page to be copied to.
153  1 DocumentPicker documentPicker = copyPage.getDocumentPicker();
154  1 documentPicker.setTitle(targetPageName);
155  1 documentPicker.browseDocuments();
156  1 DocumentPickerModal documentPickerModal = new DocumentPickerModal();
157  1 documentPickerModal.waitForDocumentSelected(sourceSpaceName, "WebHome").selectDocument(targetSpaceName,
158    "WebHome");
159  1 documentPicker.waitForLocation(Arrays.asList("", targetSpaceName, targetPageName));
160  1 Assert.assertEquals(targetSpaceName, copyPage.getTargetSpaceName());
161   
162    // Click copy button
163  1 CopyOverwritePromptPage copyOverwritePrompt = copyPage.clickCopyButtonExpectingOverwritePrompt();
164   
165    // Check overwrite warning
166  1 Assert.assertEquals(OVERWRITE_PROMPT1 + targetSpaceName + '.' + targetPageName + OVERWRITE_PROMPT2,
167    copyOverwritePrompt.getWarningMessage());
168   
169    // Cancel the copy
170  1 viewPage = copyOverwritePrompt.clickCancelButton();
171   
172    // Verify that we have been sent back to the original page
173  1 Assert.assertEquals(sourcePageName, viewPage.getDocumentTitle());
174   
175    // Click on Copy from the Page top menu.
176  1 viewPage.copy();
177  1 copyPage = new CopyPage();
178   
179    // Fill the target destination the page to be copied to.
180  1 copyPage.getDocumentPicker().toggleLocationAdvancedEdit().setParent(targetSpaceName).setName(targetPageName);
181   
182    // Click copy button
183  1 copyOverwritePrompt = copyPage.clickCopyButtonExpectingOverwritePrompt();
184   
185    // Click change target
186  1 copyOverwritePrompt.clickChangeTargetButton();
187  1 copyPage = new CopyPage();
188   
189    // Check the source document
190  1 Assert.assertEquals(Arrays.asList("", sourceSpaceName, sourcePageName), copyPage.getSourceLocation().getPath());
191  1 Assert.assertEquals(sourceSpaceName, copyPage.getSourceSpaceName());
192  1 Assert.assertEquals(sourcePageName, copyPage.getSourcePageName());
193   
194    // Check the default target document.
195  1 documentPicker = copyPage.getDocumentPicker();
196  1 Assert.assertEquals(sourcePageName, documentPicker.getTitle());
197  1 Assert.assertEquals(Arrays.asList("", sourceSpaceName, sourcePageName), documentPicker.getLocation().getPath());
198  1 Assert.assertEquals(sourceSpaceName, copyPage.getTargetSpaceName());
199  1 Assert.assertEquals(sourcePageName, copyPage.getTargetPageName());
200   
201    // Fill the target destination the page to be copied to.
202  1 documentPicker.setTitle("My copy").toggleLocationAdvancedEdit().setParent(targetSpaceName)
203    .setName(targetPageName);
204   
205    // Copy and confirm overwrite
206  1 copyOverwritePrompt = copyPage.clickCopyButtonExpectingOverwritePrompt();
207  1 CopyOrRenameOrDeleteStatusPage copyStatusPage = copyOverwritePrompt.clickCopyButton().waitUntilFinished();
208   
209    // Check successful copy confirmation
210  1 Assert.assertEquals(COPY_SUCCESSFUL, copyStatusPage.getInfoMessage());
211  1 viewPage = copyStatusPage.gotoNewPage();
212   
213    // Verify that the title of the copy has been updated (independent from the name of the copy).
214  1 Assert.assertEquals("My copy", viewPage.getDocumentTitle());
215  1 Assert.assertEquals(PAGE_CONTENT, viewPage.getContent());
216    }
217    }