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

File PanelTest.java

 

Code metrics

2
40
4
1
144
76
5
0.12
10
4
1.25

Classes

Class Line # Actions
PanelTest 44 40 0% 5 1
0.978260997.8%
 

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.panels.test.ui;
21   
22    import org.junit.*;
23    import org.xwiki.administration.test.po.PageElementsAdministrationSectionPage;
24    import org.xwiki.panels.test.po.ApplicationsPanel;
25    import org.xwiki.panels.test.po.PageWithPanels;
26    import org.xwiki.panels.test.po.PanelEditPage;
27    import org.xwiki.panels.test.po.PanelsHomePage;
28    import org.xwiki.test.ui.AbstractTest;
29    import org.xwiki.test.ui.SuperAdminAuthenticationRule;
30    import org.xwiki.test.ui.po.EditRightsPane.Right;
31    import org.xwiki.test.ui.po.EditRightsPane.State;
32    import org.xwiki.test.ui.po.ViewPage;
33    import org.xwiki.test.ui.po.editor.RightsEditPage;
34    import org.xwiki.text.StringUtils;
35   
36    import static org.junit.Assert.*;
37   
38    /**
39    * Various Panel tests.
40    *
41    * @version $Id: 6dc9b19e4b91ecc8680d83958320703137a460a4 $
42    * @since 5.0M2
43    */
 
44    public class PanelTest extends AbstractTest
45    {
46    @Rule
47    public SuperAdminAuthenticationRule authenticationRule = new SuperAdminAuthenticationRule(getUtil());
48   
 
49  1 toggle @Test
50    public void verifyApplicationsPanelEntry()
51    {
52    // Navigate to the Panels app by clicking in the Application Panel.
53    // This verifies that the Panels application is registered in the Applications Panel.
54    // It also verifies that the Translation is registered properly.
55  1 ApplicationsPanel applicationPanel = ApplicationsPanel.gotoPage();
56  1 ViewPage vp = applicationPanel.clickApplication("Panels");
57   
58    // Verify we're on the right page!
59  1 assertEquals(PanelsHomePage.getSpace(), vp.getMetaDataValue("space"));
60  1 assertEquals(PanelsHomePage.getPage(), vp.getMetaDataValue("page"));
61   
62    // Now log out to verify that the Panels entry is not displayed for non admin users
63  1 getUtil().forceGuestUser();
64    // Navigate again to the Application Panels page to perform the verification
65  1 applicationPanel = ApplicationsPanel.gotoPage();
66  1 assertFalse(applicationPanel.containsApplication("Panels"));
67    }
68   
69    /**
70    * @see "XWIKI-8591: Cannot use a panel with a name containing spaces"
71    */
 
72  1 toggle @Test
73    public void addPanelWithSpacesInName()
74    {
75    // Delete panel that will be created by the test
76  1 String panelName = "My First Panel";
77  1 getUtil().deletePage("Panels", panelName);
78   
79    // Create a panel whose name contain spaces.
80  1 PanelEditPage panelEditPage = PanelsHomePage.gotoPage().createPanel(panelName);
81  1 panelEditPage.setContent(String.format(PanelEditPage.DEFAULT_CONTENT_FORMAT, panelName, getTestMethodName()));
82  1 panelEditPage.clickSaveAndContinue();
83   
84    // Add the panel to the right column from the administration.
85  1 setRightPanelInAdministration(panelName);
86  1 assertTrue(new PageWithPanels().hasPanel(panelName));
87    }
88   
89    /**
90    * @see "XWIKI-9126: Show panel only if the user has the view right on the panel page"
91    */
 
92  1 toggle @Test
93    public void limitPanelViewRight()
94    {
95    // Delete panel that will be created by the test
96  1 String panelName = getTestMethodName();
97  1 getUtil().deletePage("Panels", panelName);
98   
99    // Create a user for the test so that we can give view rights to the panel page to that user.
100  1 String userName = String.format("%s%s", getTestClassName(), getTestMethodName());
101  1 getUtil().createUser(userName, "password", getUtil().getURLToNonExistentPage());
102   
103    // Create new Panel
104  1 PanelEditPage panelEditPage = PanelsHomePage.gotoPage().createPanel(panelName);
105  1 panelEditPage.setContent(String.format(PanelEditPage.DEFAULT_CONTENT_FORMAT, panelName, "Panel content."));
106  1 panelEditPage.clickSaveAndContinue();
107   
108    // Add the panel to the right column from the administration. This also proves that the Panel Admin UI is
109    // displayed fine and can be modified.
110  1 setRightPanelInAdministration(panelName);
111   
112    // The panel should be visible for the administrator.
113  1 assertTrue(new PageWithPanels().hasPanel(panelName));
114   
115    // Force the guest user to verify the Panel is also visible for Guests.
116  1 getUtil().gotoPage(getTestClassName(), getTestMethodName());
117  1 getUtil().forceGuestUser();
118  1 assertTrue(new PageWithPanels().hasPanel(panelName));
119   
120    // Login and limit the view right on the panel document to the test user.
121  1 this.authenticationRule.authenticate();
122  1 RightsEditPage rightsEditor = getUtil().gotoPage("Panels", panelName).editRights();
123  1 rightsEditor.switchToUsers();
124    // Explicit view right for the test user.
125  1 rightsEditor.setRight(userName, Right.VIEW, State.ALLOW);
126   
127    // Check again the panel visibility for the test user and then for guest
128  1 getUtil().loginAndGotoPage(userName, "password", getUtil().getURL(getTestClassName(), getTestMethodName()));
129  1 assertTrue(new PageWithPanels().hasPanel(panelName));
130  1 getUtil().forceGuestUser();
131  1 assertFalse(new PageWithPanels().hasPanel(panelName));
132    }
133   
 
134  2 toggle private void setRightPanelInAdministration(String panelName)
135    {
136  2 PageElementsAdministrationSectionPage peasp = PageElementsAdministrationSectionPage.gotoPage();
137  2 String rightPanels = peasp.getRightPanels();
138  2 String newPanelString = "Panels." + panelName;
139  2 if (!rightPanels.contains(newPanelString)) {
140  2 peasp.setRightPanels(StringUtils.join(new Object[]{ rightPanels, newPanelString }, ','));
141    }
142  2 peasp.clickSave();
143    }
144    }