1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.flamingo.test.ui

File BreadcrumbsTest.java

 

Code metrics

0
24
2
1
116
62
2
0.08
12
2
1

Classes

Class Line # Actions
44 24 0% 2 0
1.0100%
 

Contributing tests

This file is covered by 2 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.flamingo.test.ui;
21   
22    import java.util.Arrays;
23   
24    import org.junit.Rule;
25    import org.junit.Test;
26    import org.xwiki.model.reference.DocumentReference;
27    import org.xwiki.test.ui.AbstractTest;
28    import org.xwiki.test.ui.SuperAdminAuthenticationRule;
29    import org.xwiki.test.ui.browser.IgnoreBrowser;
30    import org.xwiki.test.ui.browser.IgnoreBrowsers;
31    import org.xwiki.test.ui.po.BreadcrumbElement;
32    import org.xwiki.test.ui.po.ViewPage;
33   
34    import static org.junit.Assert.assertEquals;
35    import static org.junit.Assert.assertFalse;
36    import static org.junit.Assert.assertTrue;
37   
38    /**
39    * Test Breadcrumbs.
40    *
41    * @version $Id: 9549632d65f6480be92f317f821d578dc937051b $
42    * @since 2.7RC1
43    */
 
44    public class BreadcrumbsTest extends AbstractTest
45    {
46    @Rule
47    public SuperAdminAuthenticationRule adminAuthenticationRule = new SuperAdminAuthenticationRule(getUtil());
48   
49    private static final String PARENT_TITLE = "Parent page";
50   
51    private static final String CHILD_TITLE = "Child page";
52   
 
53  1 toggle @Test
54    @IgnoreBrowsers({
55    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See https://jira.xwiki.org/browse/XE-1146"),
56    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See https://jira.xwiki.org/browse/XE-1177")
57    })
58    public void verifyBreadcrumbInParentChildMode()
59    {
60    // Delete the page to reset the rights on it (since the test below modifies them).
61  1 getUtil().deletePage(getTestClassName(), getTestMethodName());
62   
63  1 getUtil().setHierarchyMode("parentchild");
64   
65  1 String parentPageName = getTestMethodName() + "ParentPage";
66  1 String parentPageFullName = getTestClassName() + "." + parentPageName;
67   
68  1 getUtil().createPage(getTestClassName(), parentPageName, null, PARENT_TITLE);
69  1 ViewPage vp = getUtil().createPage(getTestClassName(), getTestMethodName(), null, CHILD_TITLE, null,
70    parentPageFullName);
71   
72    // Verify standard breadcrumb behavior.
73  1 assertTrue(vp.hasBreadcrumbContent(PARENT_TITLE, false));
74  1 assertTrue(vp.hasBreadcrumbContent(CHILD_TITLE, true));
75   
76    // Remove view rights on the Test.ParentPage page to everyone except superadmin user so that we can verify
77    // that the breadcrumb of the child page doesn't display page titles for pages for which you don't have view
78    // rights.
79  1 getUtil().addObject(getTestClassName(), parentPageName, "XWiki.XWikiRights",
80    "levels", "view",
81    "users", "XWiki.superadmin",
82    "allow", "1");
83   
84    // Log out...
85  1 getUtil().forceGuestUser();
86   
87    // Verify breadcrumb doesn't display page title for the parent page (since the guest user doesn't have view
88    // permission for it).
89  1 vp = getUtil().gotoPage(getTestClassName(), getTestMethodName());
90  1 assertFalse(vp.isAuthenticated());
91  1 assertFalse(vp.hasBreadcrumbContent(PARENT_TITLE, false, true));
92  1 assertTrue(vp.hasBreadcrumbContent(CHILD_TITLE, true, true));
93  1 assertTrue(vp.hasBreadcrumbContent(parentPageName, false, false));
94   
95    // Set back the default hierarchy mode (but first we need to log back).
96  1 adminAuthenticationRule.authenticate();
97  1 getUtil().setHierarchyMode("reference");
98    }
99   
 
100  1 toggle @Test
101    public void verifyBreadcrumbInLongHierarchy() throws Exception
102    {
103  1 DocumentReference documentReference =
104    new DocumentReference("xwiki", Arrays.asList("A", "B", "C", "D", "E", "F", "G", "H"), "WebHome");
105  1 ViewPage page = getUtil().createPage(documentReference, "Content", getTestMethodName());
106   
107  1 BreadcrumbElement breadcrumb = page.getBreadcrumb();
108    // Verify that the breadcrumb is limited
109  1 assertEquals("/A/…/F/G/" + getTestMethodName(), breadcrumb.getPathAsString());
110    // Verify we can expand it
111  1 breadcrumb.expand();
112  1 assertEquals("/A/B/C/D/E/F/G/" + getTestMethodName(), breadcrumb.getPathAsString());
113    // Clean
114  1 getUtil().deletePage(documentReference);
115    }
116    }