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

File CommentAsAdminTest.java

 

Code metrics

0
37
8
1
146
95
8
0.22
4.62
8
1

Classes

Class Line # Actions
CommentAsAdminTest 36 37 0% 8 0
1.0100%
 

Contributing tests

This file is covered by 7 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.test.ui;
21   
22    import org.junit.Assert;
23    import org.junit.Before;
24    import org.junit.Rule;
25    import org.junit.Test;
26    import org.xwiki.test.ui.po.CommentForm;
27    import org.xwiki.test.ui.po.CommentsTab;
28    import org.xwiki.test.ui.po.ViewPage;
29   
30    /**
31    * Test comment and reply on XWiki Pages when logged as Administrator.
32    *
33    * @version $Id: 4ffcfd8287583c9e9b509b0482ef47edb88eb25a $
34    * @since 3.1M2
35    */
 
36    public class CommentAsAdminTest extends AbstractTest
37    {
38    @Rule
39    public AdminAuthenticationRule adminAuthenticationRule = new AdminAuthenticationRule(getUtil());
40   
41    private CommentsTab commentsTab;
42   
43    private static final String CONTENT = "Some dummy Content";
44   
45    private static final String TITLE = "CommentsTest Page";
46   
47    private static final String COMMENT_CONTENT = "Some content";
48   
49    private static final String COMMENT_REPLACED_CONTENT = "Some replaced content";
50   
51    private static final String ADMIN = "Administrator";
52   
53    private static final String COMMENT_REPLY = "Comment Reply";
54   
 
55  7 toggle @Before
56    public void setUp() throws Exception
57    {
58  7 getUtil().rest().deletePage(getTestClassName(), getTestMethodName());
59  7 ViewPage vp = getUtil().createPage(getTestClassName(), getTestMethodName(), CONTENT, TITLE);
60  7 this.commentsTab = vp.openCommentsDocExtraPane();
61    }
62   
 
63  1 toggle @Test
64    public void testPostCommentAsAdmin()
65    {
66  1 Assert.assertTrue(this.commentsTab.isCommentFormShown());
67  1 this.commentsTab.postComment(COMMENT_CONTENT, true);
68  1 Assert.assertEquals(COMMENT_CONTENT,
69    this.commentsTab.getCommentContentByID(this.commentsTab.getCommentID(COMMENT_CONTENT)));
70  1 Assert.assertEquals(ADMIN,
71    this.commentsTab.getCommentAuthorByID(this.commentsTab.getCommentID(COMMENT_CONTENT)));
72    }
73   
 
74  1 toggle @Test
75    public void testReplyToCommentAsAdmin()
76    {
77  1 this.commentsTab.postComment(COMMENT_CONTENT, true);
78  1 this.commentsTab.replyToCommentByID(this.commentsTab.getCommentID(COMMENT_CONTENT), COMMENT_REPLY);
79  1 Assert.assertEquals(COMMENT_REPLY,
80    this.commentsTab.getCommentContentByID(this.commentsTab.getCommentID(COMMENT_REPLY)));
81  1 Assert.assertEquals(ADMIN, this.commentsTab.getCommentAuthorByID(this.commentsTab.getCommentID(COMMENT_REPLY)));
82    }
83   
 
84  1 toggle @Test
85    public void testDeleteCommentAsAdmin()
86    {
87  1 Assert.assertTrue(this.commentsTab.isCommentFormShown());
88  1 this.commentsTab.postComment(COMMENT_CONTENT, true);
89  1 this.commentsTab.deleteCommentByID(this.commentsTab.getCommentID(COMMENT_CONTENT));
90  1 Assert.assertTrue(this.commentsTab.getCommentID(COMMENT_CONTENT) == -1);
91    }
92   
 
93  1 toggle @Test
94    public void testEditCommentAsAdmin()
95    {
96  1 Assert.assertTrue(this.commentsTab.isCommentFormShown());
97  1 this.commentsTab.postComment(COMMENT_CONTENT, true);
98  1 this.commentsTab.editCommentByID(0, COMMENT_REPLACED_CONTENT);
99  1 Assert.assertEquals(COMMENT_REPLACED_CONTENT,
100    this.commentsTab.getCommentContentByID(this.commentsTab.getCommentID(COMMENT_REPLACED_CONTENT)));
101    }
102   
 
103  1 toggle @Test
104    public void testPostCommentAsAdminNoJs()
105    {
106    // In this test class, the only user who logs in is admin.
107  1 getUtil().gotoPage(getTestClassName(), getTestMethodName(), "view", "xpage=xpart&vm=commentsinline.vm");
108  1 this.commentsTab.postComment(COMMENT_CONTENT, false);
109  1 ViewPage vp = new ViewPage();
110    // This opens with ?viewer=comments, don't explicitly load the comments tab
111  1 vp.waitUntilPageIsLoaded();
112  1 Assert.assertEquals(COMMENT_CONTENT,
113    this.commentsTab.getCommentContentByID(this.commentsTab.getCommentID(COMMENT_CONTENT)));
114  1 Assert.assertEquals(ADMIN,
115    this.commentsTab.getCommentAuthorByID(this.commentsTab.getCommentID(COMMENT_CONTENT)));
116    }
117   
118    /**
119    * Preview a comment on a plain wiki page.
120    */
 
121  1 toggle @Test
122    public void testPreviewComment()
123    {
124  1 CommentForm addCommentForm = commentsTab.getAddCommentForm();
125  1 addCommentForm.getContentField().sendKeys("one **two** three");
126  1 Assert.assertEquals("one two three", addCommentForm.clickPreview().getText());
127  1 addCommentForm.clickBack();
128  1 addCommentForm.getContentField().sendKeys(" //four//");
129  1 addCommentForm.clickPreview();
130  1 addCommentForm.clickSubmit();
131  1 Assert.assertTrue(commentsTab.getCommentID("one two three four") >= 0);
132    }
133   
134    /**
135    * Preview a comment on a wiki page that has a sheet applied.
136    */
 
137  1 toggle @Test
138    public void testPreviewCommentOnPageWithSheet()
139    {
140    // We know Blog.BlogIntroduction has a sheet applied.
141  1 commentsTab = getUtil().gotoPage("Blog", "BlogIntroduction").openCommentsDocExtraPane();
142  1 CommentForm addCommentForm = commentsTab.getAddCommentForm();
143  1 addCommentForm.getContentField().sendKeys("xyz");
144  1 Assert.assertEquals("xyz", addCommentForm.clickPreview().getText());
145    }
146    }