1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.test.ui; |
21 |
|
|
22 |
|
import java.util.HashMap; |
23 |
|
import java.util.Map; |
24 |
|
|
25 |
|
import org.junit.Assert; |
26 |
|
import org.junit.Rule; |
27 |
|
import org.junit.Test; |
28 |
|
import org.xwiki.administration.test.po.AdministrationPage; |
29 |
|
import org.xwiki.administration.test.po.LocalizationAdministrationSectionPage; |
30 |
|
import org.xwiki.model.reference.LocalDocumentReference; |
31 |
|
import org.xwiki.test.ui.browser.IgnoreBrowser; |
32 |
|
import org.xwiki.test.ui.browser.IgnoreBrowsers; |
33 |
|
import org.xwiki.test.ui.po.ViewPage; |
34 |
|
import org.xwiki.test.ui.po.editor.WYSIWYGEditPage; |
35 |
|
import org.xwiki.test.ui.po.editor.WikiEditPage; |
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
@version |
41 |
|
@since |
42 |
|
|
|
|
| 92.9% |
Uncovered Elements: 4 (56) |
Complexity: 8 |
Complexity Density: 0.17 |
|
43 |
|
public class SectionTest extends AbstractTest |
44 |
|
{ |
45 |
|
@Rule |
46 |
|
public AdminAuthenticationRule adminAuthenticationRule = new AdminAuthenticationRule(getUtil()); |
47 |
|
|
|
|
| 63.6% |
Uncovered Elements: 4 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
48 |
3 |
private ViewPage createTestPages(String syntaxId)... |
49 |
|
{ |
50 |
3 |
if (syntaxId.equalsIgnoreCase("xwiki/1.0")) { |
51 |
0 |
getUtil().createPage("Test", "SectionEditing", "1 Section1\nContent1\n\n" |
52 |
|
+ "1 Section2\nContent2\n\n1.1 Section3\nContent3\n\n" |
53 |
|
+ "1 Section4\nContent4", "section test in " + syntaxId, syntaxId); |
54 |
|
|
55 |
3 |
} else if (syntaxId.startsWith("xwiki/2.")) { |
56 |
3 |
getUtil().createPage("Test", "SectionEditingIncluded", "== Section4 ==\n" + |
57 |
|
"Content4\n" + |
58 |
|
"\n" + |
59 |
|
"{{velocity wiki=true}}\n" + |
60 |
|
"#foreach($h in ['5', '6'])\n" + |
61 |
|
"== Section$h ==\n" + |
62 |
|
"Content$h\n" + |
63 |
|
"#end\n" + |
64 |
|
"{{velocity}}", "section test included in " + syntaxId, syntaxId); |
65 |
|
|
66 |
3 |
getUtil().createPage("Test", "SectionEditing", "= Section1 =\nContent1\n\n" |
67 |
|
+ "= Section2 =\nContent2\n\n== Section3 ==\nContent3\n\n" |
68 |
|
+ "{{include document='Test.SectionEditingIncluded'/}}\n\n" + "= Section7 =\nContent7", |
69 |
|
"section test in " + syntaxId, syntaxId); |
70 |
|
} else { |
71 |
0 |
throw new RuntimeException("Unhandled syntax [" + syntaxId + "]"); |
72 |
|
} |
73 |
|
|
74 |
3 |
return new ViewPage(); |
75 |
|
} |
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
85 |
1 |
@Test... |
86 |
|
@IgnoreBrowsers({ |
87 |
|
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"), |
88 |
|
@IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177") |
89 |
|
}) |
90 |
|
public void testSectionEditInWikiEditorWhenSyntax2x() |
91 |
|
{ |
92 |
1 |
testSectionEditInWikiEditorWhenSyntax2x("xwiki/2.0"); |
93 |
1 |
testSectionEditInWikiEditorWhenSyntax2x("xwiki/2.1"); |
94 |
|
} |
95 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
|
96 |
2 |
private void testSectionEditInWikiEditorWhenSyntax2x(String syntaxId)... |
97 |
|
{ |
98 |
2 |
ViewPage vp = createTestPages(syntaxId); |
99 |
|
|
100 |
|
|
101 |
2 |
WYSIWYGEditPage wysiwygEditPage = vp.editSection(2); |
102 |
2 |
wysiwygEditPage.waitUntilPageIsLoaded(); |
103 |
2 |
Assert.assertEquals("Section2\nContent2\nSection3\nContent3\nSection4\nContent4\nSection5\nContent5\n" |
104 |
|
+ "Section6\nContent6", wysiwygEditPage.getContent()); |
105 |
|
|
106 |
|
|
107 |
2 |
WikiEditPage wikiEditPage = wysiwygEditPage.editWiki(); |
108 |
2 |
Assert.assertEquals("= Section2 = Content2 == Section3 == Content3 " |
109 |
|
+ "{{include document=\"Test.SectionEditingIncluded\"/}}", wikiEditPage.getContent()); |
110 |
2 |
vp = wikiEditPage.clickCancel(); |
111 |
|
|
112 |
|
|
113 |
2 |
wikiEditPage = vp.editSection(3).editWiki(); |
114 |
2 |
Assert.assertEquals("== Section3 == Content3 {{include document=\"Test.SectionEditingIncluded\"/}}", |
115 |
|
wikiEditPage.getContent()); |
116 |
2 |
vp = wikiEditPage.clickCancel(); |
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
2 |
wikiEditPage = vp.editSection(4).editWiki(); |
122 |
2 |
Assert.assertEquals("= Section7 = Content7", wikiEditPage.getContent()); |
123 |
|
} |
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
129 |
1 |
@Test... |
130 |
|
@IgnoreBrowsers({ |
131 |
|
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"), |
132 |
|
@IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177") |
133 |
|
}) |
134 |
|
public void testSectionSaveDoesNotOverwriteTheWholeContentWhenSyntax20() |
135 |
|
{ |
136 |
1 |
ViewPage vp = createTestPages("xwiki/2.0"); |
137 |
1 |
vp.editSection(4).editWiki().clickSaveAndView(); |
138 |
1 |
WikiEditPage wep = vp.editWiki(); |
139 |
1 |
Assert.assertEquals("= Section1 = Content1 = Section2 = Content2 == Section3 == Content3 " |
140 |
|
+ "{{include document=\"Test.SectionEditingIncluded\"/}} = Section7 = Content7", wep.getContent()); |
141 |
|
} |
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
@see |
147 |
|
|
148 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
149 |
1 |
@Test... |
150 |
|
public void testSectionSaveDoesNotOverwriteTheTitle() throws Exception |
151 |
|
{ |
152 |
1 |
LocalDocumentReference pageReference = new LocalDocumentReference(getTestClassName(), getTestMethodName()); |
153 |
|
|
154 |
|
|
155 |
1 |
setLanguageSettings(false, "en", "en"); |
156 |
1 |
getUtil().rest().delete(pageReference); |
157 |
1 |
getUtil().rest().savePage(pageReference, "Original content", "Original title"); |
158 |
|
|
159 |
1 |
try { |
160 |
|
|
161 |
1 |
setLanguageSettings(true, "en", "en,fr"); |
162 |
1 |
Map<String, String> parameters = new HashMap<String, String>(); |
163 |
1 |
parameters.put("language", "fr"); |
164 |
1 |
parameters.put("title", "Translated title"); |
165 |
1 |
parameters.put("content", "= Chapter 1 =\n\n Once upon a time ..."); |
166 |
1 |
getUtil().gotoPage(pageReference, "save", parameters); |
167 |
|
|
168 |
|
|
169 |
1 |
setLanguageSettings(false, "fr", "fr"); |
170 |
|
|
171 |
|
|
172 |
1 |
getUtil().gotoPage(pageReference, "edit", "editor=wiki§ion=1"); |
173 |
1 |
Assert.assertEquals("Translated title", new WikiEditPage().clickSaveAndView().getDocumentTitle()); |
174 |
|
} finally { |
175 |
|
|
176 |
1 |
setLanguageSettings(false, "en", "en"); |
177 |
|
} |
178 |
|
} |
179 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
180 |
4 |
private void setLanguageSettings(boolean isMultiLingual, String defaultLanguage, String supportedLanguages)... |
181 |
|
{ |
182 |
4 |
AdministrationPage adminPage = AdministrationPage.gotoPage(); |
183 |
4 |
LocalizationAdministrationSectionPage localizationSection = adminPage.clickLocalizationSection(); |
184 |
4 |
localizationSection.setMultiLingual(isMultiLingual); |
185 |
4 |
localizationSection.setDefaultLanguage(defaultLanguage); |
186 |
4 |
localizationSection.setSupportedLanguages(supportedLanguages); |
187 |
4 |
localizationSection.clickSave(); |
188 |
|
} |
189 |
|
} |