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.Arrays; |
23 |
|
import java.util.HashSet; |
24 |
|
import java.util.List; |
25 |
|
import java.util.Locale; |
26 |
|
|
27 |
|
import org.junit.AfterClass; |
28 |
|
import org.junit.Assert; |
29 |
|
import org.junit.Before; |
30 |
|
import org.junit.Rule; |
31 |
|
import org.junit.Test; |
32 |
|
import org.openqa.selenium.By; |
33 |
|
import org.openqa.selenium.WebElement; |
34 |
|
import org.xwiki.administration.test.po.AdministrationPage; |
35 |
|
import org.xwiki.administration.test.po.LocalizationAdministrationSectionPage; |
36 |
|
import org.xwiki.model.reference.LocalDocumentReference; |
37 |
|
import org.xwiki.rest.model.jaxb.Page; |
38 |
|
import org.xwiki.test.ui.browser.IgnoreBrowser; |
39 |
|
import org.xwiki.test.ui.po.ViewPage; |
40 |
|
import org.xwiki.test.ui.po.editor.WikiEditPage; |
41 |
|
|
42 |
|
import static org.junit.Assert.assertEquals; |
43 |
|
import static org.junit.Assert.assertTrue; |
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
@version |
49 |
|
@since |
50 |
|
|
|
|
| 65.1% |
Uncovered Elements: 29 (83) |
Complexity: 14 |
Complexity Density: 0.21 |
|
51 |
|
public class LanguageTest extends AbstractTest |
52 |
|
{ |
53 |
|
@Rule |
54 |
|
public AdminAuthenticationRule adminAuthenticationRule = new AdminAuthenticationRule(getUtil()); |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
59 |
1 |
@AfterClass... |
60 |
|
public static void afterClass() |
61 |
|
{ |
62 |
1 |
setLanguageSettings(false, "en"); |
63 |
|
} |
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
68 |
5 |
@Before... |
69 |
|
public void before() throws Exception |
70 |
|
{ |
71 |
5 |
setLanguageSettings(false, "en"); |
72 |
|
} |
73 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
74 |
1 |
@Test... |
75 |
|
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason = "See http://jira.xwiki.org/browse/XE-1146") |
76 |
|
public void testChangeLanguageInMonolingualModeUsingTheAdministrationPreference() |
77 |
|
{ |
78 |
1 |
WikiEditPage edit = WikiEditPage.gotoPage("Test", "LanguageTest"); |
79 |
1 |
edit.setContent("{{velocity}}context = ($xcontext.language), doc = ($doc.language), " |
80 |
|
+ "default = ($doc.defaultLanguage), tdoc = ($tdoc.language), " |
81 |
|
+ "tdocdefault = ($tdoc.defaultLanguage){{/velocity}}"); |
82 |
1 |
ViewPage vp = edit.clickSaveAndView(); |
83 |
|
|
84 |
|
|
85 |
1 |
Assert.assertEquals("Invalid content", vp.getContent(), |
86 |
|
"context = (en), doc = (), default = (en), tdoc = (), tdocdefault = (en)"); |
87 |
|
|
88 |
|
|
89 |
1 |
AdministrationPage adminPage = AdministrationPage.gotoPage(); |
90 |
1 |
LocalizationAdministrationSectionPage sectionPage = adminPage.clickLocalizationSection(); |
91 |
1 |
sectionPage.setDefaultLanguage("fr"); |
92 |
1 |
sectionPage.clickSave(); |
93 |
|
|
94 |
|
|
95 |
1 |
vp = getUtil().gotoPage("Test", "LanguageTest"); |
96 |
1 |
Assert.assertTrue("Page not in French!", isPageInFrench()); |
97 |
1 |
Assert.assertEquals("Invalid content", vp.getContent(), |
98 |
|
"context = (fr), doc = (), default = (en), tdoc = (), tdocdefault = (en)"); |
99 |
|
} |
100 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
101 |
1 |
@Test... |
102 |
|
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason = "See http://jira.xwiki.org/browse/XE-1146") |
103 |
|
public void testPassingLanguageInRequestHasNoEffectInMonoligualMode() |
104 |
|
{ |
105 |
1 |
getUtil().gotoPage("Main", "WebHome", "view", "language=fr"); |
106 |
1 |
Assert.assertTrue("Page not in English!", isPageInEnglish()); |
107 |
|
} |
108 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
109 |
1 |
@Test... |
110 |
|
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason = "See http://jira.xwiki.org/browse/XE-1146") |
111 |
|
public void testChangeLanguageInMultilingualModeUsingTheLanguageRequestParameter() |
112 |
|
{ |
113 |
1 |
setLanguageSettings(true, "en"); |
114 |
|
|
115 |
1 |
getUtil().gotoPage("Main", "WebHome", "view", "language=fr"); |
116 |
1 |
Assert.assertTrue("Page not in French!", isPageInFrench()); |
117 |
|
} |
118 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
119 |
1 |
@Test... |
120 |
|
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason = "See http://jira.xwiki.org/browse/XE-1146") |
121 |
|
public void testHeaderCorrectLanguage() |
122 |
|
{ |
123 |
1 |
setLanguageSettings(true, "en"); |
124 |
|
|
125 |
|
|
126 |
1 |
getUtil().gotoPage("Main", "Test", "view", "language=default"); |
127 |
1 |
checkLanguageTagsArePresent("en"); |
128 |
|
|
129 |
1 |
getUtil().gotoPage("Main", "Test", "view", "language=fr"); |
130 |
1 |
checkLanguageTagsArePresent("fr"); |
131 |
|
} |
132 |
|
|
|
|
| 0% |
Uncovered Elements: 25 (25) |
Complexity: 1 |
Complexity Density: 0.04 |
3FAIL
|
|
133 |
0 |
@Test... |
134 |
|
public void testTranslateDocument() throws Exception |
135 |
|
{ |
136 |
0 |
LocalDocumentReference referenceDEFAULT = new LocalDocumentReference("LanguageTest", "Page"); |
137 |
0 |
LocalDocumentReference referenceFR = new LocalDocumentReference(referenceDEFAULT, Locale.FRENCH); |
138 |
|
|
139 |
|
|
140 |
0 |
getUtil().rest().delete(referenceFR); |
141 |
0 |
getUtil().rest().delete(referenceDEFAULT); |
142 |
|
|
143 |
|
|
144 |
0 |
setLanguageSettings(true, "en", Arrays.asList("en", "fr")); |
145 |
|
|
146 |
|
|
147 |
0 |
ViewPage viewPage = getUtil().createPage("LanguageTest", "Page", "en content", "en title"); |
148 |
|
|
149 |
|
|
150 |
0 |
WikiEditPage editPage = viewPage.editWiki(); |
151 |
|
|
152 |
|
|
153 |
0 |
assertTrue(getDriver().hasElement(By.xpath("//strong[text()='You are editing the original page (en).']"))); |
154 |
|
|
155 |
0 |
assertEquals(Arrays.asList(Locale.FRENCH), editPage.getNotExistingLocales()); |
156 |
0 |
assertEquals(Arrays.asList(), editPage.getExistingLocales()); |
157 |
|
|
158 |
|
|
159 |
0 |
editPage = editPage.clickTranslate("fr"); |
160 |
0 |
editPage.setTitle("titre fr"); |
161 |
0 |
editPage.setContent("contenu fr"); |
162 |
|
|
163 |
0 |
viewPage = editPage.clickSaveAndView(); |
164 |
|
|
165 |
|
|
166 |
0 |
Page page = getUtil().rest().get(referenceFR); |
167 |
0 |
assertEquals("titre fr", page.getTitle()); |
168 |
0 |
assertEquals("contenu fr", page.getContent()); |
169 |
0 |
page = getUtil().rest().get(referenceDEFAULT); |
170 |
0 |
assertEquals("en title", page.getTitle()); |
171 |
0 |
assertEquals("en content", page.getContent()); |
172 |
|
|
173 |
|
|
174 |
0 |
assertEquals(new HashSet<>(Arrays.asList(Locale.ENGLISH, Locale.FRENCH)), new HashSet<>(viewPage.getLocales())); |
175 |
|
|
176 |
|
|
177 |
0 |
viewPage.clickLocale(Locale.ENGLISH); |
178 |
|
|
179 |
|
|
180 |
0 |
editPage = viewPage.editWiki(); |
181 |
|
|
182 |
0 |
assertEquals(Arrays.asList(), editPage.getNotExistingLocales()); |
183 |
0 |
assertEquals(Arrays.asList(Locale.FRENCH), editPage.getExistingLocales()); |
184 |
|
} |
185 |
|
|
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
@param |
190 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
191 |
2 |
private void checkLanguageTagsArePresent(String language)... |
192 |
|
{ |
193 |
2 |
WebElement html = getDriver().findElement(By.tagName("html")); |
194 |
2 |
Assert.assertEquals(language, html.getAttribute("lang")); |
195 |
2 |
Assert.assertEquals(language, html.getAttribute("xml:lang")); |
196 |
|
|
197 |
2 |
ViewPage vp = new ViewPage(); |
198 |
2 |
Assert.assertEquals("locale=" + language, vp.getHTMLMetaDataValue("gwt:property")); |
199 |
|
|
200 |
2 |
Assert.assertEquals(language, vp.getHTMLMetaDataValue("language")); |
201 |
|
|
202 |
2 |
String content = getDriver().getPageSource(); |
203 |
2 |
Assert.assertTrue(content.contains("language=" + language)); |
204 |
|
} |
205 |
|
|
206 |
|
|
207 |
|
|
208 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
209 |
1 |
private boolean isPageInEnglish()... |
210 |
|
{ |
211 |
1 |
return getDriver().findElement(By.className("xdocLastModification")).getText().toLowerCase() |
212 |
|
.contains("last modified by"); |
213 |
|
} |
214 |
|
|
215 |
|
|
216 |
|
|
217 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
218 |
2 |
private boolean isPageInFrench()... |
219 |
|
{ |
220 |
2 |
return getDriver().findElement(By.className("xdocLastModification")).getText().toLowerCase() |
221 |
|
.contains("modifié par"); |
222 |
|
} |
223 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
224 |
8 |
private static void setLanguageSettings(boolean isMultiLingual, String defaultLanguage)... |
225 |
|
{ |
226 |
8 |
setLanguageSettings(isMultiLingual, defaultLanguage, null); |
227 |
|
} |
228 |
|
|
|
|
| 75% |
Uncovered Elements: 3 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
229 |
9 |
private static void setLanguageSettings(boolean isMultiLingual, String defaultLanguage,... |
230 |
|
List<String> supportedLanguages) |
231 |
|
{ |
232 |
9 |
AdministrationPage adminPage = AdministrationPage.gotoPage(); |
233 |
9 |
LocalizationAdministrationSectionPage sectionPage = adminPage.clickLocalizationSection(); |
234 |
9 |
sectionPage.setMultiLingual(isMultiLingual); |
235 |
9 |
if (defaultLanguage != null) { |
236 |
9 |
sectionPage.setDefaultLanguage(defaultLanguage); |
237 |
|
} |
238 |
8 |
if (supportedLanguages != null) { |
239 |
0 |
sectionPage.setSupportedLanguages(supportedLanguages); |
240 |
|
} |
241 |
9 |
sectionPage.clickSave(); |
242 |
|
} |
243 |
|
} |