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

File RegularUserTest.java

 

Code metrics

2
62
9
1
207
113
10
0.16
6.89
9
1.11

Classes

Class Line # Actions
RegularUserTest 33 62 0% 10 0
1.0100%
 

Contributing tests

This file is covered by 3 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.wysiwyg;
21   
22    import java.util.Arrays;
23   
24    import org.junit.Test;
25    import org.xwiki.test.wysiwyg.framework.AbstractWysiwygTestCase;
26    import org.xwiki.test.wysiwyg.framework.XWikiExplorer;
27   
28    import static org.junit.Assert.*;
29   
30    /**
31    * Test for the Wysiwyg editing features when editing as a regular user, not an admin.
32    */
 
33    public class RegularUserTest extends AbstractWysiwygTestCase
34    {
35    /**
36    * The object used to assert the state of the XWiki Explorer tree.
37    */
38    private XWikiExplorer explorer;
39   
 
40  3 toggle @Override
41    public void setUp()
42    {
43  3 super.setUp();
44   
45  3 this.explorer = new XWikiExplorer(getDriver());
46    }
47   
48    /**
49    * {@inheritDoc}
50    * <p>
51    * Override to login as a regular user (and create the user if necessary).
52    */
 
53  3 toggle @Override
54    protected void login()
55    {
56  3 loginAndRegisterUser("Pokemon", "Pokemon", false);
57    }
58   
59    /**
60    * Test that creating a link to a page, logged in as a regular user, does not show technical documents in the search
61    * results.
62    * <p>
63    * See http://jira.xwiki.org/browse/XWIKI-4412 and http://jira.xwiki.org/browse/XWIKI-7568.
64    */
 
65  1 toggle @Test
66    public void testWikiLinkSearchedPageHidesTechnicalSpaces()
67    {
68  1 openDialog("Link", "Wiki Page...");
69   
70  1 waitForStepToLoad("xSelectorAggregatorStep");
71  1 clickTab("Search");
72  1 waitForStepToLoad("xPagesSearch");
73    // Check the results list: Blog, Main and Sandbox are present.
74  1 checkSpaceInSearchResults("Blog", true);
75  1 checkSpaceInSearchResults("Main", true);
76  1 checkSpaceInSearchResults("Sandbox", true);
77    // Check the results list: ColorThemes, Panels, Scheduler, Stats, XWiki are not present.
78  1 checkSpaceInSearchResults("ColorThemes", false);
79  1 checkSpaceInSearchResults("Panels", false);
80  1 checkSpaceInSearchResults("Scheduler", false);
81  1 checkSpaceInSearchResults("Stats", false);
82  1 checkSpaceInSearchResults("XWiki", false);
83   
84  1 closeDialog();
85    }
86   
87    /**
88    * Helper method to test if a space appears in the search results or not.
89    *
90    * @param spaceName the name of the space to test whether it is returned among the search results or not
91    * @param present {@code true} if the space is expected in the search results, {@code false} otherwise
92    */
 
93  8 toggle private void checkSpaceInSearchResults(String spaceName, boolean expected)
94    {
95  8 typeInInput("Type a keyword to search for a wiki page", spaceName + ".WebHome");
96  8 clickButtonWithText("Search");
97    // We have to look for the new page selector inside the search panel because it is also present on the recent
98    // pages panel (which is hidden, but still present in DOM, while the search tab is selected).
99  8 String newPageSelector =
100    "//div[contains(@class, 'xPagesSearch')]" + "//div[contains(@class, 'xListItem')]"
101    + "//div[contains(@class, 'xNewPagePreview')]";
102    // Wait for the search results. The list is cleared (including the new page selector) as soon as we click the
103    // search button and is refilled when the search results are received. The new page selector is (re)added after
104    // the list is filled with the search results.
105  8 waitForElement(newPageSelector);
106    // Check if the desired element is there or not, but look precisely inside the search panel.
107  8 String pageInListLocator =
108    "//div[contains(@class, 'xPagesSearch')]" + "//div[contains(@class, 'xListItem')]" + "//div[. = '"
109    + String.format(LinkTest.PAGE_LOCATION, spaceName, "WebHome") + "']";
110  8 if (expected) {
111  3 assertElementPresent(pageInListLocator);
112    } else {
113  5 assertElementNotPresent(pageInListLocator);
114    }
115    }
116   
117    /**
118    * Test that upon selecting the wiki page to create a link to from all the pages in the wiki, with the tree
119    * explorer, the technical spaces are not displayed to the regular user to choose from.
120    */
 
121  1 toggle @Test
122    public void testWikiLinkAllPagesPageHidesTechnicalSpaces()
123    {
124  1 String currentSpace = getClass().getSimpleName();
125  1 String currentPage = getTestMethodName();
126   
127    // Save the current page so that it appears in the tree.
128  1 clickEditSaveAndContinue();
129   
130  1 openDialog("Link", "Wiki Page...");
131  1 waitForStepToLoad("xSelectorAggregatorStep");
132  1 clickTab("All pages");
133  1 waitForStepToLoad("xExplorerPanel");
134  1 explorer.waitForPageSelected(currentSpace, currentPage);
135   
136    // Now the tree is loaded. Check the list of top level documents.
137    // Note that the home page of the XWiki space is hidden ATM although there are pages inside the XWiki space that
138    // are not hidden, like the syntax guide. So the "XWiki" top level document is visible but is not provided
139    // in the finder suggestions. We search for the syntax guide instead.
140  1 for (String page : Arrays.asList("Blog", "Home", "Sandbox", "XWiki Syntax Guide")) {
141  4 explorer.findAndSelectPage(page);
142    }
143   
144    // Technical documents shouldn't be present.
145  1 for (String space : Arrays.asList("ColorThemes", "Panels", "Scheduler", "Stats")) {
146  4 assertFalse(explorer.hasPage(space, "WebHome"));
147    }
148  1 for (String page : Arrays.asList("Color Themes", "Panels", "Job Scheduler", "Statistics")) {
149  4 assertFalse(explorer.find(page).hasPage(page));
150    }
151   
152  1 closeDialog();
153    }
154   
155    /**
156    * Test that upon selecting an image from all the images in the wiki, the technical spaces are not listed in the
157    * space selector for the regular user to choose from.
158    */
 
159  1 toggle @Test
160    public void testImageSelectorHidesTechnicalSpaces()
161    {
162  1 String currentSpace = getClass().getSimpleName();
163   
164    // Save the current page so that it appears in the tree.
165  1 clickEditSaveAndContinue();
166   
167  1 openDialog(ImageTest.MENU_IMAGE, ImageTest.MENU_INSERT_ATTACHED_IMAGE);
168  1 waitForStepToLoad("xSelectorAggregatorStep");
169  1 clickTab("All pages");
170  1 waitForStepToLoad("xImagesExplorer");
171    // wait for the current space to load in the selector to be sure the spaces list is loaded
172  1 waitForElement(ImageTest.SPACE_SELECTOR + "/option[@value=\"" + currentSpace + "\"]");
173    // check the spaces: Blog, Main, Sandbox are present
174  1 assertElementPresent(ImageTest.SPACE_SELECTOR + "/option[@value=\"Blog\"]");
175  1 assertElementPresent(ImageTest.SPACE_SELECTOR + "/option[@value=\"Main\"]");
176  1 assertElementPresent(ImageTest.SPACE_SELECTOR + "/option[@value=\"Sandbox\"]");
177    // check the spaces: ColorThemes, Panels, Scheduler, Stats, XWiki are not present
178  1 assertElementNotPresent(ImageTest.SPACE_SELECTOR + "/option[@value=\"ColorThemes\"]");
179  1 assertElementNotPresent(ImageTest.SPACE_SELECTOR + "/option[@value=\"Panels\"]");
180  1 assertElementNotPresent(ImageTest.SPACE_SELECTOR + "/option[@value=\"Scheduler\"]");
181  1 assertElementNotPresent(ImageTest.SPACE_SELECTOR + "/option[@value=\"Stats\"]");
182    // TODO: XWiki space should not be listed but currently there are few pages in this space that are not marked as
183    // hidden/technical. Update this check as soon as the XWiki space is completely hidden.
184  1 assertElementPresent(ImageTest.SPACE_SELECTOR + "/option[@value=\"XWiki\"]");
185   
186  1 closeDialog();
187    }
188   
 
189  6 toggle protected void waitForStepToLoad(String name)
190    {
191  6 waitForElement("//*[contains(@class, '" + name + "')]");
192    }
193   
 
194  3 toggle private void openDialog(String menuName, String menuItemName)
195    {
196  3 clickMenu(menuName);
197  3 assertTrue(isMenuEnabled(menuItemName));
198  3 clickMenu(menuItemName);
199  3 waitForDialogToLoad();
200    }
201   
 
202  3 toggle private void clickTab(String tabName)
203    {
204  3 String tabSelector = "//div[.='" + tabName + "']";
205  3 getSelenium().click(tabSelector);
206    }
207    }