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 org.junit.Test; |
23 |
|
import org.xwiki.test.selenium.framework.AbstractXWikiTestCase; |
24 |
|
|
25 |
|
import static org.junit.Assert.*; |
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
@version |
31 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (183) |
Complexity: 30 |
Complexity Density: 0.19 |
|
32 |
|
public class UsersGroupsRightsManagementTest extends AbstractXWikiTestCase |
33 |
|
{ |
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
42 |
1 |
@Test... |
43 |
|
public void testCreateAndDeleteGroup() |
44 |
|
{ |
45 |
|
|
46 |
1 |
deleteGroup("XWikiNewGroup", true); |
47 |
1 |
createGroup("XWikiNewGroup"); |
48 |
|
|
49 |
|
|
50 |
1 |
assertEquals("Group XWikiNewGroup which is empty print more than 0 members", 0, |
51 |
|
getGroupMembersCount("XWikiNewGroup")); |
52 |
|
|
53 |
|
|
54 |
1 |
openGlobalRightsPage(); |
55 |
1 |
clickGroupsRadioButton(); |
56 |
1 |
clickViewRightsCheckbox("XWikiNewGroup", "allow"); |
57 |
|
|
58 |
|
|
59 |
1 |
createPage("Test", "TestCreateAndDeleteGroup", "whatever"); |
60 |
1 |
clickEditPageAccessRights(); |
61 |
1 |
clickGroupsRadioButton(); |
62 |
1 |
clickCommentRightsCheckbox("XWikiNewGroup", "allow"); |
63 |
|
|
64 |
|
|
65 |
1 |
deleteGroup("XWikiNewGroup", false); |
66 |
|
|
67 |
|
|
68 |
1 |
open("XWiki", "XWikiPreferences", "edit", "editor=object"); |
69 |
1 |
assertTextNotPresent("XWikiNewGroup"); |
70 |
1 |
open("Test", "TestCreateAndDeleteGroup", "edit", "editor=object"); |
71 |
1 |
assertTextNotPresent("XWikiNewGroup"); |
72 |
|
} |
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
77 |
1 |
@Test... |
78 |
|
public void testCreateGroupWhenGroupAlreadyExists() |
79 |
|
{ |
80 |
1 |
open("XWiki", "testCreateGroupWhenGroupAlreadyExists", "edit", "editor=wiki"); |
81 |
1 |
clickEditSaveAndView(); |
82 |
1 |
openGroupsPage(); |
83 |
1 |
clickLinkWithText("Add new group", false); |
84 |
1 |
waitForLightbox("Create new group".toUpperCase()); |
85 |
1 |
setFieldValue("newgroupi", "testCreateGroupWhenGroupAlreadyExists"); |
86 |
1 |
getSelenium().click("//input[@value='Create group']"); |
87 |
|
|
88 |
|
|
89 |
1 |
waitForAlert(); |
90 |
1 |
assertEquals("testCreateGroupWhenGroupAlreadyExists cannot be used for the " |
91 |
|
+ "group name, as another page with this name already exists.", getSelenium().getAlert()); |
92 |
|
} |
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
101 |
1 |
@Test... |
102 |
|
public void testCreateAndDeleteUser() |
103 |
|
{ |
104 |
|
|
105 |
1 |
deleteUser("XWikiNewUser", true); |
106 |
1 |
createUser("XWikiNewUser", "XWikiNewUser"); |
107 |
|
|
108 |
|
|
109 |
1 |
open("XWiki", "XWikiAllGroup"); |
110 |
1 |
waitForGroupUsersLiveTable(); |
111 |
1 |
assertTextPresent("XWiki.XWikiNewUser"); |
112 |
|
|
113 |
|
|
114 |
1 |
deleteUser("XWikiNewUser", false); |
115 |
|
|
116 |
|
|
117 |
1 |
open("XWiki", "XWikiAllGroup"); |
118 |
1 |
waitForGroupUsersLiveTable(); |
119 |
1 |
assertTextNotPresent("XWiki.XWikiNewUser"); |
120 |
|
} |
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
125 |
1 |
@Test... |
126 |
|
public void testCreateNonAsciiUser() |
127 |
|
{ |
128 |
|
|
129 |
1 |
deleteUser("AccentUser", true); |
130 |
|
|
131 |
|
|
132 |
1 |
createUser("AccentUser", "AccentUser", "a\u00e9b", "c\u00e0d"); |
133 |
|
|
134 |
|
|
135 |
1 |
assertTextPresent("AccentUser"); |
136 |
|
|
137 |
1 |
assertTextPresent("a\u00e9b"); |
138 |
1 |
assertTextPresent("c\u00e0d"); |
139 |
|
} |
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
145 |
1 |
@Test... |
146 |
|
public void testGroupRights() |
147 |
|
{ |
148 |
1 |
String username = "TestUser"; |
149 |
|
|
150 |
1 |
String groupname = "Test Group"; |
151 |
|
|
152 |
|
|
153 |
1 |
deleteUser(username, true); |
154 |
1 |
deleteGroup(groupname, true); |
155 |
|
|
156 |
|
|
157 |
1 |
createUser(username, username); |
158 |
1 |
createGroup(groupname); |
159 |
1 |
addUserToGroup(username, groupname); |
160 |
1 |
createPage("Test", "TestGroupRights", "Some content"); |
161 |
|
|
162 |
|
|
163 |
1 |
open("Test", "TestGroupRights", "edit", "editor=rights"); |
164 |
1 |
clickGroupsRadioButton(); |
165 |
|
|
166 |
1 |
clickViewRightsCheckbox(groupname, "allow"); |
167 |
1 |
clickViewRightsCheckbox(groupname, "deny1"); |
168 |
|
|
169 |
|
|
170 |
1 |
open("Test", "TestGroupRights"); |
171 |
1 |
assertTextPresent("Some content"); |
172 |
|
|
173 |
|
|
174 |
1 |
login(username, username, false); |
175 |
1 |
open("Test", "TestGroupRights"); |
176 |
1 |
assertTextPresent("not allowed"); |
177 |
|
|
178 |
|
|
179 |
1 |
loginAsAdmin(); |
180 |
1 |
deleteUser(username, false); |
181 |
1 |
deleteGroup(groupname, false); |
182 |
|
} |
183 |
|
|
184 |
|
|
185 |
|
|
186 |
|
|
187 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (21) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
188 |
1 |
@Test... |
189 |
|
public void testAddGroupToGroup() |
190 |
|
{ |
191 |
1 |
String group = "GroupWithGroup"; |
192 |
1 |
createGroup(group); |
193 |
1 |
openGroupsPage(); |
194 |
1 |
String xpath = "//tbody/tr[td/a='" + group + "']/td[3]/img[@title='Edit']"; |
195 |
1 |
System.out.println("XPATH: " + xpath); |
196 |
1 |
waitForCondition("selenium.isElementPresent(\"" + xpath + "\")"); |
197 |
1 |
getSelenium().click("//tbody/tr[td/a=\"" + group + "\"]/td[3]/img[@title=\"Edit\"]"); |
198 |
1 |
waitForLightbox("SUBGROUPS TO ADD"); |
199 |
1 |
setFieldValue("groupInput", "XWiki.XWikiAllGroup"); |
200 |
1 |
clickLinkWithLocator("addMembers", false); |
201 |
1 |
String xpathPrefix = "//div[@id='lb-content']/div/div/table/tbody/tr/td/table/tbody/tr"; |
202 |
1 |
String adminGroupXPath = |
203 |
|
xpathPrefix + "/td[contains(@class, 'member')]/a[@href='/xwiki/bin/view/XWiki/XWikiAllGroup']"; |
204 |
|
|
205 |
|
|
206 |
|
|
207 |
1 |
waitForCondition("selenium.isElementPresent(\"" + adminGroupXPath + "\")"); |
208 |
|
|
209 |
1 |
assertElementNotPresent(xpathPrefix + "/td[contains(@class, 'member')]/a[@href='/xwiki/bin/view/XWiki/Admin']"); |
210 |
1 |
clickLinkWithLocator("lb-close"); |
211 |
|
|
212 |
|
|
213 |
1 |
clickLinkWithText(group); |
214 |
1 |
clickEditPageInlineForm(); |
215 |
1 |
setFieldValue("groupInput", "XWiki.XWikiAdminGroup"); |
216 |
1 |
clickLinkWithLocator("addMembers", false); |
217 |
1 |
waitForTextContains("id=groupusers", "XWiki.XWikiAdminGroup"); |
218 |
|
|
219 |
|
|
220 |
1 |
deleteGroup(group, false); |
221 |
|
} |
222 |
|
|
223 |
|
|
224 |
|
|
225 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
226 |
1 |
@Test... |
227 |
|
public void testAddUserToGroup() |
228 |
|
{ |
229 |
|
|
230 |
1 |
deleteUser("XWikiTestUser", true); |
231 |
1 |
createUser("XWikiTestUser", "XWikiTestUser"); |
232 |
|
|
233 |
1 |
addUserToGroup("XWikiTestUser", "XWikiAdminGroup"); |
234 |
|
|
235 |
1 |
deleteUser("XWikiTestUser", true); |
236 |
|
} |
237 |
|
|
238 |
|
|
239 |
|
|
240 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
241 |
1 |
@Test... |
242 |
|
public void testFilteringOnGroupSheet() |
243 |
|
{ |
244 |
1 |
openGroupsPage(); |
245 |
1 |
String rowXPath = "//td[contains(@class, 'member')]/a[@href='/xwiki/bin/view/XWiki/Admin']"; |
246 |
1 |
this.clickLinkWithText("XWikiAdminGroup"); |
247 |
1 |
this.waitForCondition("selenium.isElementPresent(\"" + rowXPath + "\")"); |
248 |
|
|
249 |
1 |
this.getSelenium().focus("member"); |
250 |
1 |
this.getSelenium().typeKeys("member", "zzz"); |
251 |
1 |
this.waitForCondition("!selenium.isElementPresent(\"" + rowXPath + "\")"); |
252 |
|
|
253 |
1 |
this.getSelenium().focus("member"); |
254 |
|
|
255 |
1 |
this.getSelenium().typeKeys("member", "\b\b\bAd"); |
256 |
1 |
this.waitForCondition("selenium.isElementPresent(\"" + rowXPath + "\")"); |
257 |
|
} |
258 |
|
|
259 |
|
|
260 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
261 |
3 |
private void createGroup(String groupname)... |
262 |
|
{ |
263 |
3 |
openGroupsPage(); |
264 |
3 |
clickLinkWithText("Add new group", false); |
265 |
3 |
waitForLightbox("Create new group".toUpperCase()); |
266 |
3 |
setFieldValue("newgroupi", groupname); |
267 |
3 |
clickLinkWithXPath("//input[@value='Create group']", true); |
268 |
3 |
waitForTextContains("id=groupstable", groupname); |
269 |
|
} |
270 |
|
|
271 |
|
|
272 |
|
@param |
273 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 4 |
Complexity Density: 0.57 |
|
274 |
5 |
private void deleteGroup(String groupname, boolean deleteOnlyIfExists)... |
275 |
|
{ |
276 |
5 |
if (!deleteOnlyIfExists || (deleteOnlyIfExists && isExistingPage("XWiki", groupname))) { |
277 |
3 |
openGroupsPage(); |
278 |
3 |
getSelenium().chooseOkOnNextConfirmation(); |
279 |
3 |
clickLinkWithLocator("//tbody/tr[td/a='" + groupname + "']//img[@title='Delete']", false); |
280 |
3 |
waitForConfirmation(); |
281 |
3 |
assertEquals("The group XWiki." + groupname + " will be deleted. Are you sure you want to proceed?", |
282 |
|
getSelenium().getConfirmation()); |
283 |
|
|
284 |
3 |
waitForCondition("!selenium.isElementPresent('//tbody/tr[td/a=\"" + groupname + "\"]')"); |
285 |
|
} |
286 |
|
} |
287 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
288 |
3 |
private void createUser(String login, String pwd)... |
289 |
|
{ |
290 |
3 |
createUser(login, pwd, "New", "User"); |
291 |
|
} |
292 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
|
293 |
4 |
private void createUser(String login, String pwd, String fname, String lname)... |
294 |
|
{ |
295 |
4 |
openUsersPage(); |
296 |
4 |
clickLinkWithText("Add new user", false); |
297 |
4 |
waitForElement("//input[@id='register_first_name']"); |
298 |
4 |
setFieldValue("register_first_name", fname); |
299 |
4 |
setFieldValue("register_last_name", lname); |
300 |
4 |
setFieldValue("xwikiname", login); |
301 |
4 |
setFieldValue("register_password", pwd); |
302 |
4 |
setFieldValue("register2_password", pwd); |
303 |
4 |
setFieldValue("register_email", "new.user@xwiki.org"); |
304 |
4 |
getSelenium().click("//input[@value='Save']"); |
305 |
|
|
306 |
4 |
waitForTextContains("id=userstable", login); |
307 |
|
} |
308 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 4 |
Complexity Density: 0.67 |
|
309 |
7 |
private void deleteUser(String login, boolean deleteOnlyIfExists)... |
310 |
|
{ |
311 |
7 |
if (!deleteOnlyIfExists || (deleteOnlyIfExists && isExistingPage("XWiki", login))) { |
312 |
3 |
openUsersPage(); |
313 |
3 |
clickLinkWithLocator("//tbody/tr[td/a='" + login + "']//img[@title='Delete']", false); |
314 |
3 |
waitForConfirmation(); |
315 |
3 |
assertEquals("The user XWiki." + login + " will be deleted and removed from all groups he belongs to. " |
316 |
|
+ "Are you sure you want to proceed?", getSelenium().getConfirmation()); |
317 |
|
|
318 |
3 |
waitForCondition("!selenium.isElementPresent('//tbody/tr[td/a=\"" + login + "\"]')"); |
319 |
|
} |
320 |
|
} |
321 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
|
322 |
2 |
private void addUserToGroup(String user, String group)... |
323 |
|
{ |
324 |
2 |
openGroupsPage(); |
325 |
2 |
String xpath = "//tbody/tr[td/a='" + group + "']/td[3]/img[@title='Edit']"; |
326 |
2 |
waitForCondition("selenium.isElementPresent(\"" + xpath + "\")"); |
327 |
2 |
getSelenium().click(xpath); |
328 |
2 |
waitForLightbox("USERS TO ADD"); |
329 |
2 |
setFieldValue("userInput", "XWiki." + user); |
330 |
2 |
clickLinkWithLocator("addMembers", false); |
331 |
|
|
332 |
2 |
String xpathPrefix = "//div[@id='lb-content']/div/div/table/tbody/tr/td/table/tbody/tr"; |
333 |
2 |
String newGroupMemberXPath = |
334 |
|
xpathPrefix + "/td[contains(@class, 'member')]/a[@href='/xwiki/bin/view/XWiki/" + user + "']"; |
335 |
|
|
336 |
|
|
337 |
|
|
338 |
2 |
waitForCondition("selenium.isElementPresent(\"" + newGroupMemberXPath + "\")"); |
339 |
|
|
340 |
|
|
341 |
2 |
clickLinkWithLocator("lb-close"); |
342 |
2 |
open("XWiki", group); |
343 |
2 |
waitForGroupUsersLiveTable(); |
344 |
2 |
assertTextPresent(user); |
345 |
|
} |
346 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
347 |
7 |
private void waitForLightbox(String lightboxName)... |
348 |
|
{ |
349 |
7 |
waitForBodyContains(lightboxName); |
350 |
|
} |
351 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
352 |
3 |
private void clickGroupsRadioButton()... |
353 |
|
{ |
354 |
3 |
clickLinkWithXPath("//input[@name='uorg' and @value='groups']", false); |
355 |
|
} |
356 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
357 |
1 |
private void openGlobalRightsPage()... |
358 |
|
{ |
359 |
1 |
openAdministrationPage(); |
360 |
1 |
clickLinkWithText("Rights"); |
361 |
|
} |
362 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
363 |
11 |
private void openGroupsPage()... |
364 |
|
{ |
365 |
11 |
openAdministrationPage(); |
366 |
11 |
clickLinkWithText("Groups"); |
367 |
11 |
waitForLiveTable("groupstable"); |
368 |
|
} |
369 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
370 |
7 |
private void openUsersPage()... |
371 |
|
{ |
372 |
|
|
373 |
|
|
374 |
|
|
375 |
7 |
openAdministrationPage(); |
376 |
7 |
clickLinkWithText("Users"); |
377 |
7 |
waitForLiveTable("userstable"); |
378 |
|
} |
379 |
|
|
380 |
|
|
381 |
|
@return |
382 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
383 |
1 |
private int getGroupMembersCount(String groupname)... |
384 |
|
{ |
385 |
1 |
return Integer.parseInt(getSelenium().getText("//tbody/tr[td/a=\"" + groupname + "\"]/td[2]")); |
386 |
|
} |
387 |
|
|
388 |
|
|
389 |
|
@param |
390 |
|
|
391 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
392 |
3 |
private void clickViewRightsCheckbox(String groupOrUserName, String actionToVerify)... |
393 |
|
{ |
394 |
3 |
clickRightsCheckbox(groupOrUserName, actionToVerify, 2); |
395 |
|
} |
396 |
|
|
397 |
|
|
398 |
|
@param |
399 |
|
|
400 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
401 |
1 |
private void clickCommentRightsCheckbox(String groupOrUserName, String actionToVerify)... |
402 |
|
{ |
403 |
1 |
clickRightsCheckbox(groupOrUserName, actionToVerify, 3); |
404 |
|
} |
405 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
406 |
4 |
private void clickRightsCheckbox(String groupOrUserName, String actionToVerify, int positionInTd)... |
407 |
|
{ |
408 |
4 |
String xpath = "//tbody/tr[td/a='" + groupOrUserName + "']/td[" + positionInTd + "]/img"; |
409 |
4 |
clickLinkWithXPath(xpath, false); |
410 |
|
|
411 |
4 |
waitForCondition("selenium.isElementPresent(\"" + xpath + "[contains(@src, '" + actionToVerify + ".png')]\")"); |
412 |
|
} |
413 |
|
|
414 |
|
|
415 |
|
|
416 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
417 |
4 |
private void waitForGroupUsersLiveTable()... |
418 |
|
{ |
419 |
4 |
waitForLiveTable("groupusers"); |
420 |
|
} |
421 |
|
} |