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

File UserProfileTest.java

 

Code metrics

2
104
11
1
316
225
12
0.12
9.45
11
1.09

Classes

Class Line # Actions
UserProfileTest 43 104 0% 12 1
0.99145399.1%
 

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.user.test.ui;
21   
22    import org.apache.commons.lang.RandomStringUtils;
23    import org.junit.Assert;
24    import org.junit.Before;
25    import org.junit.Test;
26    import org.xwiki.test.ui.AbstractTest;
27    import org.xwiki.test.ui.browser.IgnoreBrowser;
28    import org.xwiki.test.ui.browser.IgnoreBrowsers;
29    import org.xwiki.test.ui.po.ViewPage;
30    import org.xwiki.user.test.po.ChangeAvatarPage;
31    import org.xwiki.user.test.po.ChangePasswordPage;
32    import org.xwiki.user.test.po.PreferencesEditPage;
33    import org.xwiki.user.test.po.PreferencesUserProfilePage;
34    import org.xwiki.user.test.po.ProfileEditPage;
35    import org.xwiki.user.test.po.ProfileUserProfilePage;
36   
37    /**
38    * Test the User Profile.
39    *
40    * @version $Id: d38d145d480731522045c500f24178806af4cfa0 $
41    * @since 2.4
42    */
 
43    public class UserProfileTest extends AbstractTest
44    {
45    private static final String IMAGE_NAME = "avatar.png";
46   
47    private static final String USER_FIRST_NAME = "User";
48   
49    private static final String USER_LAST_NAME = "of this Wiki";
50   
51    private static final String USER_COMPANY = "XWiki.org";
52   
53    private static final String USER_ABOUT = "This is some example text to type into the text area";
54   
55    private static final String USER_EMAIL = "webmaster@xwiki.org";
56   
57    private static final String USER_PHONE = "0000-000-000";
58   
59    private static final String USER_ADDRESS = "1600 No Street";
60   
61    private static final String USER_BLOG = "http://xwiki.org/";
62   
63    private static final String USER_BLOGFEED = "http://xwiki.org/feed";
64   
65    private static final String WYSIWYG_EDITOR = "Wysiwyg";
66   
67    private static final String TEXT_EDITOR = "Text";
68   
69    private static final String DEFAULT_EDITOR = "Text (Default)";
70   
71    private static final String SIMPLE_USER = "Simple";
72   
73    private static final String ADVANCED_USER = "Advanced";
74   
75    private static final String PASSWORD_1 = "password1";
76   
77    private static final String PASSWORD_2 = "password2";
78   
79    private static final String DEFAULT_PASSWORD = "testtest";
80   
81    private ProfileUserProfilePage customProfilePage;
82   
83    private String userName;
84   
 
85  10 toggle @Before
86    public void setUp()
87    {
88  10 getUtil().recacheSecretToken();
89  10 this.userName = getTestClassName() + getTestMethodName();
90  10 getUtil().createUserAndLogin(this.userName, DEFAULT_PASSWORD);
91   
92  10 this.customProfilePage = ProfileUserProfilePage.gotoPage(this.userName);
93    }
94   
95    /** Functionality check: changing profile information. */
 
96  1 toggle @Test
97    @IgnoreBrowsers({
98    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
99    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
100    })
101    public void testEditProfile()
102    {
103  1 ProfileEditPage profileEditPage = this.customProfilePage.editProfile();
104  1 profileEditPage.setUserFirstName(USER_FIRST_NAME);
105  1 profileEditPage.setUserLastName(USER_LAST_NAME);
106  1 profileEditPage.setUserCompany(USER_COMPANY);
107  1 profileEditPage.setUserAbout(USER_ABOUT);
108  1 profileEditPage.setUserEmail(USER_EMAIL);
109  1 profileEditPage.setUserPhone(USER_PHONE);
110  1 profileEditPage.setUserAddress(USER_ADDRESS);
111  1 profileEditPage.setUserBlog(USER_BLOG);
112  1 profileEditPage.setUserBlogFeed(USER_BLOGFEED);
113  1 profileEditPage.clickSaveAndView();
114   
115    // Check that the information was updated
116  1 Assert.assertEquals(USER_FIRST_NAME, this.customProfilePage.getUserFirstName());
117  1 Assert.assertEquals(USER_LAST_NAME, this.customProfilePage.getUserLastName());
118  1 Assert.assertEquals(USER_COMPANY, this.customProfilePage.getUserCompany());
119  1 Assert.assertEquals(USER_ABOUT, this.customProfilePage.getUserAbout());
120  1 Assert.assertEquals(USER_EMAIL, this.customProfilePage.getUserEmail());
121  1 Assert.assertEquals(USER_PHONE, this.customProfilePage.getUserPhone());
122  1 Assert.assertEquals(USER_ADDRESS, this.customProfilePage.getUserAddress());
123  1 Assert.assertEquals(USER_BLOG, this.customProfilePage.getUserBlog());
124  1 Assert.assertEquals(USER_BLOGFEED, this.customProfilePage.getUserBlogFeed());
125    }
126   
127    /** Functionality check: changing the profile picture. */
 
128  1 toggle @Test
129    @IgnoreBrowsers({
130    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
131    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
132    })
133    public void testChangeAvatarImage()
134    {
135  1 ChangeAvatarPage changeAvatarImage = this.customProfilePage.changeAvatarImage();
136  1 changeAvatarImage.setAvatarImage(IMAGE_NAME);
137  1 changeAvatarImage.submit();
138  1 Assert.assertEquals(IMAGE_NAME, this.customProfilePage.getAvatarImageName());
139    }
140   
141    /** Functionality check: changing the password. */
 
142  1 toggle @Test
143    @IgnoreBrowsers({
144    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
145    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
146    })
147    public void testChangePassword()
148    {
149    // Change the password
150  1 PreferencesUserProfilePage preferencesPage = this.customProfilePage.switchToPreferences();
151  1 ChangePasswordPage changePasswordPage = preferencesPage.changePassword();
152  1 String newPassword = RandomStringUtils.randomAlphanumeric(6);
153  1 changePasswordPage.changePassword(DEFAULT_PASSWORD, newPassword, newPassword);
154  1 changePasswordPage.submit();
155   
156    // Logout
157  1 getUtil().forceGuestUser();
158   
159    // Login with the new password and navigate to a page to verify that the user is logged in
160  1 getUtil().loginAndGotoPage(this.userName, newPassword,
161    getUtil().getURL(getTestClassName(), getTestMethodName()));
162  1 ViewPage vp = new ViewPage();
163  1 Assert.assertTrue(vp.isAuthenticated());
164  1 getUtil().recacheSecretToken();
165   
166    //Reset the password
167  1 getUtil().loginAsSuperAdminAndGotoPage(this.customProfilePage.getURL());
168   
169  1 preferencesPage = this.customProfilePage.switchToPreferences();
170  1 changePasswordPage = preferencesPage.changePassword();
171  1 changePasswordPage.changePasswordAsAdmin(DEFAULT_PASSWORD, DEFAULT_PASSWORD);
172  1 changePasswordPage.submit();
173  1 Assert.assertEquals("Your password has been successfully changed.", changePasswordPage.getSuccessMessage());
174    }
175   
176    /** Functionality check: changing the user type. */
 
177  1 toggle @Test
178    @IgnoreBrowsers({
179    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
180    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
181    })
182    public void testChangeUserProfile()
183    {
184  1 String timezone = "Europe/Paris";
185  1 PreferencesUserProfilePage preferencesPage = this.customProfilePage.switchToPreferences();
186  1 Assert.assertEquals("", preferencesPage.getTimezone());
187   
188    // Setting to Simple user and setting the timezone to Europe/Paris
189  1 PreferencesEditPage preferencesEditPage = preferencesPage.editPreferences();
190  1 preferencesEditPage.setSimpleUserType();
191  1 preferencesEditPage.setTimezone(timezone);
192  1 preferencesEditPage.clickSaveAndView();
193  1 preferencesPage = this.customProfilePage.switchToPreferences();
194  1 Assert.assertEquals(SIMPLE_USER, preferencesPage.getUserType());
195  1 Assert.assertEquals(timezone, preferencesPage.getTimezone());
196   
197    // Setting to Advanced user
198  1 preferencesEditPage = preferencesPage.editPreferences();
199  1 preferencesEditPage.setAdvancedUserType();
200  1 preferencesEditPage.clickSaveAndView();
201  1 this.customProfilePage.switchToPreferences();
202  1 Assert.assertEquals(ADVANCED_USER, preferencesPage.getUserType());
203    }
204   
205    /** Functionality check: changing the default editor. */
 
206  1 toggle @Test
207    @IgnoreBrowsers({
208    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
209    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
210    })
211    public void testChangeDefaultEditor()
212    {
213  1 PreferencesUserProfilePage preferencesPage = this.customProfilePage.switchToPreferences();
214   
215    // Setting to Text Editor
216  1 PreferencesEditPage preferencesEditPage = preferencesPage.editPreferences();
217  1 preferencesEditPage.setDefaultEditorText();
218  1 preferencesEditPage.clickSaveAndView();
219  1 preferencesPage = this.customProfilePage.switchToPreferences();
220  1 Assert.assertEquals(TEXT_EDITOR, preferencesPage.getDefaultEditor());
221   
222    // Setting to WYSIWYG Editor
223  1 this.customProfilePage = ProfileUserProfilePage.gotoPage(this.userName);
224  1 preferencesPage = this.customProfilePage.switchToPreferences();
225  1 preferencesEditPage = preferencesPage.editPreferences();
226  1 preferencesEditPage.setDefaultEditorWysiwyg();
227  1 preferencesEditPage.clickSaveAndView();
228  1 preferencesPage = this.customProfilePage.switchToPreferences();
229  1 Assert.assertEquals(WYSIWYG_EDITOR, preferencesPage.getDefaultEditor());
230   
231    // Setting to Default Editor
232  1 this.customProfilePage = ProfileUserProfilePage.gotoPage(this.userName);
233  1 preferencesPage = this.customProfilePage.switchToPreferences();
234  1 preferencesEditPage = preferencesPage.editPreferences();
235  1 preferencesEditPage.setDefaultEditorDefault();
236  1 preferencesEditPage.clickSaveAndView();
237  1 preferencesPage = this.customProfilePage.switchToPreferences();
238  1 Assert.assertEquals(DEFAULT_EDITOR, preferencesPage.getDefaultEditor());
239    }
240   
241    /**
242    * Check that the content of the first comment isn't used as the "About" information in the user profile. See
243    * XAADMINISTRATION-157.
244    */
 
245  1 toggle @Test
246    public void testCommentDoesntOverrideAboutInformation()
247    {
248  1 String commentContent = "this is from a comment";
249   
250  1 int commentId = this.customProfilePage.openCommentsDocExtraPane().postComment(commentContent, true);
251  1 getDriver().navigate().refresh();
252  1 Assert.assertFalse("Comment content was used as profile information", this.customProfilePage.getContent()
253    .contains(commentContent));
254   
255  1 if (commentId != -1) {
256  1 this.customProfilePage.openCommentsDocExtraPane().deleteCommentByID(commentId);
257    }
258    }
259   
 
260  1 toggle @Test
261    @IgnoreBrowsers({
262    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
263    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
264    })
265    public void testChangePasswordWithTwoDifferentPasswords()
266    {
267  1 PreferencesUserProfilePage preferencesPage = this.customProfilePage.switchToPreferences();
268  1 ChangePasswordPage changePasswordPage = preferencesPage.changePassword();
269  1 changePasswordPage.changePassword(DEFAULT_PASSWORD, PASSWORD_1, PASSWORD_2);
270  1 changePasswordPage.submit();
271  1 Assert.assertEquals("The two passwords do not match.", changePasswordPage.getValidationErrorMessage());
272    }
273   
 
274  1 toggle @Test
275    @IgnoreBrowsers({
276    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
277    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
278    })
279    public void testChangePasswordWithoutEnteringPasswords()
280    {
281  1 ChangePasswordPage changePasswordPage = this.customProfilePage.switchToPreferences().changePassword();
282  1 changePasswordPage.submit();
283  1 Assert.assertEquals("Your new password should be at least 6 characters long.", changePasswordPage.getValidationErrorMessage());
284    }
285   
 
286  1 toggle @Test
287    @IgnoreBrowsers({
288    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
289    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
290    })
291    public void testChangePasswordOfAnotherUserWithTwoDifferentPasswords()
292    {
293    // Login as superadmin (to have Admin rights) and change the password of another user.
294  1 getUtil().loginAsSuperAdminAndGotoPage(this.customProfilePage.getURL());
295   
296  1 PreferencesUserProfilePage preferencesPage = this.customProfilePage.switchToPreferences();
297  1 ChangePasswordPage changePasswordPage = preferencesPage.changePassword();
298  1 changePasswordPage.changePasswordAsAdmin(PASSWORD_1, PASSWORD_2);
299  1 changePasswordPage.submit();
300  1 Assert.assertEquals("The two passwords do not match.", changePasswordPage.getValidationErrorMessage());
301    }
302   
 
303  1 toggle @Test
304    @IgnoreBrowsers({
305    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
306    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
307    })
308    public void testChangePasswordWithWrongOriginalPassword()
309    {
310  1 PreferencesUserProfilePage preferencesPage = this.customProfilePage.switchToPreferences();
311  1 ChangePasswordPage changePasswordPage = preferencesPage.changePassword();
312  1 changePasswordPage.changePassword("badPassword", PASSWORD_1, PASSWORD_1);
313  1 changePasswordPage.submit();
314  1 Assert.assertEquals("Current password is invalid.", changePasswordPage.getErrorMessage());
315    }
316    }