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

File LinkTest.java

 

Code metrics

0
1,031
57
1
2,074
1,342
57
0.06
18.09
57
1

Classes

Class Line # Actions
LinkTest 32 1,031 0% 57 0
1.0100%
 

Contributing tests

This file is covered by 50 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.wysiwyg;
21   
22    import java.io.UnsupportedEncodingException;
23    import java.net.URLEncoder;
24   
25    import org.junit.Test;
26    import org.openqa.selenium.By;
27    import org.xwiki.test.wysiwyg.framework.AbstractWysiwygTestCase;
28    import org.xwiki.test.wysiwyg.framework.XWikiExplorer;
29   
30    import static org.junit.Assert.*;
31   
 
32    public class LinkTest extends AbstractWysiwygTestCase
33    {
34    public static final String MENU_LINK = "Link";
35   
36    public static final String MENU_WEB_PAGE = "Web Page...";
37   
38    public static final String MENU_EMAIL_ADDRESS = "Email Address...";
39   
40    public static final String MENU_WIKI_PAGE = "Wiki Page...";
41   
42    public static final String MENU_ATTACHMENT = "Attached File...";
43   
44    public static final String MENU_LINK_EDIT = "Edit Link...";
45   
46    public static final String MENU_LINK_REMOVE = "Remove Link";
47   
48    public static final String BUTTON_SELECT = "Select";
49   
50    public static final String BUTTON_LINK_SETTINGS = "Link Settings";
51   
52    public static final String BUTTON_CREATE_LINK = "Create Link";
53   
54    public static final String CURRENT_PAGE_TAB = "Current page";
55   
56    public static final String ALL_PAGES_TAB = "All pages";
57   
58    public static final String RECENT_PAGES_TAB = "My recent changes";
59   
60    public static final String SEARCH_TAB = "Search";
61   
62    public static final String STEP_EXPLORER = "xExplorerPanel";
63   
64    public static final String LABEL_INPUT_TITLE = "Type the label of the created link.";
65   
66    public static final String ERROR_MSG_CLASS = "xErrorMsg";
67   
68    public static final String ITEMS_LIST = "//div[contains(@class, 'xListBox')]";
69   
70    public static final String TREE_EXPLORER = "//div[contains(@class, 'xExplorer')]";
71   
72    public static final String FILE_UPLOAD_INPUT = "//input[contains(@class, 'gwt-FileUpload')]";
73   
74    public static final String PAGE_LOCATION = "Located in xwiki \u00BB %s \u00BB %s";
75   
76    public static final String NEW_PAGE_FROM_SEARCH_LOCATOR = "//div[contains(@class, 'xPagesSearch')]"
77    + "//div[contains(@class, 'xListItem')]/div[contains(@class, 'xNewPagePreview')]";
78   
79    public static final String NEW_ATTACHMENT = "//div[@class = 'xAttachmentsSelector']"
80    + "//div[contains(@class, \"xListItem\")]" + "/div[contains(@class, \"xNewFilePreview\")]";
81   
82    public static final String NEW_ATTACHMENT_SELECTED = "//div[@class = 'xAttachmentsSelector']"
83    + "//div[contains(@class, \"xListItem-selected\")]" + "/div[contains(@class, \"xNewFilePreview\")]";
84   
85    public static final String ABSOLUTE_DOCUMENT_REFERENCE = "xwiki:%s.%s";
86   
87    public static final String ABSOLUTE_ATTACHMENT_REFERENCE = ABSOLUTE_DOCUMENT_REFERENCE + "@%s";
88   
89    /**
90    * The object used to assert the state of the XWiki Explorer tree.
91    */
92    private XWikiExplorer explorer;
93   
 
94  50 toggle @Override
95    public void setUp()
96    {
97  50 super.setUp();
98   
99  50 this.explorer = new XWikiExplorer(getDriver());
100    }
101   
102    /**
103    * Test the basic feature for adding a link to an existing page.
104    */
 
105  1 toggle @Test
106    public void testCreateLinkToExistingPage()
107    {
108  1 String linkLabel = "x";
109  1 typeText(linkLabel);
110  1 selectNodeContents("document.body.firstChild");
111   
112  1 openLinkDialog(MENU_WIKI_PAGE);
113    // get the all pages tree
114  1 clickTab(ALL_PAGES_TAB);
115  1 waitForStepToLoad(STEP_EXPLORER);
116   
117  1 explorer.waitForIt().findAndSelectPage("News");
118  1 clickButtonWithText(BUTTON_SELECT);
119    // make sure the existing page config parameters are loaded
120  1 waitForStepToLoad("xLinkConfig");
121  1 clickButtonWithText(BUTTON_CREATE_LINK);
122   
123    // wait for the link dialog to close
124  1 waitForDialogToClose();
125   
126  1 switchToSource();
127  1 assertSourceText("[[" + linkLabel + ">>doc:Blog.News]]");
128    }
129   
130    /**
131    * Test the basic feature for adding a link to a new page.
132    */
 
133  1 toggle @Test
134    public void testCreateLinkToNewPage()
135    {
136  1 String linkLabel = "a";
137  1 String newPageName = "AliceInWonderwiki";
138  1 typeText(linkLabel);
139  1 selectNodeContents("document.body.firstChild");
140  1 openLinkDialog(MENU_WIKI_PAGE);
141    // get the all pages tree
142  1 clickTab(ALL_PAGES_TAB);
143  1 waitForStepToLoad(STEP_EXPLORER);
144  1 explorer.waitForIt().findAndSelectPage("Home").selectNewPage("Main");
145  1 clickButtonWithText(BUTTON_SELECT);
146  1 waitForStepToLoad("xLinkToNewPage");
147  1 getSelenium().type("//div[contains(@class, 'xLinkToNewPage')]//input", newPageName);
148  1 clickButtonWithText(BUTTON_LINK_SETTINGS);
149  1 waitForStepToLoad("xLinkConfig");
150  1 clickButtonWithText(BUTTON_CREATE_LINK);
151    // wait for the link dialog to close
152  1 waitForDialogToClose();
153   
154  1 switchToSource();
155  1 assertSourceText("[[" + linkLabel + ">>doc:Main." + newPageName + "]]");
156    }
157   
158    /**
159    * Test the basic feature for adding a link to a new page in a new space.
160    *
161    * @see <a href="http://jira.xwiki.org/jira/browse/XWIKI-3511">XWIKI-3511</a>
162    */
 
163  1 toggle @Test
164    public void testCreateLinkToNewPageInNewSpace()
165    {
166  1 String linkLabel = "b";
167  1 String newSpace = "Bob";
168  1 String newPage = "Cat";
169  1 typeText(linkLabel);
170  1 selectNodeContents("document.body.firstChild");
171  1 openLinkDialog(MENU_WIKI_PAGE);
172    // get the all pages tree
173  1 clickTab(ALL_PAGES_TAB);
174  1 waitForStepToLoad(STEP_EXPLORER);
175  1 explorer.waitForIt().find("document:xwiki:" + newSpace + "." + newPage);
176   
177  1 clickButtonWithText(BUTTON_SELECT);
178  1 waitForStepToLoad("xLinkConfig");
179  1 clickButtonWithText(BUTTON_CREATE_LINK);
180    // wait for the link dialog to close
181  1 waitForDialogToClose();
182   
183  1 switchToSource();
184  1 assertSourceText("[[" + linkLabel + ">>doc:" + newSpace + "." + newPage + "]]");
185    }
186   
187    /**
188    * Test the basic feature for adding a link to a web page.
189    */
 
190  1 toggle @Test
191    public void testCreateLinkToWebPage()
192    {
193  1 String linkLabel = "x";
194  1 String url = "http://www.xwiki.org";
195  1 typeText(linkLabel);
196  1 selectNodeContents("document.body.firstChild");
197   
198  1 openLinkDialog(MENU_WEB_PAGE);
199    // ensure wizard step is loaded
200  1 waitForStepToLoad("xLinkToUrl");
201  1 typeInInput("Web page address", url);
202  1 clickButtonWithText(BUTTON_CREATE_LINK);
203  1 waitForDialogToClose();
204   
205  1 switchToSource();
206  1 assertSourceText("[[" + linkLabel + ">>url:" + url + "]]");
207    }
208   
209    /**
210    * Test adding a link to a web page with a different label than the selected text.
211    */
 
212  1 toggle @Test
213    public void testCreateLinkToWebPageWithChangedLabel()
214    {
215  1 String linkLabel = "x";
216  1 String url = "http://www.xwiki.org";
217  1 typeText(linkLabel);
218  1 selectAllContent();
219  1 openLinkDialog(MENU_WEB_PAGE);
220    // ensure wizard step is loaded
221  1 waitForStepToLoad("xLinkToUrl");
222  1 String newLabel = "xwiki rox";
223  1 typeInInput(LABEL_INPUT_TITLE, newLabel);
224  1 typeInInput("Web page address", url);
225  1 clickButtonWithText(BUTTON_CREATE_LINK);
226  1 waitForDialogToClose();
227   
228  1 switchToSource();
229  1 assertSourceText("[[" + newLabel + ">>url:" + url + "]]");
230    }
231   
232    /**
233    * Test the basic feature for adding a link to an email address.
234    */
 
235  1 toggle @Test
236    public void testCreateLinkToEmailAddress()
237    {
238  1 String linkLabel = "c";
239  1 String email = "carol@xwiki.org";
240  1 typeText(linkLabel);
241  1 selectNodeContents("document.body.firstChild");
242  1 openLinkDialog(MENU_EMAIL_ADDRESS);
243   
244  1 typeInInput("Email address", email);
245  1 clickButtonWithText(BUTTON_CREATE_LINK);
246  1 waitForDialogToClose();
247   
248  1 switchToSource();
249  1 assertSourceText("[[" + linkLabel + ">>mailto:" + email + "]]");
250    }
251   
252    /**
253    * Test adding a link by typing the link label instead of selecting it.
254    */
 
255  1 toggle @Test
256    public void testCreateLinkWithNewLabel()
257    {
258  1 String linkLabel = "xwiki";
259  1 String linkURL = "www.xwiki.org";
260  1 openLinkDialog(MENU_WEB_PAGE);
261   
262  1 typeInInput("Web page address", linkURL);
263  1 typeInInput(LABEL_INPUT_TITLE, linkLabel);
264  1 clickButtonWithText(BUTTON_CREATE_LINK);
265  1 waitForDialogToClose();
266   
267  1 switchToSource();
268  1 assertSourceText("[[" + linkLabel + ">>url:http://" + linkURL + "]]");
269    }
270   
271    /**
272    * Test that anchor label formatting is preserved.
273    */
 
274  1 toggle @Test
275    public void testCreateLinkPreservesLabelFormatting()
276    {
277  1 typeText("1");
278  1 clickBoldButton();
279  1 typeText("2");
280  1 clickBoldButton();
281  1 typeText("3");
282  1 selectAllContent();
283  1 openLinkDialog(MENU_WEB_PAGE);
284   
285    // test that the picked up label of the link is the right text
286  1 assertEquals("123", getInputValue(LABEL_INPUT_TITLE));
287  1 typeInInput("Web page address", "www.xwiki.org");
288  1 clickButtonWithText(BUTTON_CREATE_LINK);
289   
290  1 waitForDialogToClose();
291  1 switchToSource();
292  1 assertSourceText("[[1**2**3>>url:http://www.xwiki.org]]");
293    }
294   
295    /**
296    * Test creating a link with some text around and then editing it. Test that the link type and parameters are
297    * correctly read and that the wiki syntax is correctly generated.
298    */
 
299  1 toggle @Test
300    public void testCreateThenEditLink()
301    {
302    // put everything in a paragraph because editing in body is sometimes parsed wrong
303  1 applyStyleTitle1();
304  1 applyStylePlainText();
305  1 typeText("1");
306  1 String linkLabel = "xwiki";
307  1 String linkURL = "http://www.xwiki.com";
308  1 String newLinkURL = "http://www.xwiki.org";
309   
310  1 openLinkDialog(MENU_WEB_PAGE);
311   
312  1 typeInInput("Web page address", linkURL);
313  1 typeInInput(LABEL_INPUT_TITLE, linkLabel);
314  1 clickButtonWithText(BUTTON_CREATE_LINK);
315  1 waitForDialogToClose();
316   
317  1 moveCaret("document.body.firstChild.childNodes[1].firstChild", 5);
318  1 triggerToolbarUpdate();
319   
320  1 clickMenu(MENU_LINK);
321  1 assertTrue(isMenuEnabled(MENU_LINK_REMOVE));
322    // unlink here should only move the caret out
323  1 clickMenu(MENU_LINK_REMOVE);
324  1 typeText("2");
325  1 switchToSource();
326  1 assertSourceText("1[[" + linkLabel + ">>url:" + linkURL + "]]2");
327  1 switchToWysiwyg();
328   
329  1 select("document.body.firstChild", 1, "document.body.firstChild.childNodes[1].firstChild", 5);
330   
331  1 openLinkDialog(MENU_LINK_EDIT);
332   
333  1 assertEquals(linkLabel, getInputValue(LABEL_INPUT_TITLE));
334  1 assertEquals(linkURL, getInputValue("Web page address"));
335   
336  1 typeInInput("Web page address", newLinkURL);
337  1 clickButtonWithText(BUTTON_CREATE_LINK);
338  1 waitForDialogToClose();
339   
340  1 switchToSource();
341  1 assertSourceText("1[[" + linkLabel + ">>url:" + newLinkURL + "]]2");
342    }
343   
344    /**
345    * Test creating and editing link around an image. Test that the displayed label is the alt text of the image and is
346    * not editable, that the link parameters are correctly read, and that the wiki syntax is correctly generated.
347    */
 
348  1 toggle @Test
349    public void testCreateAndEditLinkOnImage()
350    {
351  1 clickMenu("Image");
352  1 clickMenu("Attached Image...");
353   
354  1 waitForDialogToLoad();
355   
356    // Switch to "All Pages" tab.
357  1 clickTab(ALL_PAGES_TAB);
358   
359  1 String imageSpace = "XWiki";
360  1 waitForCondition("selenium.isElementPresent('" + ImageTest.SPACE_SELECTOR + "/option[@value=\"" + imageSpace
361    + "\"]');");
362  1 getSelenium().select(ImageTest.SPACE_SELECTOR, imageSpace);
363   
364  1 String imagePage = "AdminSheet";
365  1 waitForCondition("selenium.isElementPresent('" + ImageTest.PAGE_SELECTOR + "/option[@value=\"" + imagePage
366    + "\"]');");
367  1 getSelenium().select(ImageTest.PAGE_SELECTOR, imagePage);
368   
369  1 getSelenium().click("//div[@class=\"xPageChooser\"]//button[text()=\"Update\"]");
370   
371  1 String imageSelector = "//div[@class=\"xImagesSelector\"]//img[@title=\"presentation.png\"]";
372  1 waitForCondition("selenium.isElementPresent('" + imageSelector + "');");
373  1 getSelenium().click(imageSelector);
374   
375  1 clickButtonWithText(BUTTON_SELECT);
376  1 waitForStepToLoad("xImageConfig");
377  1 clickButtonWithText("Insert Image");
378   
379  1 waitForDialogToClose();
380   
381    // Now add a link around the image we just inserted.
382  1 openLinkDialog(MENU_WIKI_PAGE);
383    // Select the link target page from the tree.
384  1 clickTab(ALL_PAGES_TAB);
385  1 waitForStepToLoad(STEP_EXPLORER);
386  1 explorer.waitForIt().findAndSelectPage("Sandbox");
387  1 clickButtonWithText(BUTTON_SELECT);
388  1 waitForStepToLoad("xLinkConfig");
389  1 assertEquals("presentation.png", getInputValue(LABEL_INPUT_TITLE));
390    // Check that the link label is read-only.
391  1 assertElementPresent("//input[@title=\"" + LABEL_INPUT_TITLE + "\" and @disabled=\"\"]");
392   
393  1 clickButtonWithText(BUTTON_CREATE_LINK);
394  1 waitForDialogToClose();
395   
396  1 switchToSource();
397  1 assertSourceText("[[[[image:XWiki.AdminSheet@presentation.png]]>>doc:Sandbox.WebHome]]");
398  1 switchToWysiwyg();
399   
400    // Move caret at the end and type some text.
401  1 moveCaret("document.body", 1);
402  1 typeText("x");
403   
404  1 openLinkDialog(MENU_WEB_PAGE);
405  1 typeInInput(LABEL_INPUT_TITLE, "bar");
406  1 typeInInput("Web page address", "http://bar.myxwiki.org");
407  1 clickButtonWithText(BUTTON_CREATE_LINK);
408  1 waitForDialogToClose();
409   
410    // Now go on and edit the inserted image.
411  1 selectNode("document.body.firstChild.firstChild");
412  1 openLinkDialog(MENU_LINK_EDIT);
413   
414    // Check the page selected in the XWiki Explorer tree.
415  1 explorer.waitForPageSelected("Sandbox", "WebHome");
416  1 explorer.findAndSelectPage("Space Index");
417  1 clickButtonWithText(BUTTON_SELECT);
418  1 waitForStepToLoad("xLinkConfig");
419  1 clickButtonWithText(BUTTON_CREATE_LINK);
420  1 waitForDialogToClose();
421   
422  1 switchToSource();
423  1 assertSourceText("[[[[image:XWiki.AdminSheet@presentation.png]]>>doc:Main.SpaceIndex]]x[[bar>>url:http://bar.myxwiki.org]]");
424    }
425   
426    /**
427    * Test that the link existence is detected correctly for a couple of cases of the selection around a link, and that
428    * unlink executes correctly for these situations.
429    */
 
430  1 toggle @Test
431    public void testDetectAndUnlinkSelectedAnchor()
432    {
433  1 switchToSource();
434  1 setSourceText("foo [[bar>>http://xwiki.org]] [[far>>Main.WebHome]] [[alice>>Main.NewPage]] "
435    + "[[carol>>mailto:carol@xwiki.org]] [[b**o**b>>http://xwiki.org]] blog webhome [[Blog.WebHome]] "
436    + "[[image:XWiki.AdminSheet@presentation.png>>Blog.Photos]]");
437  1 switchToWysiwyg();
438   
439    // put selection inside first text
440  1 moveCaret("document.body.firstChild.firstChild", 2);
441  1 clickMenu(MENU_LINK);
442  1 assertFalse(isMenuEnabled(MENU_LINK_REMOVE));
443  1 assertTrue(isMenuEnabled(MENU_WIKI_PAGE));
444  1 assertTrue(isMenuEnabled(MENU_WEB_PAGE));
445  1 assertTrue(isMenuEnabled(MENU_EMAIL_ADDRESS));
446  1 clickMenu(MENU_LINK);
447   
448    // put selection inside the first link
449  1 moveCaret("document.body.firstChild.childNodes[1].firstChild", 2);
450  1 clickMenu(MENU_LINK);
451  1 assertTrue(isMenuEnabled(MENU_LINK_EDIT));
452  1 assertTrue(isMenuEnabled(MENU_LINK_REMOVE));
453    // now unlink it
454  1 clickMenu(MENU_LINK_REMOVE);
455   
456    // put selection around the second link, in the parent
457  1 select("document.body.firstChild", 3, "document.body.firstChild", 4);
458  1 clickMenu(MENU_LINK);
459  1 assertTrue(isMenuEnabled(MENU_LINK_EDIT));
460  1 assertTrue(isMenuEnabled(MENU_LINK_REMOVE));
461    // now unlink it
462  1 clickMenu(MENU_LINK_REMOVE);
463   
464    // put selection with ends at the end of previous text and at the beginning of the next text
465  1 select("document.body.firstChild.childNodes[4]", 1, "document.body.firstChild.childNodes[6]", 0);
466  1 clickMenu(MENU_LINK);
467  1 assertTrue(isMenuEnabled(MENU_LINK_EDIT));
468  1 assertTrue(isMenuEnabled(MENU_LINK_REMOVE));
469    // now unlink it
470  1 clickMenu(MENU_LINK_REMOVE);
471   
472    // put selection with one end inside the anchor and one end at the end of the text before or after
473  1 select("document.body.firstChild.childNodes[6]", 1, "document.body.firstChild.childNodes[7].firstChild", 5);
474  1 clickMenu(MENU_LINK);
475  1 assertTrue(isMenuEnabled(MENU_LINK_EDIT));
476  1 assertTrue(isMenuEnabled(MENU_LINK_REMOVE));
477    // now unlink it
478  1 clickMenu(MENU_LINK_REMOVE);
479   
480    // put selection around the bold text inside a link label
481  1 select("document.body.firstChild.childNodes[9].childNodes[1].firstChild", 0,
482    "document.body.firstChild.childNodes[9].childNodes[1].firstChild", 1);
483  1 clickMenu(MENU_LINK);
484  1 assertTrue(isMenuEnabled(MENU_LINK_EDIT));
485  1 assertTrue(isMenuEnabled(MENU_LINK_REMOVE));
486    // now unlink it
487  1 clickMenu(MENU_LINK_REMOVE);
488   
489    // set selection starting in the text before the link and ending in the link
490  1 select("document.body.firstChild.childNodes[12]", 5,
491    "document.body.firstChild.childNodes[13].firstChild.firstChild", 4);
492  1 clickMenu(MENU_LINK);
493  1 assertFalse(isMenuEnabled(MENU_LINK_EDIT));
494  1 assertFalse(isMenuEnabled(MENU_LINK_REMOVE));
495  1 assertFalse(isMenuEnabled(MENU_WEB_PAGE));
496  1 assertFalse(isMenuEnabled(MENU_EMAIL_ADDRESS));
497  1 assertFalse(isMenuEnabled(MENU_WIKI_PAGE));
498  1 clickMenu(MENU_LINK);
499   
500    // set selection in two different links
501  1 select("document.body.firstChild.childNodes[13].firstChild.firstChild", 4,
502    "document.body.firstChild.childNodes[15]", 1);
503  1 clickMenu(MENU_LINK);
504  1 assertFalse(isMenuEnabled(MENU_LINK_EDIT));
505  1 assertFalse(isMenuEnabled(MENU_LINK_REMOVE));
506  1 assertFalse(isMenuEnabled(MENU_WEB_PAGE));
507  1 assertFalse(isMenuEnabled(MENU_EMAIL_ADDRESS));
508  1 assertFalse(isMenuEnabled(MENU_WIKI_PAGE));
509   
510  1 switchToSource();
511  1 assertSourceText("foo bar far alice carol b**o**b blog webhome [[Blog.WebHome]] "
512    + "[[image:XWiki.AdminSheet@presentation.png>>Blog.Photos]]");
513    }
514   
515    /**
516    * Test editing a link which is the single text in a list item. This case is special because the delete command is
517    * invoked upon replacing the link, which causes clean up of the list.
518    */
 
519  1 toggle @Test
520    public void testEditLinkInList()
521    {
522  1 switchToSource();
523  1 setSourceText("* one\n* [[two>>http://www.xwiki.com]]\n** three");
524  1 switchToWysiwyg();
525   
526    // now edit the link in the second list item
527  1 moveCaret("document.body.firstChild.childNodes[1].firstChild.firstChild", 1);
528   
529  1 openLinkDialog(MENU_LINK_EDIT);
530   
531    // now check if the dialog has loaded correctly
532  1 waitForStepToLoad("xLinkToUrl");
533  1 assertEquals("two", getInputValue(LABEL_INPUT_TITLE));
534  1 assertEquals("http://www.xwiki.com", getInputValue("Web page address"));
535  1 typeInInput("Web page address", "http://www.xwiki.org");
536   
537  1 clickButtonWithText(BUTTON_CREATE_LINK);
538  1 waitForDialogToClose();
539   
540  1 switchToSource();
541  1 assertSourceText("* one\n* [[two>>http://www.xwiki.org]]\n** three");
542    }
543   
544    /**
545    * Test that the link dialogs are correctly validated and alerts are displayed when mandatory fields are not filled
546    * in.
547    */
 
548  1 toggle @Test
549    public void testValidationOnLinkInsert()
550    {
551    // try to create a link to an existing page without a label
552  1 openLinkDialog(MENU_WIKI_PAGE);
553    // get the all pages tree
554  1 clickTab(ALL_PAGES_TAB);
555  1 waitForStepToLoad(STEP_EXPLORER);
556   
557  1 explorer.waitForIt().findAndSelectPage("Home");
558  1 clickButtonWithText(BUTTON_SELECT);
559  1 waitForStepToLoad("xLinkConfig");
560    // try to create link without filling in the label
561  1 clickButtonWithText(BUTTON_CREATE_LINK);
562   
563  1 assertFieldErrorIsPresentInStep("The label of the link cannot be empty", "//input[@title='" + LABEL_INPUT_TITLE
564    + "']", "xLinkConfig");
565   
566    // fill in the label and create link
567  1 typeInInput(LABEL_INPUT_TITLE, "foo");
568  1 clickButtonWithText(BUTTON_CREATE_LINK);
569   
570  1 waitForDialogToClose();
571   
572  1 switchToSource();
573  1 assertSourceText("[[foo>>doc:Main.WebHome]]");
574   
575    // clean up
576  1 setSourceText("");
577  1 switchToWysiwyg();
578   
579    // now try again with a new page link
580  1 openLinkDialog(MENU_WIKI_PAGE);
581    // get the all pages tree
582  1 clickTab(ALL_PAGES_TAB);
583  1 waitForStepToLoad(STEP_EXPLORER);
584   
585  1 explorer.waitForIt().findAndSelectPage("Sandbox Test Page 1");
586  1 clickButtonWithText(BUTTON_SELECT);
587  1 waitForStepToLoad("xLinkConfig");
588  1 clickButtonWithText(BUTTON_CREATE_LINK);
589   
590  1 assertFieldErrorIsPresentInStep("The label of the link cannot be empty", "//input[@title='" + LABEL_INPUT_TITLE
591    + "']", "xLinkConfig");
592   
593    // fill in the label and create link
594  1 typeInInput(LABEL_INPUT_TITLE, "foo");
595  1 clickButtonWithText(BUTTON_CREATE_LINK);
596   
597  1 switchToSource();
598  1 assertSourceText("[[foo>>doc:Sandbox.TestPage1]]");
599   
600    // clean up
601  1 setSourceText("");
602  1 switchToWysiwyg();
603   
604    // now create a link to a web page
605  1 openLinkDialog(MENU_WEB_PAGE);
606   
607    // test that initially 2 errors are displayed
608  1 clickButtonWithText(BUTTON_CREATE_LINK);
609  1 assertFieldErrorIsPresentInStep("The label of the link cannot be empty", "//input[@title='" + LABEL_INPUT_TITLE
610    + "']", "xLinkToUrl");
611  1 assertFieldErrorIsPresentInStep("The web page address was not set", "//input[@title='Web page address']",
612    "xLinkToUrl");
613   
614  1 typeInInput("Web page address", "http://www.xwiki.org");
615  1 clickButtonWithText(BUTTON_CREATE_LINK);
616   
617  1 assertFieldErrorIsPresentInStep("The label of the link cannot be empty", "//input[@title='" + LABEL_INPUT_TITLE
618    + "']", "xLinkToUrl");
619    // now the web page address error is no longer there
620  1 assertFieldErrorIsNotPresent("The web page address was not set", "//input[@title='Web page address']");
621   
622    // fill in the label and create link
623  1 typeInInput(LABEL_INPUT_TITLE, "xwiki");
624  1 clickButtonWithText(BUTTON_CREATE_LINK);
625  1 waitForDialogToClose();
626   
627  1 switchToSource();
628  1 assertSourceText("[[xwiki>>url:http://www.xwiki.org]]");
629   
630    // clean up
631  1 setSourceText("");
632  1 switchToWysiwyg();
633   
634    // now create a link to an email page
635  1 openLinkDialog(MENU_EMAIL_ADDRESS);
636   
637  1 clickButtonWithText(BUTTON_CREATE_LINK);
638   
639  1 assertFieldErrorIsPresentInStep("The label of the link cannot be empty", "//input[@title='" + LABEL_INPUT_TITLE
640    + "']", "xLinkToUrl");
641  1 assertFieldErrorIsPresentInStep("The email address was not set", "//input[@title='Email address']",
642    "xLinkToUrl");
643   
644  1 typeInInput(LABEL_INPUT_TITLE, "alice");
645  1 clickButtonWithText(BUTTON_CREATE_LINK);
646   
647  1 assertFieldErrorIsPresentInStep("The email address was not set", "//input[@title='Email address']",
648    "xLinkToUrl");
649  1 assertFieldErrorIsNotPresent("The label of the link cannot be empty", "//input[@title='" + LABEL_INPUT_TITLE
650    + "']");
651   
652  1 typeInInput("Email address", "alice@wonderla.nd");
653  1 clickButtonWithText(BUTTON_CREATE_LINK);
654   
655  1 waitForDialogToClose();
656   
657  1 switchToSource();
658  1 assertSourceText("[[alice>>mailto:alice@wonderla.nd]]");
659    }
660   
661    /**
662    * Test that the link button is not enabled when the selection contains some block elements.
663    */
 
664  1 toggle @Test
665    public void testCannotCreateLinkAroundBlockElements()
666    {
667  1 setContent("<p>foo</p><p>bar</p>");
668  1 select("document.body.firstChild.firstChild", 2, "document.body.childNodes[1].firstChild", 2);
669  1 clickMenu(MENU_LINK);
670  1 assertFalse(isMenuEnabled(MENU_WEB_PAGE));
671  1 assertFalse(isMenuEnabled(MENU_WIKI_PAGE));
672  1 assertFalse(isMenuEnabled(MENU_EMAIL_ADDRESS));
673  1 assertFalse(isMenuEnabled(MENU_ATTACHMENT));
674  1 assertFalse(isMenuEnabled(MENU_LINK_EDIT));
675  1 assertFalse(isMenuEnabled(MENU_LINK_REMOVE));
676    }
677   
678    /**
679    * Test that the location of the link is preserved if we go back from the configuration step to the page selection
680    * step.
681    */
 
682  1 toggle @Test
683    public void testLinkLocationIsPreservedOnPrevious()
684    {
685  1 String linkLabel = "x";
686  1 typeText(linkLabel);
687  1 selectNodeContents("document.body.firstChild");
688   
689  1 openLinkDialog(MENU_WIKI_PAGE);
690    // get the all pages tree
691  1 clickTab(ALL_PAGES_TAB);
692  1 waitForStepToLoad(STEP_EXPLORER);
693   
694  1 explorer.waitForIt().findAndSelectPage("News");
695  1 clickButtonWithText(BUTTON_SELECT);
696    // make sure the existing page config parameters are loaded
697  1 waitForStepToLoad("xLinkConfig");
698   
699    // now hit previous
700  1 clickButtonWithText("Previous");
701    // wait for tree to load
702  1 waitForStepToLoad("xExplorerPanel");
703    // Make sure the selection in the tree reflects the previously inserted values.
704  1 explorer.waitForPageSelected("Blog", "News");
705   
706    // and now change it
707  1 explorer.findAndSelectPage("Activity Stream");
708  1 clickButtonWithText(BUTTON_SELECT);
709    // make sure the existing page config parameters are loaded
710  1 waitForStepToLoad("xLinkConfig");
711  1 clickButtonWithText(BUTTON_CREATE_LINK);
712   
713    // wait for the link dialog to close
714  1 waitForDialogToClose();
715   
716  1 switchToSource();
717  1 assertSourceText("[[" + linkLabel + ">>doc:Main.Activity]]");
718    }
719   
720    /**
721    * Test the basic feature of adding a link to an attached file with the label from the selected text.
722    */
 
723  1 toggle @Test
724    public void testCreateLinkToAttachment()
725    {
726  1 String linkLabel = "x";
727  1 typeText(linkLabel);
728  1 selectNodeContents("document.body.firstChild");
729   
730  1 openLinkDialog(MENU_ATTACHMENT);
731   
732    // click the tree explorer tab
733  1 clickTab(ALL_PAGES_TAB);
734  1 waitForStepToLoad("xExplorerPanel");
735   
736  1 explorer.waitForIt().findAndSelectAttachment("export.png");
737   
738  1 clickButtonWithText(BUTTON_SELECT);
739    // make sure the existing page config parameters are loaded
740  1 waitForStepToLoad("xLinkConfig");
741  1 clickButtonWithText(BUTTON_CREATE_LINK);
742   
743    // wait for the link dialog to close
744  1 waitForDialogToClose();
745   
746  1 switchToSource();
747  1 assertSourceText("[[" + linkLabel + ">>attach:XWiki.AdminSheet@export.png]]");
748    }
749   
750    /**
751    * @see <a href="http://jira.xwiki.org/browse/XWIKI-8440">XWIKI-8440: Unable to link to an attachment from the
752    * current page in the WYSIWYG Editor using "All Pages" tab</a>
753    */
 
754  1 toggle @Test
755    public void testCreateLinkToAttachmentFromCurrentPage()
756    {
757    // Edit a page that has an attachment.
758  1 open("Sandbox", "WebHome", "edit", "editor=wysiwyg");
759  1 waitForEditorToLoad();
760   
761    // Insert a link to the attached file using the All Pages tab.
762  1 openLinkDialog(MENU_ATTACHMENT);
763  1 clickTab(ALL_PAGES_TAB);
764  1 waitForStepToLoad("xExplorerPanel");
765   
766  1 explorer.waitForIt().findAndSelectAttachment("XWikiLogo.png");
767   
768  1 clickButtonWithText(BUTTON_SELECT);
769  1 waitForStepToLoad("xLinkConfig");
770  1 clickButtonWithText(BUTTON_CREATE_LINK);
771  1 waitForDialogToClose();
772   
773  1 switchToSource();
774  1 assertTrue(getSourceText().startsWith("[[XWikiLogo.png>>attach:XWikiLogo.png"));
775    }
776   
777    /**
778    * @see <a href="http://jira.xwiki.org/browse/XWIKI-8465">Unable to upload a new attachment using the "All pages"
779    * tab in the WYSIWYG editor</a>
780    */
 
781  1 toggle @Test
782    public void testCreateLinkToNewAttachment()
783    {
784    // We have to save the page in order to appear in the tree.
785  1 clickEditSaveAndContinue();
786  1 clickEditPageInWysiwyg();
787  1 waitForEditorToLoad();
788   
789  1 openLinkDialog(MENU_ATTACHMENT);
790  1 clickTab(ALL_PAGES_TAB);
791  1 waitForStepToLoad("xExplorerPanel");
792   
793  1 String spaceName = this.getClass().getSimpleName();
794  1 String pageName = getTestMethodName();
795  1 explorer.waitForAttachmentsSelected(spaceName, pageName).selectNewAttachment(spaceName, pageName);
796   
797  1 clickButtonWithText(BUTTON_SELECT);
798  1 waitForStepToLoad("xUploadPanel");
799    // TODO: Test real file upload.
800    }
801   
802    /**
803    * Test the basic feature of adding a link to an attached file, configuring its parameters in the parameter panel.
804    */
 
805  1 toggle @Test
806    public void testCreateLinkToAttachmentWithParameters()
807    {
808  1 String linkLabel = "XWiki.org Logo";
809  1 String linkTooltip = "Download XWiki's Logo";
810  1 openLinkDialog(MENU_ATTACHMENT);
811   
812    // click the tree explorer tab
813  1 clickTab(ALL_PAGES_TAB);
814  1 waitForStepToLoad("xExplorerPanel");
815   
816  1 explorer.waitForIt().findAndSelectAttachment("XWikiLogo.png");
817   
818  1 clickButtonWithText(BUTTON_SELECT);
819    // make sure the existing page config parameters are loaded
820  1 waitForStepToLoad("xLinkConfig");
821    // fill in the link label and title
822  1 typeInInput(LABEL_INPUT_TITLE, linkLabel);
823  1 typeInInput("Type the tooltip of the created link, which appears when mouse is over the link.", linkTooltip);
824   
825  1 clickButtonWithText(BUTTON_CREATE_LINK);
826   
827    // wait for the link dialog to close
828  1 waitForDialogToClose();
829   
830  1 switchToSource();
831  1 assertSourceText("[[" + linkLabel + ">>attach:Sandbox.WebHome@XWikiLogo.png||title=\"" + linkTooltip + "\"]]");
832    }
833   
834    /**
835    * Test that he creation of a link to an attached file is validated correctly.
836    */
 
837  1 toggle @Test
838    public void testValidationOnLinkToAttachment()
839    {
840  1 String linkLabel = "boo";
841   
842  1 openLinkDialog(MENU_ATTACHMENT);
843   
844    // Select the attachment from a different page.
845  1 clickTab(ALL_PAGES_TAB);
846  1 waitForStepToLoad("xExplorerPanel");
847   
848  1 String attachSpace = "XWiki";
849  1 String attachPage = "AdminSheet";
850  1 String attachment = "users.png";
851   
852    // Get an error from not inserting the attachment name.
853  1 explorer.waitForIt().findAndSelectPage(attachPage);
854   
855  1 clickButtonWithText(BUTTON_SELECT);
856   
857  1 assertFieldErrorIsPresentInStep("No attachment was selected", TREE_EXPLORER, "xExplorerPanel");
858   
859    // Select an attachment.
860  1 explorer.openAttachments(attachSpace, attachPage).selectAttachment(attachSpace, attachPage, attachment);
861   
862    // Move to the next step: link configuration.
863  1 clickButtonWithText(BUTTON_SELECT);
864  1 waitForStepToLoad("xLinkConfig");
865   
866    // The link label should be the attachment name.
867  1 assertEquals(attachment, getInputValue(LABEL_INPUT_TITLE));
868    // Try to create a link with an empty label.
869  1 typeInInput(LABEL_INPUT_TITLE, "");
870  1 clickButtonWithText(BUTTON_CREATE_LINK);
871   
872  1 assertFieldErrorIsPresentInStep("The label of the link cannot be empty", "//input[@title='" + LABEL_INPUT_TITLE
873    + "']", "xLinkConfig");
874   
875  1 typeInInput(LABEL_INPUT_TITLE, linkLabel);
876  1 clickButtonWithText(BUTTON_CREATE_LINK);
877   
878    // Wait for the link dialog to close.
879  1 waitForDialogToClose();
880   
881  1 switchToSource();
882  1 assertSourceText("[[" + linkLabel + ">>attach:" + attachSpace + "." + attachPage + "@" + attachment + "]]");
883    }
884   
885    /**
886    * Test editing an existing link to an attachment
887    */
 
888  1 toggle @Test
889    public void testEditLinkToAttachment()
890    {
891  1 switchToSource();
892  1 setSourceText("[[foobar>>attach:Sandbox.WebHome@XWikiLogo.png]]");
893  1 switchToWysiwyg();
894  1 moveCaret("document.body.firstChild.firstChild.firstChild", 3);
895  1 openLinkDialog(MENU_LINK_EDIT);
896  1 waitForStepToLoad("xExplorerPanel");
897  1 explorer.waitForAttachmentSelected("Sandbox", "WebHome", "XWikiLogo.png");
898  1 explorer.findAndSelectAttachment("export.png");
899  1 clickButtonWithText(BUTTON_SELECT);
900  1 waitForStepToLoad("xLinkConfig");
901  1 clickButtonWithText(BUTTON_CREATE_LINK);
902  1 waitForDialogToClose();
903   
904  1 switchToSource();
905  1 assertSourceText("[[foobar>>attach:XWiki.AdminSheet@export.png]]");
906    }
907   
908    /**
909    * @see XWIKI-7237: mailto is not stripped when editing a link to an e-mail address
910    */
 
911  1 toggle @Test
912    public void testEditLinkToEmailAddress()
913    {
914  1 switchToSource();
915  1 setSourceText("[[test>>mailto:test@xwiki.org]]");
916  1 switchToWysiwyg();
917  1 moveCaret("document.body.firstChild.firstChild.firstChild", 2);
918  1 openLinkDialog(MENU_LINK_EDIT);
919  1 waitForStepToLoad("xLinkToUrl");
920  1 assertEquals("test@xwiki.org", getInputValue("Email address"));
921  1 typeInInput("Email address", "test@gmail.com");
922  1 clickButtonWithText(BUTTON_CREATE_LINK);
923  1 waitForDialogToClose();
924   
925  1 switchToSource();
926  1 assertSourceText("[[test>>mailto:test@gmail.com]]");
927    }
928   
929    /**
930    * Test that editing a link with custom parameters set from wiki syntax preserves the parameters of the link.
931    *
932    * @see <a href="http://jira.xwiki.org/jira/browse/XWIKI-3568">XWIKI-3568</a>
933    */
 
934  1 toggle @Test
935    public void testEditLinkPreservesCustomParameters()
936    {
937  1 switchToSource();
938  1 setSourceText("[[foobar>>Main.Activity||class=\"foobarLink\"]]");
939  1 switchToWysiwyg();
940  1 moveCaret("document.body.firstChild.firstChild.firstChild", 3);
941  1 openLinkDialog(MENU_LINK_EDIT);
942   
943  1 waitForStepToLoad("xExplorerPanel");
944  1 explorer.waitForPageSelected("Main", "Activity");
945  1 clickButtonWithText(BUTTON_SELECT);
946  1 waitForStepToLoad("xLinkConfig");
947  1 typeInInput(LABEL_INPUT_TITLE, "barfoo");
948  1 typeInInput("Type the tooltip of the created link, which appears when mouse is over the link.", "Foo and bar");
949  1 clickButtonWithText(BUTTON_CREATE_LINK);
950  1 waitForDialogToClose();
951   
952  1 switchToSource();
953  1 assertSourceText("[[barfoo>>Main.Activity||class=\"foobarLink\" title=\"Foo and bar\"]]");
954    }
955   
956    /**
957    * Test creating a link to open in a new page.
958    */
 
959  1 toggle @Test
960    public void testCreateLinkToOpenInNewWindow()
961    {
962  1 String linkLabel = "XWiki rox";
963  1 String url = "http://www.xwiki.org";
964   
965  1 openLinkDialog(MENU_WEB_PAGE);
966    // ensure wizard step is loaded
967  1 waitForStepToLoad("xLinkToUrl");
968  1 typeInInput("Web page address", url);
969  1 typeInInput(LABEL_INPUT_TITLE, linkLabel);
970    // open in new window
971  1 getSelenium().check("//div[contains(@class, 'xLinkToUrl')]//span[contains(@class, 'gwt-CheckBox')]/input");
972  1 clickButtonWithText(BUTTON_CREATE_LINK);
973  1 waitForDialogToClose();
974   
975  1 switchToSource();
976  1 assertSourceText("[[" + linkLabel + ">>url:" + url + "||rel=\"__blank\"]]");
977  1 switchToWysiwyg();
978   
979    // now edit
980  1 moveCaret("document.body.firstChild.firstChild", 4);
981  1 openLinkDialog(MENU_LINK_EDIT);
982   
983  1 assertEquals(linkLabel, getInputValue(LABEL_INPUT_TITLE));
984  1 assertEquals(url, getInputValue("Web page address"));
985  1 assertTrue(isChecked("//div[contains(@class, 'xLinkToUrl')]//span[contains(@class, 'gwt-CheckBox')]/input"));
986    }
987   
988    /**
989    * Test that quotes in link tooltips are correctly escaped.
990    *
991    * @see <a href="http://jira.xwiki.org/jira/browse/XWIKI-3569">XWIKI-3569</a>
992    * @see <a href="http://jira.xwiki.org/jira/browse/XWIKI-3569">XWIKI-3575</a>
993    */
 
994  1 toggle @Test
995    public void testQuoteInLinkTooltip()
996    {
997  1 String linkLabel = "x";
998  1 String url = "http://www.xwiki.org";
999  1 String tooltip = "our xwiki \"rox\"";
1000  1 String tooltipTitle = "Type the tooltip of the created link, which appears when mouse is over the link.";
1001  1 typeText(linkLabel);
1002  1 selectNodeContents("document.body.firstChild");
1003  1 openLinkDialog(MENU_WEB_PAGE);
1004    // ensure wizard step is loaded
1005  1 waitForStepToLoad("xLinkToUrl");
1006  1 typeInInput(tooltipTitle, tooltip);
1007  1 typeInInput("Web page address", url);
1008  1 clickButtonWithText(BUTTON_CREATE_LINK);
1009  1 waitForDialogToClose();
1010   
1011  1 switchToSource();
1012  1 assertSourceText("[[" + linkLabel + ">>url:" + url + "||title=\"our xwiki ~\"rox~\"\"]]");
1013  1 switchToWysiwyg();
1014   
1015    // now test the link is correctly parsed back
1016  1 moveCaret("document.body.firstChild.firstChild", 1);
1017  1 openLinkDialog(MENU_LINK_EDIT);
1018  1 waitForStepToLoad("xLinkToUrl");
1019  1 assertEquals(tooltip, getInputValue(tooltipTitle));
1020    }
1021   
1022    /**
1023    * Test that the default selection is set to the current page when opening the wizard to create a link to a wiki
1024    * page.
1025    */
 
1026  1 toggle @Test
1027    public void testDefaultWikipageExplorerSelection()
1028    {
1029    // make sure this page is saved so that the tree can load the reference to it
1030  1 clickEditSaveAndContinue();
1031   
1032  1 String currentSpace = this.getClass().getSimpleName();
1033  1 String currentPage = getTestMethodName();
1034   
1035  1 String newSpace = "XWiki";
1036  1 String newPage = "AdminSheet";
1037    // check the wikipage link dialog
1038  1 openLinkDialog(MENU_WIKI_PAGE);
1039   
1040    // check the recent changes selection
1041  1 waitForStepToLoad("xSelectorAggregatorStep");
1042   
1043    // test that the default open tab is the recent changes tab
1044  1 assertElementPresent("//div[contains(@class, 'gwt-TabBarItem-selected')]/div[.='" + RECENT_PAGES_TAB + "']");
1045   
1046  1 waitForStepToLoad("xPagesSelector");
1047    // Test that the selected element is the edited page.
1048  1 assertElementPresent("//div[contains(@class, 'xPagesRecent')]"
1049    + "//div[contains(@class, 'xListItem-selected')]//div[. = '"
1050    + String.format(PAGE_LOCATION, currentSpace, currentPage) + "']");
1051   
1052    // get the all pages tree
1053  1 clickTab(ALL_PAGES_TAB);
1054  1 waitForStepToLoad(STEP_EXPLORER);
1055   
1056  1 explorer.waitForPageSelected(currentSpace, currentPage).findAndSelectPage(newPage);
1057  1 closeDialog();
1058  1 waitForDialogToClose();
1059   
1060    // now type something and check second display of the dialog, that it stays to the last inserted page
1061  1 typeText("z");
1062  1 openLinkDialog(MENU_WIKI_PAGE);
1063  1 waitForStepToLoad("xExplorerPanel");
1064  1 explorer.waitForPageSelected(newSpace, newPage);
1065  1 closeDialog();
1066  1 waitForDialogToClose();
1067    }
1068   
1069    /**
1070    * Test the creation of a link to a recent page (the current page, saved).
1071    */
 
1072  1 toggle @Test
1073    public void testCreateLinkToRecentPage()
1074    {
1075    // make sure this page is saved so that the recent pages can load reference to it
1076  1 clickEditSaveAndContinue();
1077   
1078  1 openLinkDialog(MENU_WIKI_PAGE);
1079    // The tab with the recently modified pages should be selected.
1080  1 waitForStepToLoad("xSelectorAggregatorStep");
1081  1 waitForStepToLoad("xPagesSelector");
1082    // The currently edited page should be selected.
1083  1 assertElementPresent("//div[contains(@class, 'xPagesRecent')]"
1084    + "//div[contains(@class, 'xListItem-selected')]//div[. = '"
1085    + String.format(PAGE_LOCATION, getClass().getSimpleName(), getTestMethodName()) + "']");
1086  1 clickButtonWithText(BUTTON_SELECT);
1087  1 waitForStepToLoad("xLinkConfig");
1088  1 String label = "barfoo";
1089  1 typeInInput(LABEL_INPUT_TITLE, label);
1090  1 clickButtonWithText(BUTTON_CREATE_LINK);
1091  1 waitForDialogToClose();
1092   
1093  1 switchToSource();
1094  1 assertSourceText("[[" + label + ">>doc:" + getTestMethodName() + "]]");
1095    }
1096   
1097    /**
1098    * Test the creation of a link to a new page in the current space, from the default tab in the link dialog.
1099    */
 
1100  1 toggle @Test
1101    public void testCreateLinkToNewPageInCurrentSpace()
1102    {
1103  1 String newPageName = "NewPage";
1104  1 String label = "new page label";
1105   
1106  1 openLinkDialog(MENU_WIKI_PAGE);
1107   
1108    // check the recent changes selection
1109  1 waitForStepToLoad("xSelectorAggregatorStep");
1110  1 waitForStepToLoad("xPagesSelector");
1111    // test that the selected element is the new page element
1112  1 assertElementPresent("//div[contains(@class, 'xListItem-selected')]/div[contains(@class, 'xNewPagePreview')]");
1113   
1114  1 clickButtonWithText(BUTTON_SELECT);
1115  1 waitForStepToLoad("xLinkToNewPage");
1116  1 getSelenium().type("//div[contains(@class, 'xLinkToNewPage')]//input", newPageName);
1117  1 clickButtonWithText(BUTTON_LINK_SETTINGS);
1118  1 waitForStepToLoad("xLinkConfig");
1119  1 typeInInput(LABEL_INPUT_TITLE, label);
1120  1 clickButtonWithText(BUTTON_CREATE_LINK);
1121  1 waitForDialogToClose();
1122   
1123  1 switchToSource();
1124  1 assertSourceText("[[" + label + ">>doc:" + newPageName + "]]");
1125    }
1126   
1127    /**
1128    * Tests the default selection for the search tab.
1129    */
 
1130  1 toggle @Test
1131    public void testDefaultSearchSelection()
1132    {
1133    // check the wikipage link dialog
1134  1 openLinkDialog(MENU_WIKI_PAGE);
1135   
1136  1 waitForStepToLoad("xSelectorAggregatorStep");
1137  1 clickTab(SEARCH_TAB);
1138  1 waitForStepToLoad("xPagesSearch");
1139    // test that the selected element is the new page element
1140  1 assertElementPresent("//div[contains(@class, 'xListItem-selected')]/div[contains(@class, 'xNewPagePreview')]");
1141   
1142  1 closeDialog();
1143  1 waitForDialogToClose();
1144    }
1145   
1146    /**
1147    * Test adding a link to a page from the search tab.
1148    */
 
1149  1 toggle @Test
1150    public void testCreateLinkToSearchedPage()
1151    {
1152  1 String label = "foobar";
1153  1 openLinkDialog(MENU_WIKI_PAGE);
1154  1 waitForStepToLoad("xSelectorAggregatorStep");
1155  1 clickTab(SEARCH_TAB);
1156  1 waitForStepToLoad("xPagesSearch");
1157   
1158    // Search for "Main.WebHome".
1159  1 typeInInput("Type a keyword to search for a wiki page", "Main.WebHome");
1160  1 clickButtonWithText("Search");
1161   
1162    // Wait for the target page to appear in the list and then select it.
1163  1 String targetPageLocator =
1164    "//div[contains(@class, 'xPagesSearch')]//div[contains(@class, 'xListItem')]//div[.='"
1165    + String.format(PAGE_LOCATION, "Main", "WebHome") + "']";
1166  1 waitForElement(targetPageLocator);
1167  1 getSelenium().click(targetPageLocator);
1168   
1169  1 clickButtonWithText(BUTTON_SELECT);
1170  1 waitForStepToLoad("xLinkConfig");
1171  1 typeInInput(LABEL_INPUT_TITLE, label);
1172  1 clickButtonWithText(BUTTON_CREATE_LINK);
1173  1 waitForDialogToClose();
1174   
1175  1 switchToSource();
1176  1 assertSourceText("[[" + label + ">>doc:Main.WebHome]]");
1177    }
1178   
1179    /**
1180    * Tests the creation of a link in the current space from the search pages dialog.
1181    */
 
1182  1 toggle @Test
1183    public void testCreateLinkToNewPageInCurrentSpaceFromSearch()
1184    {
1185  1 String newPageName = "AnotherNewPage";
1186  1 String label = "x";
1187   
1188  1 typeText(label);
1189    // Select the text.
1190  1 selectNodeContents("document.body.firstChild");
1191   
1192  1 openLinkDialog(MENU_WIKI_PAGE);
1193   
1194    // check the recent changes selection
1195  1 waitForStepToLoad("xSelectorAggregatorStep");
1196  1 clickTab(SEARCH_TAB);
1197  1 waitForStepToLoad("xPagesSearch");
1198    // test that the selected element is the new page element
1199  1 assertElementPresent("//div[contains(@class, 'xListItem-selected')]/div[contains(@class, 'xNewPagePreview')]");
1200   
1201  1 clickButtonWithText(BUTTON_SELECT);
1202  1 waitForStepToLoad("xLinkToNewPage");
1203  1 getSelenium().type("//div[contains(@class, 'xLinkToNewPage')]//input", newPageName);
1204  1 clickButtonWithText(BUTTON_CREATE_LINK);
1205  1 waitForDialogToClose();
1206   
1207  1 switchToSource();
1208  1 assertSourceText("[[" + label + ">>doc:" + newPageName + "]]");
1209    }
1210   
1211    /**
1212    * Tests that the link attachments step is loaded on the current page attachments every time it's displayed.
1213    */
 
1214  1 toggle @Test
1215    public void testDefaultAttachmentSelectorSelection()
1216    {
1217    // make sure this page is saved so that the tree can load the reference to it
1218  1 clickEditSaveAndContinue();
1219   
1220  1 String currentSpace = this.getClass().getSimpleName();
1221  1 String currentPage = getTestMethodName();
1222   
1223    // check the wikipage link dialog
1224  1 openLinkDialog(MENU_ATTACHMENT);
1225   
1226  1 waitForStepToLoad("xAttachmentsSelector");
1227    // test that there is a "new attachment" option
1228  1 assertElementPresent(NEW_ATTACHMENT);
1229   
1230  1 clickTab(ALL_PAGES_TAB);
1231  1 explorer.waitForAttachmentsSelected(currentSpace, currentPage);
1232  1 closeDialog();
1233  1 waitForDialogToClose();
1234   
1235    // now type something and check second display of the dialog, that it opens on the current page
1236  1 typeText("z");
1237  1 openLinkDialog(MENU_ATTACHMENT);
1238  1 waitForStepToLoad("xAttachmentsSelector");
1239    // test that there is a "new attachment" option
1240  1 assertElementPresent(NEW_ATTACHMENT);
1241  1 closeDialog();
1242  1 waitForDialogToClose();
1243    }
1244   
1245    /**
1246    * Test that a relative link is correctly edited.
1247    *
1248    * @see <a href="http://jira.xwiki.org/jira/browse/XWIKI-3676">XWIKI-3676</a>
1249    */
 
1250  1 toggle @Test
1251    public void testEditRelativeLink()
1252    {
1253    // Edit a page in the Main space because we know pages that already exit there.
1254  1 String currentSpace = "Main";
1255  1 open(currentSpace, getTestMethodName(), "edit", "editor=wysiwyg");
1256  1 waitForEditorToLoad();
1257   
1258  1 String pageToLinkTo = "SpaceIndex";
1259  1 switchToSource();
1260  1 setSourceText("[[the main page>>" + pageToLinkTo + "]]");
1261  1 switchToWysiwyg();
1262  1 moveCaret("document.body.firstChild.firstChild.firstChild", 3);
1263  1 openLinkDialog(MENU_LINK_EDIT);
1264   
1265  1 waitForStepToLoad("xExplorerPanel");
1266  1 explorer.waitForPageSelected(currentSpace, pageToLinkTo);
1267  1 clickButtonWithText(BUTTON_SELECT);
1268  1 waitForStepToLoad("xLinkConfig");
1269  1 typeInInput(LABEL_INPUT_TITLE, "space index");
1270  1 clickButtonWithText(BUTTON_CREATE_LINK);
1271  1 waitForDialogToClose();
1272   
1273  1 switchToSource();
1274  1 assertSourceText("[[space index>>" + pageToLinkTo + "]]");
1275    }
1276   
1277    /**
1278    * Test that a relative link to a file attachment is correctly edited
1279    */
 
1280  1 toggle @Test
1281    public void testEditRelativeLinkToAttachment()
1282    {
1283    // Edit a page in the Sandbox space because we know pages that already exit there and have attachments.
1284  1 String currentSpace = "Sandbox";
1285  1 open(currentSpace, getTestMethodName(), "edit", "editor=wysiwyg");
1286  1 waitForEditorToLoad();
1287   
1288  1 String pageToLinkTo = "WebHome";
1289  1 String fileToLinkTo = "XWikiLogo.png";
1290   
1291  1 switchToSource();
1292  1 setSourceText("[[XWiki Logo>>attach:" + pageToLinkTo + "@" + fileToLinkTo + "]]");
1293  1 switchToWysiwyg();
1294  1 moveCaret("document.body.firstChild.firstChild.firstChild", 3);
1295  1 openLinkDialog(MENU_LINK_EDIT);
1296  1 waitForStepToLoad("xExplorerPanel");
1297  1 explorer.waitForAttachmentSelected(currentSpace, pageToLinkTo, fileToLinkTo);
1298   
1299    // check the current page step is correctly loaded when we switch to it
1300  1 clickTab(CURRENT_PAGE_TAB);
1301  1 waitForStepToLoad("xAttachmentsSelector");
1302    // test that there is a "new attachment" option
1303  1 assertElementPresent(NEW_ATTACHMENT);
1304   
1305    // switch back to the tree
1306  1 clickTab(ALL_PAGES_TAB);
1307  1 waitForStepToLoad("xExplorerPanel");
1308    // test that the position in the tree was preserved
1309  1 explorer.waitForAttachmentSelected(currentSpace, pageToLinkTo, fileToLinkTo);
1310   
1311  1 clickButtonWithText(BUTTON_SELECT);
1312  1 waitForStepToLoad("xLinkConfig");
1313  1 typeInInput(LABEL_INPUT_TITLE, "XWiki.org Logo");
1314  1 clickButtonWithText(BUTTON_CREATE_LINK);
1315  1 waitForDialogToClose();
1316   
1317  1 switchToSource();
1318  1 assertSourceText("[[XWiki.org Logo>>attach:" + pageToLinkTo + "@" + fileToLinkTo + "]]");
1319   
1320    // ensure this opens on the current page selector
1321  1 setSourceText("[[attach.png>>attach:attach.png]]");
1322  1 switchToWysiwyg();
1323  1 moveCaret("document.body.firstChild.firstChild.firstChild", 3);
1324  1 openLinkDialog(MENU_LINK_EDIT);
1325  1 waitForStepToLoad("xAttachmentsSelector");
1326    // The option for uploading a new attachment should be selected.
1327  1 assertElementPresent(NEW_ATTACHMENT_SELECTED);
1328  1 closeDialog();
1329  1 waitForDialogToClose();
1330    }
1331   
1332    /**
1333    * Test that when no option is selected in the current page attachments selector and a "select" is tried, an alert
1334    * is displayed to show the error.
1335    */
 
1336  1 toggle @Test
1337    public void testValidationOnCurrentPageAttachmentsSelector()
1338    {
1339  1 switchToSource();
1340  1 setSourceText("[[Export>>attach:XWiki.AdminSheet@export.png]]");
1341  1 switchToWysiwyg();
1342  1 moveCaret("document.body.firstChild.firstChild.firstChild", 3);
1343  1 openLinkDialog(MENU_LINK_EDIT);
1344  1 waitForStepToLoad("xExplorerPanel");
1345  1 explorer.waitForAttachmentSelected("XWiki", "AdminSheet", "export.png");
1346  1 explorer.findAndSelectAttachment("import.png");
1347   
1348  1 clickTab(CURRENT_PAGE_TAB);
1349   
1350  1 waitForStepToLoad("xAttachmentsSelector");
1351    // The option to upload a new attachment should be selected.
1352  1 assertElementPresent(NEW_ATTACHMENT_SELECTED);
1353  1 clickButtonWithText(BUTTON_SELECT);
1354  1 waitForStepToLoad("xUploadPanel");
1355  1 assertFieldErrorIsNotPresentInStep("xUploadPanel");
1356  1 clickButtonWithText(BUTTON_LINK_SETTINGS);
1357  1 assertFieldErrorIsPresentInStep("The file path was not set", FILE_UPLOAD_INPUT, "xUploadPanel");
1358   
1359  1 closeDialog();
1360    }
1361   
1362    /**
1363    * Test that editing a link and not changing its location preserves a full reference and does not transform it into
1364    * a relative one.
1365    */
 
1366  1 toggle @Test
1367    public void testEditLinkPreservesFullReferences()
1368    {
1369    // Edit a page in the Sandbox space because we know pages that already exit there and have attachments.
1370  1 open("Sandbox", getTestMethodName(), "edit", "editor=wysiwyg");
1371  1 waitForEditorToLoad();
1372   
1373  1 switchToSource();
1374    // Insert links to resources from the same space, using full references.
1375  1 setSourceText("[[bob>>Sandbox.WebHome]] [[alice>>Sandbox.NewPage]] "
1376    + "[[carol>>attach:Sandbox.WebHome@XWikiLogo.png]]");
1377  1 switchToWysiwyg();
1378   
1379    // Edit first link, a link to an existing page.
1380  1 moveCaret("document.body.firstChild.firstChild.firstChild", 1);
1381  1 openLinkDialog(MENU_LINK_EDIT);
1382   
1383  1 waitForStepToLoad("xExplorerPanel");
1384  1 explorer.waitForPageSelected("Sandbox", "WebHome");
1385  1 clickButtonWithText(BUTTON_SELECT);
1386  1 waitForStepToLoad("xLinkConfig");
1387  1 clickButtonWithText(BUTTON_CREATE_LINK);
1388  1 waitForDialogToClose();
1389   
1390    // Edit second link, a link to a new page.
1391  1 moveCaret("document.body.firstChild.childNodes[2].firstChild", 2);
1392  1 openLinkDialog(MENU_LINK_EDIT);
1393  1 waitForStepToLoad("xExplorerPanel");
1394  1 explorer.waitForFinderValue("document:xwiki:Sandbox.NewPage.WebHome");
1395  1 clickButtonWithText(BUTTON_SELECT);
1396  1 waitForStepToLoad("xLinkConfig");
1397  1 clickButtonWithText(BUTTON_CREATE_LINK);
1398  1 waitForDialogToClose();
1399   
1400    // Edit third link, a link to an existing file.
1401  1 moveCaret("document.body.firstChild.childNodes[4].firstChild", 2);
1402  1 openLinkDialog(MENU_LINK_EDIT);
1403  1 waitForStepToLoad("xExplorerPanel");
1404  1 explorer.waitForAttachmentSelected("Sandbox", "WebHome", "XWikiLogo.png");
1405  1 clickButtonWithText(BUTTON_SELECT);
1406  1 waitForStepToLoad("xLinkConfig");
1407  1 clickButtonWithText(BUTTON_CREATE_LINK);
1408  1 waitForDialogToClose();
1409   
1410  1 switchToSource();
1411  1 assertSourceText("[[bob>>Sandbox.WebHome]] [[alice>>Sandbox.NewPage]] "
1412    + "[[carol>>attach:Sandbox.WebHome@XWikiLogo.png]]");
1413    }
1414   
1415    /**
1416    * Test that the error markers are removed for the following displays of an external link step with an error: either
1417    * the dialog with the error is closed by canceling or by selecting a correct value and continuing, upon return to
1418    * the error dialog, the error message and markers are now hidden.
1419    */
 
1420  1 toggle @Test
1421    public void testErrorIsHiddenOnNextDisplayOfExternalLink()
1422    {
1423    // for a web page
1424  1 openLinkDialog(MENU_WEB_PAGE);
1425  1 typeInInput("Web page address", "http://www.xwiki.org");
1426  1 clickButtonWithText(BUTTON_CREATE_LINK);
1427    // check that an error is present
1428  1 assertFieldErrorIsPresentInStep("The label of the link cannot be empty", "//input[@title='" + LABEL_INPUT_TITLE
1429    + "']", "xLinkToUrl");
1430    // cancel everything
1431  1 closeDialog();
1432    // now open a new one
1433  1 openLinkDialog(MENU_WEB_PAGE);
1434    // check that the error is no longer there
1435  1 assertElementNotPresent(ERROR_MSG_CLASS);
1436  1 closeDialog();
1437   
1438    // for an email
1439  1 openLinkDialog(MENU_EMAIL_ADDRESS);
1440  1 typeInInput("Email address", "xwiki@xwiki.com");
1441  1 clickButtonWithText(BUTTON_CREATE_LINK);
1442    // check that an error is present
1443  1 assertFieldErrorIsPresentInStep("The label of the link cannot be empty", "//input[@title='" + LABEL_INPUT_TITLE
1444    + "']", "xLinkToUrl");
1445    // cancel everything
1446  1 closeDialog();
1447    // now open a new one
1448  1 openLinkDialog(MENU_EMAIL_ADDRESS);
1449    // check that the error is no longer there
1450  1 assertElementNotPresent(ERROR_MSG_CLASS);
1451  1 closeDialog();
1452    }
1453   
1454    /**
1455    * Test that the error markers are removed for the following displays of an attachment link step with an error:
1456    * either the dialog with the error is closed by canceling or by selecting a correct value and continuing, upon
1457    * return to the error dialog, the error message and markers are now hidden.
1458    */
 
1459  1 toggle @Test
1460    public void testErrorIsHiddenOnNextDisplayOfAttachmentLink()
1461    {
1462    // Get an error at the upload step and check that it's hidden on next display.
1463  1 openLinkDialog(MENU_ATTACHMENT);
1464  1 waitForStepToLoad("xAttachmentsSelector");
1465    // The option to upload a new attachment should be selected.
1466  1 assertElementPresent(NEW_ATTACHMENT_SELECTED);
1467  1 clickButtonWithText(BUTTON_SELECT);
1468  1 waitForStepToLoad("xUploadPanel");
1469    // Click the upload button without selecting a file.
1470  1 clickButtonWithText(BUTTON_LINK_SETTINGS);
1471  1 assertFieldErrorIsPresentInStep("The file path was not set", FILE_UPLOAD_INPUT, "xUploadPanel");
1472    // Go to the previous step and come back: the error should be gone.
1473  1 clickButtonWithText("Previous");
1474    // We need to wait for the previous step to load because it is reinitialized (the list of attachments is fetched
1475    // again with an asynchronous request).
1476  1 waitForStepToLoad("xAttachmentsSelector");
1477  1 clickButtonWithText(BUTTON_SELECT);
1478  1 assertFieldErrorIsNotPresentInStep("xUploadPanel");
1479    // Get the error again to check that closing it and displaying this step again makes it go away.
1480  1 clickButtonWithText(BUTTON_CREATE_LINK);
1481  1 assertFieldErrorIsPresentInStep("The file path was not set", FILE_UPLOAD_INPUT, "xUploadPanel");
1482  1 closeDialog();
1483  1 openLinkDialog(MENU_ATTACHMENT);
1484  1 waitForStepToLoad("xAttachmentsSelector");
1485  1 assertElementPresent(NEW_ATTACHMENT_SELECTED);
1486  1 clickButtonWithText(BUTTON_SELECT);
1487  1 assertFieldErrorIsNotPresentInStep("xUploadPanel");
1488    }
1489   
1490    /**
1491    * Test that the error markers are removed for the following displays of a wiki page link step with an error: either
1492    * the dialog with the error is closed by canceling or by selecting a correct value and continuing, upon return to
1493    * the error dialog, the error message and markers are now hidden.
1494    */
 
1495  1 toggle @Test
1496    public void testErrorIsHiddenOnNextDisplayOfWikipageLink()
1497    {
1498    // 1/ get an error on the new page step, fix it, go to previous, next => error not displayed anymore. Get
1499    // another error, go next, previous, error should not be there anymore. Get another error, close dialog. Open
1500    // again, get there, the error should not be displayed.
1501  1 openLinkDialog(MENU_WIKI_PAGE);
1502  1 waitForStepAggregatorAndAssertSelectedStep(RECENT_PAGES_TAB);
1503  1 assertElementPresent("//div[contains(@class, 'xListItem-selected')]/div[contains(@class, 'xNewPagePreview')]");
1504  1 clickButtonWithText(BUTTON_SELECT);
1505  1 waitForStepToLoad("xLinkToNewPage");
1506  1 clickButtonWithText(BUTTON_LINK_SETTINGS);
1507  1 assertFieldErrorIsPresentInStep("The name of the new page was not set", "//input", "xLinkToNewPage");
1508  1 clickButtonWithText("Previous");
1509  1 waitForStepAggregatorAndAssertSelectedStep(RECENT_PAGES_TAB);
1510  1 assertElementPresent("//div[contains(@class, 'xListItem-selected')]/div[contains(@class, 'xNewPagePreview')]");
1511  1 clickButtonWithText(BUTTON_SELECT);
1512    // error not present on coming back from previous
1513  1 assertFieldErrorIsNotPresentInStep("xLinkToNewPage");
1514  1 clickButtonWithText(BUTTON_CREATE_LINK);
1515  1 assertFieldErrorIsPresentInStep("The name of the new page was not set", "//input", "xLinkToNewPage");
1516  1 getSelenium().type("//div[contains(@class, 'xLinkToNewPage')]//input", "NewPage");
1517  1 clickButtonWithText(BUTTON_LINK_SETTINGS);
1518  1 waitForStepToLoad("xLinkConfig");
1519  1 clickButtonWithText("Previous");
1520    // error not present when coming back from next
1521  1 assertFieldErrorIsNotPresentInStep("xLinkToNewPage");
1522    // check the content of the field
1523  1 assertEquals("NewPage", getSelenium().getValue("//div[contains(@class, 'xLinkToNewPage')]//input"));
1524    // get error again
1525  1 getSelenium().type("//div[contains(@class, 'xLinkToNewPage')]//input", "");
1526  1 clickButtonWithText(BUTTON_CREATE_LINK);
1527  1 assertFieldErrorIsPresentInStep("The name of the new page was not set", "//input", "xLinkToNewPage");
1528  1 closeDialog();
1529    // open again, check the error is not still there
1530  1 openLinkDialog(MENU_WIKI_PAGE);
1531  1 waitForStepAggregatorAndAssertSelectedStep(RECENT_PAGES_TAB);
1532  1 assertElementPresent("//div[contains(@class, 'xListItem-selected')]/div[contains(@class, 'xNewPagePreview')]");
1533  1 clickButtonWithText(BUTTON_SELECT);
1534    // error not present when re-creating a link
1535  1 assertFieldErrorIsNotPresentInStep("xLinkToNewPage");
1536  1 closeDialog();
1537  1 resetContent();
1538   
1539    // 2/ get to the link config and get an error on the label -> previous, next, error should not be there anymore.
1540    // close everything, open again, error should not be there anymore. get error, fix it, add the link, on new
1541    // dialog error should not be there anymore
1542  1 switchToSource();
1543  1 setSourceText("[[the sandbox>>Sandbox.WebHome]]");
1544  1 switchToWysiwyg();
1545  1 moveCaret("document.body.firstChild.firstChild.firstChild", 4);
1546  1 openLinkDialog(MENU_LINK_EDIT);
1547  1 waitForStepAggregatorAndAssertSelectedStep(ALL_PAGES_TAB);
1548  1 explorer.waitForPageSelected("Sandbox", "WebHome");
1549  1 clickButtonWithText(BUTTON_SELECT);
1550  1 waitForStepToLoad("xLinkConfig");
1551  1 typeInInput(LABEL_INPUT_TITLE, "");
1552  1 clickButtonWithText(BUTTON_CREATE_LINK);
1553  1 assertFieldErrorIsPresentInStep("The label of the link cannot be empty", "//input[position() = 1]",
1554    "xLinkConfig");
1555    // previous, next => error is not present
1556  1 clickButtonWithText("Previous");
1557  1 waitForStepAggregatorAndAssertSelectedStep(ALL_PAGES_TAB);
1558  1 explorer.waitForPageSelected("Sandbox", "WebHome");
1559  1 clickButtonWithText(BUTTON_SELECT);
1560  1 assertFieldErrorIsNotPresentInStep("xLinkConfig");
1561    // error, again, to close this time
1562  1 typeInInput(LABEL_INPUT_TITLE, "");
1563  1 clickButtonWithText(BUTTON_CREATE_LINK);
1564  1 assertFieldErrorIsPresentInStep("The label of the link cannot be empty", "//input[position() = 1]",
1565    "xLinkConfig");
1566  1 closeDialog();
1567    // now again, check that the error is no longer there
1568  1 openLinkDialog(MENU_LINK_EDIT);
1569  1 waitForStepAggregatorAndAssertSelectedStep(ALL_PAGES_TAB);
1570  1 explorer.waitForPageSelected("Sandbox", "WebHome");
1571  1 clickButtonWithText(BUTTON_SELECT);
1572  1 assertFieldErrorIsNotPresentInStep("xLinkConfig");
1573    // get an error
1574  1 typeInInput(LABEL_INPUT_TITLE, "");
1575  1 clickButtonWithText(BUTTON_CREATE_LINK);
1576  1 assertFieldErrorIsPresentInStep("The label of the link cannot be empty", "//input[position() = 1]",
1577    "xLinkConfig");
1578    // now go ahead, edit the link
1579  1 typeInInput(LABEL_INPUT_TITLE, "PageNew");
1580  1 clickButtonWithText(BUTTON_CREATE_LINK);
1581    // now open again, check error is not there anymore
1582  1 openLinkDialog(MENU_LINK_EDIT);
1583  1 waitForStepAggregatorAndAssertSelectedStep(ALL_PAGES_TAB);
1584  1 explorer.waitForPageSelected("Sandbox", "WebHome");
1585  1 clickButtonWithText(BUTTON_SELECT);
1586  1 assertFieldErrorIsNotPresentInStep("xLinkConfig");
1587  1 closeDialog();
1588   
1589    // 5/ get to the tree explorer, don't select any page, get an error. Fill in, next, previous -> error is hidden.
1590    // Get error again, close. Open and error is hidden
1591  1 switchToSource();
1592  1 setSourceText("[[the blog>>Blog.WebHome]]");
1593  1 switchToWysiwyg();
1594  1 moveCaret("document.body.firstChild.firstChild.firstChild", 4);
1595  1 openLinkDialog(MENU_LINK_EDIT);
1596  1 waitForStepAggregatorAndAssertSelectedStep(ALL_PAGES_TAB);
1597  1 explorer.waitForPageSelected("Blog", "WebHome");
1598    // Clear the selection.
1599  1 explorer.togglePageSelection("Blog", "WebHome");
1600    // At this point no page is selected.
1601  1 clickButtonWithText(BUTTON_SELECT);
1602  1 assertFieldErrorIsPresentInStep("No page was selected", TREE_EXPLORER, "xExplorerPanel");
1603  1 explorer.findAndSelectPage("Blog");
1604  1 clickButtonWithText(BUTTON_SELECT);
1605  1 waitForStepToLoad("xLinkConfig");
1606  1 clickButtonWithText("Previous");
1607    // The previously selected page should still be selected.
1608  1 explorer.waitForPageSelected("Blog", "WebHome");
1609  1 assertFieldErrorIsNotPresentInStep("xExplorerPanel");
1610    // Repeat the steps to get the validation error.
1611    // Select a space so that no page is selected.
1612  1 explorer.togglePageSelection("Blog", "WebHome");
1613    // At this point no page is selected.
1614  1 clickButtonWithText(BUTTON_SELECT);
1615  1 assertFieldErrorIsPresentInStep("No page was selected", TREE_EXPLORER, "xExplorerPanel");
1616  1 closeDialog();
1617  1 openLinkDialog(MENU_LINK_EDIT);
1618  1 waitForStepAggregatorAndAssertSelectedStep(ALL_PAGES_TAB);
1619  1 assertFieldErrorIsNotPresentInStep("xExplorerPanel");
1620  1 closeDialog();
1621    }
1622   
1623    /**
1624    * Test fast navigation for adding a link to an attachment: double click and enter in the list of attachments
1625    * advance to the next step.
1626    */
 
1627  1 toggle @Test
1628    public void testFastNavigationToSelectAttachment()
1629    {
1630    // can't test but the current page attachment selector, the tree doesn't receive the click events
1631    // double click
1632  1 openLinkDialog(MENU_ATTACHMENT);
1633  1 waitForStepToLoad("xAttachmentsSelector");
1634  1 getSelenium().click(NEW_ATTACHMENT);
1635  1 getSelenium().doubleClick(NEW_ATTACHMENT);
1636  1 waitForStepToLoad("xUploadPanel");
1637  1 closeDialog();
1638   
1639    // enter
1640  1 openLinkDialog(MENU_ATTACHMENT);
1641  1 waitForStepToLoad("xAttachmentsSelector");
1642  1 getSelenium().click(NEW_ATTACHMENT);
1643  1 getSelenium().typeKeys(ITEMS_LIST, "\\13");
1644  1 waitForStepToLoad("xUploadPanel");
1645  1 closeDialog();
1646    }
1647   
1648    /**
1649    * Test fast navigation for adding a link to a recent page: double click and enter on a page advance to the next
1650    * step.
1651    */
 
1652  1 toggle @Test
1653    public void testFastNavigationToSelectRecentPage()
1654    {
1655    // 1. link to existing page, double click
1656    // make sure this page is saved so that the recent pages can load reference to it
1657  1 clickEditSaveAndContinue();
1658  1 String currentPageLocation = String.format(PAGE_LOCATION, this.getClass().getSimpleName(), getTestMethodName());
1659  1 String label = "barfoo";
1660  1 openLinkDialog(MENU_WIKI_PAGE);
1661  1 waitForStepAggregatorAndAssertSelectedStep(RECENT_PAGES_TAB);
1662  1 getSelenium().click(
1663    "//div[contains(@class, 'xPagesSelector')]//div[contains(@class, 'gwt-Label') and .='"
1664    + currentPageLocation + "']");
1665  1 getSelenium().doubleClick(
1666    "//div[contains(@class, 'xPagesSelector')]//div[contains(@class, 'gwt-Label') and .='"
1667    + currentPageLocation + "']");
1668  1 waitForStepToLoad("xLinkConfig");
1669  1 typeInInput(LABEL_INPUT_TITLE, label);
1670  1 clickButtonWithText(BUTTON_CREATE_LINK);
1671  1 waitForDialogToClose();
1672   
1673  1 switchToSource();
1674  1 assertSourceText("[[" + label + ">>doc:" + getTestMethodName() + "]]");
1675   
1676  1 setSourceText("");
1677  1 switchToWysiwyg();
1678   
1679    // 2. link to new page in current space, with enter
1680  1 String newPageName = "NewPage";
1681  1 label = "foobar";
1682   
1683  1 openLinkDialog(MENU_WIKI_PAGE);
1684  1 waitForStepAggregatorAndAssertSelectedStep(RECENT_PAGES_TAB);
1685    // select the current page
1686  1 getSelenium().click("//div[contains(@class, 'xListItem')]/div[contains(@class, 'xNewPagePreview')]");
1687  1 getSelenium().typeKeys(ITEMS_LIST, "\\13");
1688  1 waitForStepToLoad("xLinkToNewPage");
1689  1 getSelenium().type("//div[contains(@class, 'xLinkToNewPage')]//input", newPageName);
1690  1 clickButtonWithText(BUTTON_LINK_SETTINGS);
1691  1 waitForStepToLoad("xLinkConfig");
1692  1 typeInInput(LABEL_INPUT_TITLE, label);
1693  1 clickButtonWithText(BUTTON_CREATE_LINK);
1694  1 waitForDialogToClose();
1695   
1696  1 switchToSource();
1697  1 assertSourceText("[[" + label + ">>doc:" + newPageName + "]]");
1698    }
1699   
1700    /**
1701    * Test fast navigation for adding a link to a searched for page: double click and enter on a page advance to the
1702    * next step.
1703    */
 
1704  1 toggle @Test
1705    public void testFastNavigationToSelectSearchedPage()
1706    {
1707    // 1. Link to existing page. Use Enter key to select the target page.
1708  1 String label = "foobar";
1709  1 openLinkDialog(MENU_WIKI_PAGE);
1710  1 waitForStepToLoad("xSelectorAggregatorStep");
1711  1 clickTab(SEARCH_TAB);
1712  1 waitForStepToLoad("xPagesSearch");
1713   
1714    // Search for "Main.WebHome" page.
1715  1 typeInInput("Type a keyword to search for a wiki page", "Main.WebHome");
1716  1 clickButtonWithText("Search");
1717   
1718    // Wait for target page to appear in the list, then select it using the Enter key.
1719  1 String targetPageLocator =
1720    "//div[contains(@class, 'xPagesSearch')]//div[contains(@class, 'xListItem')]//div[.='"
1721    + String.format(PAGE_LOCATION, "Main", "WebHome") + "']";
1722  1 waitForElement(targetPageLocator);
1723  1 getSelenium().click(targetPageLocator);
1724  1 getSelenium().typeKeys("//div[contains(@class, 'xPagesSearch')]" + ITEMS_LIST, "\\13");
1725   
1726  1 waitForStepToLoad("xLinkConfig");
1727  1 typeInInput(LABEL_INPUT_TITLE, label);
1728  1 clickButtonWithText(BUTTON_CREATE_LINK);
1729  1 waitForDialogToClose();
1730   
1731  1 switchToSource();
1732  1 assertSourceText("[[" + label + ">>doc:Main.WebHome]]");
1733   
1734  1 setSourceText("");
1735  1 switchToWysiwyg();
1736   
1737    // 2. Link to a new page. Use double click to select the target page.
1738  1 String newPageName = "PageNew";
1739  1 label = "barfoo";
1740  1 openLinkDialog(MENU_WIKI_PAGE);
1741  1 waitForStepToLoad("xSelectorAggregatorStep");
1742  1 clickTab(SEARCH_TAB);
1743  1 waitForStepToLoad("xPagesSearch");
1744  1 getSelenium().click(NEW_PAGE_FROM_SEARCH_LOCATOR);
1745  1 getSelenium().doubleClick(NEW_PAGE_FROM_SEARCH_LOCATOR);
1746  1 waitForStepToLoad("xLinkToNewPage");
1747  1 getSelenium().type("//div[contains(@class, 'xLinkToNewPage')]//input", newPageName);
1748  1 clickButtonWithText(BUTTON_LINK_SETTINGS);
1749  1 waitForStepToLoad("xLinkConfig");
1750  1 typeInInput(LABEL_INPUT_TITLE, label);
1751  1 clickButtonWithText(BUTTON_CREATE_LINK);
1752  1 waitForDialogToClose();
1753   
1754  1 switchToSource();
1755  1 assertSourceText("[[" + label + ">>doc:" + newPageName + "]]");
1756    }
1757   
1758    /**
1759    * Tests if an empty link is filtered.
1760    */
 
1761  1 toggle @Test
1762    public void testFilterEmptyLink()
1763    {
1764  1 typeText("ab");
1765    // Select the text.
1766  1 selectNodeContents("document.body.firstChild");
1767    // Make it bold.
1768  1 clickBoldButton();
1769    // Make it a link to a web page.
1770  1 openLinkDialog(MENU_WEB_PAGE);
1771    // Ensure wizard step is loaded.
1772  1 waitForStepToLoad("xLinkToUrl");
1773  1 typeInInput("Web page address", "http://www.xwiki.org");
1774  1 clickButtonWithText(BUTTON_CREATE_LINK);
1775  1 waitForDialogToClose();
1776    // Place the caret inside the text.
1777  1 moveCaret("document.body.firstChild.firstChild.firstChild", 1);
1778    // Remove the bold style around the caret (not for the entire link).
1779  1 clickBoldButton();
1780    // The link must have been split in three.
1781  1 assertEquals(3L, getRichTextArea().executeScript("return document.body.getElementsByTagName('a').length"));
1782    // Check the source text.
1783  1 switchToSource();
1784  1 assertSourceText("**[[a>>url:http://www.xwiki.org]][[b>>url:http://www.xwiki.org]]**");
1785    }
1786   
1787    /**
1788    * @see XWIKI-4536: wiki pages can no longer be edited when there are links to Wiki pages within a section heading
1789    */
 
1790  1 toggle @Test
1791    public void testPreviewHeadingContainingLinkWithNoLabel()
1792    {
1793  1 switchToSource();
1794  1 setSourceText("= x [[y]] =");
1795  1 switchToWysiwyg();
1796  1 clickEditPreview();
1797  1 assertElementNotPresent("//div[@class = 'errormessage']");
1798  1 clickBackToEdit();
1799    }
1800   
1801    /**
1802    * Creates a link to a recently modified page that has special characters in its name.
1803    */
 
1804  1 toggle @Test
1805    public void testCreateLinkToRecentlyModifiedPageWithSpecialCharactersInName()
1806    {
1807    // Create a page with special characters in its name.
1808  1 String spaceName = this.getClass().getSimpleName() + ":s.t@u?v=w&x=y#z";
1809  1 String escapedSpaceName = spaceName.replaceAll("([\\:\\.])", "\\\\$1");
1810  1 String pageName = getTestMethodName() + ":a.b@c?d=e&f=g#h";
1811  1 String escapedPageName = pageName.replace(".", "\\.");
1812  1 String linkReference = String.format("%s.%s", escapedSpaceName, escapedPageName);
1813  1 open("Main", "WebHome");
1814  1 createPage(spaceName, pageName, "");
1815   
1816    // Come back to the edited page.
1817  1 open(this.getClass().getSimpleName(), getTestMethodName(), "edit", "editor=wysiwyg");
1818  1 waitForEditorToLoad();
1819   
1820    // Create a link to the created page.
1821  1 openLinkDialog(MENU_WIKI_PAGE);
1822  1 waitForStepToLoad("xSelectorAggregatorStep");
1823  1 waitForStepToLoad("xPagesSelector");
1824  1 String createdPageLocator =
1825    "//div[contains(@class, 'xListItem')]//div[contains(@class, 'gwt-Label') and .='"
1826    + String.format(PAGE_LOCATION, spaceName, pageName) + "']";
1827  1 waitForElement(createdPageLocator);
1828  1 getSelenium().click(createdPageLocator);
1829  1 clickButtonWithText(BUTTON_SELECT);
1830  1 waitForStepToLoad("xLinkConfig");
1831  1 String label = "Label";
1832  1 typeInInput(LABEL_INPUT_TITLE, label);
1833  1 clickButtonWithText(BUTTON_CREATE_LINK);
1834  1 waitForDialogToClose();
1835   
1836    // Check the result.
1837  1 switchToSource();
1838  1 assertSourceText(String.format("[[%s>>doc:%s]]", label, linkReference));
1839  1 switchToWysiwyg();
1840   
1841    // Edit the created link.
1842  1 openLinkDialog(MENU_LINK_EDIT);
1843  1 waitForStepToLoad("xSelectorAggregatorStep");
1844  1 clickTab(RECENT_PAGES_TAB);
1845  1 waitForStepToLoad("xPagesSelector");
1846  1 waitForElement("//div[contains(@class, 'xListItem-selected')]//div[. = '"
1847    + String.format(PAGE_LOCATION, spaceName, pageName) + "']");
1848  1 clickButtonWithText(BUTTON_SELECT);
1849  1 waitForStepToLoad("xLinkConfig");
1850    // Change the link to open in new window.
1851  1 getSelenium().check("//div[contains(@class, 'xLinkConfig')]//span[contains(@class, 'gwt-CheckBox')]/input");
1852  1 clickButtonWithText(BUTTON_CREATE_LINK);
1853  1 waitForDialogToClose();
1854   
1855    // Check the result.
1856  1 switchToSource();
1857  1 assertSourceText(String.format("[[%s>>doc:%s||rel=\"__blank\"]]", label, linkReference));
1858    }
1859   
1860    /**
1861    * Creates a link to a new page that has special characters in its name.
1862    */
 
1863  1 toggle @Test
1864    public void testCreateLinkToNewPageWithSpecialCharactersInName()
1865    {
1866  1 String pageName = getTestMethodName() + ":a.b@c?d=e&f=g#h";
1867  1 String linkReference = pageName.replace(".", "\\.");
1868  1 String label = "x";
1869   
1870  1 typeText(label);
1871  1 selectNode("document.body.firstChild");
1872   
1873  1 openLinkDialog(MENU_WIKI_PAGE);
1874  1 waitForStepToLoad("xSelectorAggregatorStep");
1875  1 waitForStepToLoad("xPagesSelector");
1876  1 waitForElement("//div[contains(@class, 'xListItem-selected')]/div[contains(@class, 'xNewPagePreview')]");
1877  1 clickButtonWithText(BUTTON_SELECT);
1878  1 waitForStepToLoad("xLinkToNewPage");
1879  1 getSelenium().type("//div[contains(@class, 'xLinkToNewPage')]//input", pageName);
1880  1 clickButtonWithText(BUTTON_CREATE_LINK);
1881  1 waitForDialogToClose();
1882   
1883  1 switchToSource();
1884  1 assertSourceText(String.format("[[%s>>doc:%s]]", label, linkReference));
1885    }
1886   
1887    /**
1888    * Creates a link to the currently edited page by going through the "All Pages" step.
1889    *
1890    * @see XWIKI-5849: Cannot create link to current page
1891    */
 
1892  1 toggle @Test
1893    public void testCreateLinkToCurrentPageThroughAllPages()
1894    {
1895    // We have to save the page to make it appear in the all pages tree.
1896  1 clickEditSaveAndContinue();
1897   
1898  1 String linkLabel = "x";
1899  1 typeText(linkLabel);
1900  1 selectNodeContents("document.body.firstChild");
1901   
1902  1 openLinkDialog(MENU_WIKI_PAGE);
1903  1 clickTab(ALL_PAGES_TAB);
1904  1 waitForStepToLoad(STEP_EXPLORER);
1905   
1906  1 String currentSpaceName = this.getClass().getSimpleName();
1907  1 String currentPageName = getTestMethodName();
1908   
1909    // The current page should be selected by default.
1910  1 explorer.waitForPageSelected(currentSpaceName, currentPageName);
1911  1 clickButtonWithText(BUTTON_SELECT);
1912   
1913    // Wait for the link configuration step to load.
1914  1 waitForStepToLoad("xLinkConfig");
1915  1 clickButtonWithText(BUTTON_CREATE_LINK);
1916  1 waitForDialogToClose();
1917   
1918  1 switchToSource();
1919  1 assertSourceText("[[" + linkLabel + ">>doc:" + currentPageName + "]]");
1920    }
1921   
1922    /**
1923    * @see XWIKI-4473: Cannot edit a link to an existing page to change its target to a new page using the All pages
1924    * tab
1925    */
 
1926  1 toggle @Test
1927    public void testChangeLinkTargetToNewPage()
1928    {
1929  1 switchToSource();
1930  1 setSourceText("[[Home>>Main.WebHome]]");
1931  1 switchToWysiwyg();
1932   
1933    // Edit the link and change its target to a new page.
1934  1 selectAllContent();
1935   
1936  1 openLinkDialog(MENU_LINK_EDIT);
1937  1 waitForStepToLoad("xSelectorAggregatorStep");
1938  1 waitForStepToLoad("xExplorerPanel");
1939  1 explorer.waitForPageSelected("Main", "WebHome");
1940   
1941  1 explorer.openPage("Blog", "WebHome").selectNewPage("Blog");
1942  1 clickButtonWithText(BUTTON_SELECT);
1943   
1944  1 waitForStepToLoad("xLinkToNewPage");
1945  1 getSelenium().type("//div[contains(@class, 'xLinkToNewPage')]//input", getTestMethodName());
1946  1 clickButtonWithText(BUTTON_CREATE_LINK);
1947  1 waitForDialogToClose();
1948   
1949  1 switchToSource();
1950  1 assertSourceText("[[Home>>Blog." + getTestMethodName() + "]]");
1951    }
1952   
1953    /**
1954    * XWIKI-6657: Attachment selection limited set to Yes still shows "All Pages" tab when creating a link in WYSIWYG
1955    */
 
1956  1 toggle @Test
1957    public void testAttachmentSelectionLimitedToCurrentPage()
1958    {
1959  1 String allPagesTabLocator =
1960    "//*[contains(@class, 'xStepsTabs')]//*[@class = 'gwt-TabBarItem' and . = '" + ALL_PAGES_TAB + "']";
1961  1 String location = getSelenium().getLocation();
1962   
1963    // By default, attachment selection shoudn't be limited to the current page.
1964  1 openLinkDialog(MENU_ATTACHMENT);
1965  1 waitForStepToLoad("xSelectorAggregatorStep");
1966  1 assertElementPresent(allPagesTabLocator);
1967   
1968    // Change the configuration.
1969  1 open("XWiki", "WysiwygEditorConfig", "edit", "editor=object");
1970  1 expandObject("XWiki.WysiwygEditorConfigClass", 0);
1971  1 checkField("XWiki.WysiwygEditorConfigClass_0_attachmentSelectionLimited");
1972  1 clickEditSaveAndContinue();
1973   
1974  1 try {
1975  1 open(location);
1976  1 waitForEditorToLoad();
1977   
1978    // The "All Pages" tab should be hidden now.
1979  1 openLinkDialog(MENU_ATTACHMENT);
1980  1 waitForStepToLoad("xSelectorAggregatorStep");
1981  1 assertElementNotPresent(allPagesTabLocator);
1982    } finally {
1983    // Restore the configuration.
1984  1 open("XWiki", "WysiwygEditorConfig", "edit", "editor=object");
1985  1 expandObject("XWiki.WysiwygEditorConfigClass", 0);
1986  1 checkField("XWiki.WysiwygEditorConfigClass_0_attachmentSelectionLimited_false");
1987  1 clickEditSaveAndContinue();
1988    }
1989    }
1990   
1991    /**
1992    * @see XWIKI-7593: Links from other WYSIWYG fields are removed if the page is saved while a WYSIWYG field is edited
1993    * in full screen
1994    */
 
1995  1 toggle @Test
1996    public void testEmptyLinkFilterWhenEditingFullScreen() throws UnsupportedEncodingException
1997    {
1998    // Add a link to the summary field.
1999  1 open("Blog", "BlogIntroduction", "save",
2000    "Blog.BlogPostClass_0_extract=" + URLEncoder.encode("[[XWiki>>http://www.xwiki.org]]", "UTF-8"));
2001   
2002    // Edit in "Inline form" edit mode.
2003  1 open("Blog", "BlogIntroduction", "edit", "editor=inline");
2004    // Edit the blog post content field in full screen mode and save.
2005    // Note: The following works because the content field is the first WYSIWYG field.
2006  1 waitForEditorToLoad();
2007  1 clickEditInFullScreen();
2008  1 clickEditSaveAndView();
2009   
2010    // Check if the link is still present.
2011  1 open("/xwiki/rest/wikis/xwiki/spaces/Blog/pages/BlogIntroduction/objects/Blog.BlogPostClass/0/properties/extract");
2012  1 assertTrue(getDriver().getPageSource().contains("<value>[[XWiki&gt;&gt;http://www.xwiki.org]]</value>"));
2013    }
2014   
 
2015  150 toggle protected void waitForStepToLoad(String name)
2016    {
2017  150 getDriver().waitUntilElementIsVisible(By.className(name));
2018    }
2019   
 
2020  25 toggle private void clickTab(String tabName)
2021    {
2022  25 String tabSelector = "//div[.='" + tabName + "']";
2023  25 getSelenium().click(tabSelector);
2024    }
2025   
 
2026  74 toggle private void openLinkDialog(String menuName)
2027    {
2028  74 clickMenu(MENU_LINK);
2029  74 assertTrue(isMenuEnabled(menuName));
2030  74 clickMenu(menuName);
2031  74 waitForDialogToLoad();
2032    }
2033   
2034    /**
2035    * In addition to {@link #assertFieldErrorIsPresent(String, String)}, this function does the checks in the specified
2036    * step.
2037    *
2038    * @param errorMessage the expected error message
2039    * @param fieldXPathLocator the locator for the field in error
2040    * @param step the step in which the error should appear
2041    * @see {@link #assertFieldErrorIsPresent(String, String)}
2042    */
 
2043  23 toggle public void assertFieldErrorIsPresentInStep(String errorMessage, String fieldXPathLocator, String step)
2044    {
2045  23 waitForStepToLoad(step);
2046  23 assertFieldErrorIsPresent(errorMessage, fieldXPathLocator);
2047    }
2048   
2049    /**
2050    * In addition to {@link #assertFieldErrorIsNotPresent()}, this function does the checks in the specified step.
2051    *
2052    * @param step the step to check for errors
2053    */
 
2054  11 toggle public void assertFieldErrorIsNotPresentInStep(String step)
2055    {
2056  11 waitForStepToLoad(step);
2057  11 assertFieldErrorIsNotPresent();
2058    }
2059   
2060    /**
2061    * Waits for the step aggregator to load and asserts the specified step is selected.
2062    *
2063    * @param selectedStepTitle the title of step that is expected to be selected
2064    */
 
2065  11 toggle private void waitForStepAggregatorAndAssertSelectedStep(String selectedStepTitle)
2066    {
2067  11 getDriver().waitUntilElementIsVisible(
2068    By.xpath("//*[@class = 'xSelectorAggregatorStep']/"
2069    + "*[contains(@class, 'xStepsTabs') and not(contains(@class, 'loading'))]"));
2070  11 assertTrue(getDriver().hasElementWithoutWaiting(
2071    By.xpath("//*[contains(@class, 'xStepsTabs')]"
2072    + "//*[contains(@class, 'gwt-TabBarItem-selected') and . = '" + selectedStepTitle + "']")));
2073    }
2074    }