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

File WikiEditorTest.java

 

Code metrics

2
51
11
1
180
114
12
0.24
4.64
11
1.09

Classes

Class Line # Actions
WikiEditorTest 37 51 0% 12 0
1.0100%
 

Contributing tests

This file is covered by 10 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.selenium;
21   
22    import java.io.IOException;
23   
24    import org.junit.Test;
25    import org.openqa.selenium.By;
26    import org.openqa.selenium.Keys;
27    import org.openqa.selenium.WebElement;
28    import org.xwiki.test.selenium.framework.AbstractXWikiTestCase;
29   
30    import static org.junit.Assert.*;
31   
32    /**
33    * Tests the wiki editor.
34    *
35    * @version $Id: c326e53dc2c610bcf10f6468e6beff24e1dfd811 $
36    */
 
37    public class WikiEditorTest extends AbstractXWikiTestCase
38    {
39    private static final String SYNTAX = "xwiki/2.1";
40   
 
41  1 toggle @Test
42    public void testEmptyLineAndSpaceCharactersBeforeSectionTitleIsNotRemoved()
43    {
44  1 createPage("Test", "WikiEdit", "\n== Section ==\n\ntext", SYNTAX);
45  1 open("Test", "WikiEdit", "edit", "editor=wiki");
46  1 assertEquals("\n== Section ==\n\ntext", getFieldValue("content"));
47    }
48   
 
49  1 toggle @Test
50    public void testBoldButton()
51    {
52  1 testToolBarButton("Bold", "**%s**", "Text in Bold");
53    }
54   
 
55  1 toggle @Test
56    public void testItalicsButton()
57    {
58  1 testToolBarButton("Italics", "//%s//", "Text in Italics");
59    }
60   
 
61  1 toggle @Test
62    public void testUnderlineButton()
63    {
64  1 testToolBarButton("Underline", "__%s__", "Text in Underline");
65    }
66   
 
67  1 toggle @Test
68    public void testLinkButton()
69    {
70  1 testToolBarButton("Internal Link", "[[%s]]", "Link Example");
71    }
72   
 
73  1 toggle @Test
74    public void testHRButton()
75    {
76  1 testToolBarButton("Horizontal ruler", "\n----\n", "");
77    }
78   
 
79  1 toggle @Test
80    public void testImageButton()
81    {
82  1 testToolBarButton("Attached Image", "[[image:%s]]", "example.jpg");
83    }
84   
85    /**
86    * Tests that users can completely remove the content from a document (make the document empty). In previous
87    * versions (pre-1.5M2), removing all content in page had no effect. See XWIKI-1007.
88    */
 
89  1 toggle @Test
90    public void testEmptyDocumentContentIsAllowed()
91    {
92  1 createPage("Test", "EmptyWikiContent", "this is some content", SYNTAX);
93  1 editInWikiEditor("Test", "EmptyWikiContent", SYNTAX);
94  1 setFieldValue("content", "");
95  1 clickEditSaveAndView();
96  1 assertFalse(getSelenium().isAlertPresent());
97  1 assertEquals(-1, getSelenium().getLocation().indexOf("/edit/"));
98  1 assertTextNotPresent("this is some content");
99    }
100   
101    /**
102    * Test the ability to add edit comments and the ability to disable the edit comments feature.
103    */
 
104  1 toggle @Test
105    public void testEditComment() throws IOException
106    {
107  1 try {
108  1 editInWikiEditor("Test", "EditComment", SYNTAX);
109  1 assertTrue(getSelenium().isVisible("comment"));
110   
111    // Test for XWIKI-2487: Hiding the edit comment field doesn't work
112  1 setXWikiConfiguration("xwiki.editcomment.hidden=1");
113  1 editInWikiEditor("Test", "EditComment", SYNTAX);
114  1 assertFalse(getSelenium().isVisible("comment"));
115    } finally {
116  1 setXWikiConfiguration("xwiki.editcomment.hidden=0");
117    }
118    }
119   
120    /**
121    * Verify minor edit feature is working
122    */
 
123  1 toggle @Test
124    public void testMinorEdit()
125    {
126  1 try {
127  1 editInWikiEditor("Test", "MinorEdit", SYNTAX);
128    // Note: Revision 2.1 is used since starting with 1.9-rc-1 editInWikiEditor creates an initial version to
129    // set the syntax.
130  1 setFieldValue("content", "version=1.2");
131    // Save & Continue = minor edit.
132  1 clickEditSaveAndContinue();
133  1 setFieldValue("content", "version=2.1");
134  1 clickEditSaveAndView();
135   
136  1 open("Test", "MinorEdit", "viewrev", "rev=2.1");
137  1 assertTextPresent("version=2.1");
138   
139  1 editInWikiEditor("Test", "MinorEdit", SYNTAX);
140  1 setFieldValue("content", "version=2.2");
141  1 getSelenium().click("minorEdit");
142  1 clickEditSaveAndView();
143   
144  1 open("Test", "MinorEdit", "viewrev", "rev=2.2");
145  1 assertTextPresent("version=2.2");
146    } finally {
147  1 deletePage("Test", "MinorEdit");
148    }
149    }
150   
151    /**
152    * Tests that the specified tool bar button works.
153    *
154    * @param buttonTitle the title of a tool bar button
155    * @param format the format of the text inserted by the specified button
156    * @param defaultText the default text inserted if there's no text selected in the text area
157    */
 
158  6 toggle private void testToolBarButton(String buttonTitle, String format, String defaultText)
159    {
160  6 editInWikiEditor(this.getClass().getSimpleName(), getTestMethodName(), SYNTAX);
161  6 WebElement textArea = getDriver().findElement(By.id("content"));
162  6 textArea.clear();
163  6 textArea.sendKeys("a");
164  6 String buttonLocator = "//img[@title = '" + buttonTitle + "']";
165  6 getSelenium().click(buttonLocator);
166    // Type b and c on two different lines and move the caret after b.
167  6 textArea.sendKeys("b", Keys.RETURN, "c", Keys.ARROW_LEFT, Keys.ARROW_LEFT);
168  6 getSelenium().click(buttonLocator);
169    // Move the caret after c, type d and e, then select d.
170  6 textArea.sendKeys(Keys.PAGE_DOWN, Keys.END, "de", Keys.ARROW_LEFT, Keys.chord(Keys.SHIFT, Keys.ARROW_LEFT));
171  6 getSelenium().click(buttonLocator);
172  6 if (defaultText.isEmpty()) {
173  1 assertEquals("a" + format + "b" + format + "\nc" + format + "de", textArea.getAttribute("value"));
174    } else {
175  5 assertEquals(
176    String.format("a" + format + "b" + format + "\nc" + format + "e", defaultText, defaultText, "d"),
177    textArea.getAttribute("value"));
178    }
179    }
180    }