1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
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 |
|
|
34 |
|
|
35 |
|
@version |
36 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (64) |
Complexity: 12 |
Complexity Density: 0.24 |
|
37 |
|
public class WikiEditorTest extends AbstractXWikiTestCase |
38 |
|
{ |
39 |
|
private static final String SYNTAX = "xwiki/2.1"; |
40 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
41 |
1 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
49 |
1 |
@Test... |
50 |
|
public void testBoldButton() |
51 |
|
{ |
52 |
1 |
testToolBarButton("Bold", "**%s**", "Text in Bold"); |
53 |
|
} |
54 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
55 |
1 |
@Test... |
56 |
|
public void testItalicsButton() |
57 |
|
{ |
58 |
1 |
testToolBarButton("Italics", "//%s//", "Text in Italics"); |
59 |
|
} |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
61 |
1 |
@Test... |
62 |
|
public void testUnderlineButton() |
63 |
|
{ |
64 |
1 |
testToolBarButton("Underline", "__%s__", "Text in Underline"); |
65 |
|
} |
66 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
67 |
1 |
@Test... |
68 |
|
public void testLinkButton() |
69 |
|
{ |
70 |
1 |
testToolBarButton("Internal Link", "[[%s]]", "Link Example"); |
71 |
|
} |
72 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
73 |
1 |
@Test... |
74 |
|
public void testHRButton() |
75 |
|
{ |
76 |
1 |
testToolBarButton("Horizontal ruler", "\n----\n", ""); |
77 |
|
} |
78 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
79 |
1 |
@Test... |
80 |
|
public void testImageButton() |
81 |
|
{ |
82 |
1 |
testToolBarButton("Attached Image", "[[image:%s]]", "example.jpg"); |
83 |
|
} |
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
89 |
1 |
@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 |
|
|
103 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
104 |
1 |
@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 |
|
|
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 |
|
|
122 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
123 |
1 |
@Test... |
124 |
|
public void testMinorEdit() |
125 |
|
{ |
126 |
1 |
try { |
127 |
1 |
editInWikiEditor("Test", "MinorEdit", SYNTAX); |
128 |
|
|
129 |
|
|
130 |
1 |
setFieldValue("content", "version=1.2"); |
131 |
|
|
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 |
|
|
153 |
|
|
154 |
|
@param |
155 |
|
@param |
156 |
|
@param |
157 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 2 |
Complexity Density: 0.15 |
|
158 |
6 |
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 |
|
|
167 |
6 |
textArea.sendKeys("b", Keys.RETURN, "c", Keys.ARROW_LEFT, Keys.ARROW_LEFT); |
168 |
6 |
getSelenium().click(buttonLocator); |
169 |
|
|
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 |
|
} |