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

File CommentAsGuestTest.java

 

Code metrics

0
27
7
1
152
101
7
0.26
3.86
7
1

Classes

Class Line # Actions
CommentAsGuestTest 40 27 0% 7 34
0.00%
 

Contributing tests

No tests hitting this source file were found.

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.test.ui;
21   
22    import org.junit.Assert;
23    import org.junit.Before;
24    import org.junit.BeforeClass;
25    import org.junit.ClassRule;
26    import org.junit.Rule;
27    import org.junit.Test;
28    import org.xwiki.administration.test.po.GlobalRightsAdministrationSectionPage;
29    import org.xwiki.test.ui.browser.IgnoreBrowser;
30    import org.xwiki.test.ui.browser.IgnoreBrowsers;
31    import org.xwiki.test.ui.po.CommentsTab;
32    import org.xwiki.test.ui.po.EditRightsPane.Right;
33    import org.xwiki.test.ui.po.EditRightsPane.State;
34    import org.xwiki.test.ui.po.ViewPage;
35   
36    /**
37    * @version $Id: b552c6f16806cd0244b07c5b9fe46e3d7c37e35c $
38    * @since 3.1M2
39    */
 
40    public class CommentAsGuestTest extends AbstractTest
41    {
42    @ClassRule
43    public static AdminAuthenticationRule adminAuthenticationClassRule = new AdminAuthenticationRule(getUtil());
44   
45    @Rule
46    public AdminAuthenticationRule adminAuthenticationRule = new AdminAuthenticationRule(getUtil());
47   
48    private static final String CONTENT = "Some dummy Content";
49   
50    private static final String TITLE = "CommentsTest Page";
51   
52    private static final String COMMENT_CONTENT = "Some content";
53   
54    private static final String COMMENT_AUTHOR = "Anonymous";
55   
56    private static final String COMMENT_REPLY = "Comment Reply";
57   
58    private ViewPage vp;
59   
 
60  0 toggle @BeforeClass
61    public static void initializeCommentRights()
62    {
63    // Ensure that guest user has comment permission
64  0 setRightsOnGuest(Right.COMMENT, State.ALLOW);
65    }
66   
 
67  0 toggle @Before
68    public void setUp() throws Exception
69    {
70  0 getUtil().rest().deletePage(getTestClassName(), getTestMethodName());
71  0 this.vp = getUtil().createPage(getTestClassName(), getTestMethodName(), CONTENT, TITLE);
72   
73    // Set Guest user
74  0 getUtil().forceGuestUser();
75   
76    // Important: we need to reload the page since forceGuestUser() simply removes the cookies and doesn't refresh
77    // the page and we need it refreshed since there's an extra field for guest users when commenting (the user
78    // name field).
79  0 getDriver().navigate().refresh();
80    }
81   
 
82  0 toggle private static void setRightsOnGuest(Right right, State state)
83    {
84  0 GlobalRightsAdministrationSectionPage globalRights = GlobalRightsAdministrationSectionPage.gotoPage();
85    // Wait for the rights live table to load before switching in order to prevent any possible race conditions.
86  0 globalRights.getEditRightsPane().getRightsTable().waitUntilReady();
87  0 globalRights.getEditRightsPane().switchToUsers();
88  0 globalRights.getEditRightsPane().setGuestRight(right, state);
89    }
90   
 
91  0 toggle @Test
92    @IgnoreBrowsers({
93    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
94    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
95    })
96    public void testPostCommentAsGuest()
97    {
98  0 CommentsTab commentsTab = this.vp.openCommentsDocExtraPane();
99   
100  0 commentsTab.postCommentAsGuest(COMMENT_CONTENT, COMMENT_AUTHOR, true);
101  0 Assert.assertEquals(COMMENT_CONTENT, commentsTab.getCommentContentByID(0));
102  0 Assert.assertEquals(COMMENT_AUTHOR, commentsTab.getCommentAuthorByID(0));
103    }
104   
 
105  0 toggle @Test
106    @IgnoreBrowsers({
107    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
108    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
109    })
110    public void testPostCommentAsGuestNoJs()
111    {
112  0 getUtil().gotoPage(getTestClassName(), getTestMethodName(), "view", "xpage=xpart&vm=commentsinline.vm");
113  0 CommentsTab commentsTab = new CommentsTab();
114   
115  0 commentsTab.postComment(COMMENT_CONTENT, false);
116    // This opens with ?viewer=comments, don't explicitly load the comments tab
117  0 new ViewPage().waitUntilPageIsLoaded();
118  0 Assert.assertEquals(COMMENT_CONTENT,
119    commentsTab.getCommentContentByID(commentsTab.getCommentID(COMMENT_CONTENT)));
120  0 Assert.assertEquals(COMMENT_AUTHOR,
121    commentsTab.getCommentAuthorByID(commentsTab.getCommentID(COMMENT_CONTENT)));
122    }
123   
 
124  0 toggle @Test
125    @IgnoreBrowsers({
126    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
127    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
128    })
129    public void testReplyCommentAsAnonymous()
130    {
131  0 CommentsTab commentsTab = this.vp.openCommentsDocExtraPane();
132   
133  0 commentsTab.postCommentAsGuest(COMMENT_CONTENT, COMMENT_AUTHOR, true);
134  0 commentsTab.replyToCommentByID(commentsTab.getCommentID(COMMENT_CONTENT), COMMENT_REPLY);
135  0 Assert.assertEquals(COMMENT_REPLY,
136    commentsTab.getCommentContentByID(commentsTab.getCommentID(COMMENT_REPLY)));
137  0 Assert.assertEquals(COMMENT_AUTHOR,
138    commentsTab.getCommentAuthorByID(commentsTab.getCommentID(COMMENT_REPLY)));
139    }
140   
 
141  0 toggle @Test
142    @IgnoreBrowsers({
143    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
144    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
145    })
146    public void testCannotEditCommentAsAnonymous()
147    {
148  0 CommentsTab commentsTab = this.vp.openCommentsDocExtraPane();
149  0 commentsTab.postCommentAsGuest(COMMENT_CONTENT, COMMENT_AUTHOR, true);
150  0 Assert.assertFalse(commentsTab.hasEditButtonForCommentByID(commentsTab.getCommentID(COMMENT_CONTENT)));
151    }
152    }