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

File WikiTemplateTest.java

 

Code metrics

4
63
4
1
178
102
6
0.1
15.75
4
1.5

Classes

Class Line # Actions
WikiTemplateTest 46 63 0% 6 4
0.94366294.4%
 

Contributing tests

This file is covered by 1 test. .

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.wiki.test.ui;
21   
22    import org.junit.Rule;
23    import org.junit.Test;
24    import org.xwiki.test.ui.AbstractTest;
25    import org.xwiki.test.ui.SuperAdminAuthenticationRule;
26    import org.xwiki.test.ui.po.editor.WikiEditPage;
27    import org.xwiki.wiki.test.po.CreateWikiPage;
28    import org.xwiki.wiki.test.po.CreateWikiPageStepUser;
29    import org.xwiki.wiki.test.po.DeleteWikiPage;
30    import org.xwiki.wiki.test.po.WikiCreationPage;
31    import org.xwiki.wiki.test.po.WikiHomePage;
32    import org.xwiki.wiki.test.po.WikiIndexPage;
33    import org.xwiki.wiki.test.po.WikiLink;
34   
35    import static org.junit.Assert.assertEquals;
36    import static org.junit.Assert.assertFalse;
37    import static org.junit.Assert.assertNull;
38    import static org.junit.Assert.assertTrue;
39   
40    /**
41    * UI tests for the wiki templates feature of the Wiki application.
42    *
43    * @version $Id: 8a54036d63a770cdd4aba6e3106bbd3b8915296e $
44    * @since 6.0M1
45    */
 
46    public class WikiTemplateTest extends AbstractTest
47    {
48    @Rule
49    public SuperAdminAuthenticationRule superAdminAuthenticationRule = new SuperAdminAuthenticationRule(getUtil());
50   
51    private static final String TEMPLATE_WIKI_ID = "mynewtemplate";
52    private static final String TEMPLATE_CONTENT = "Content of the template";
53   
 
54  1 toggle private void createTemplateWiki() throws Exception
55    {
56    // Go to the wiki creation wizard
57  1 WikiIndexPage wikiIndexPage = WikiIndexPage.gotoPage();
58  1 CreateWikiPage createWikiPage = wikiIndexPage.createWiki();
59   
60    // Full the first step
61  1 createWikiPage.setPrettyName("My new template");
62  1 String wikiName = createWikiPage.getComputedName();
63  1 assertEquals(TEMPLATE_WIKI_ID, wikiName);
64  1 createWikiPage.setDescription("This is the template I do for the tests");
65  1 createWikiPage.setIsTemplate(true);
66  1 assertTrue(createWikiPage.isNextStepEnabled());
67   
68    // Second step
69  1 CreateWikiPageStepUser createWikiPageStepUser = createWikiPage.goUserStep();
70   
71    // Creation step
72  1 WikiCreationPage wikiCreationPage = createWikiPageStepUser.create();
73  1 assertEquals("Wiki creation", wikiCreationPage.getStepTitle());
74    // Ensure there is no error in the log
75  1 assertFalse(wikiCreationPage.hasLogError());
76   
77    // Finalization
78  1 WikiHomePage wikiHomePage = wikiCreationPage.finalizeCreation();
79   
80    // Go to the created subwiki, and modify the home page content
81  1 wikiHomePage.edit();
82  1 WikiEditPage wikiEditPage = new WikiEditPage();
83  1 wikiEditPage.setContent(TEMPLATE_CONTENT);
84  1 wikiEditPage.clickSaveAndView();
85  1 wikiEditPage.waitUntilPageIsLoaded();
86   
87    // Go back to the wiki creation wizard, and verify the template is in the list of templates in the wizard
88  1 createWikiPage = wikiHomePage.createWiki();
89  1 assertTrue(createWikiPage.getTemplateList().contains("mynewtemplate"));
90   
91    // Verify the wiki is in the wiki index page.
92  1 wikiIndexPage = WikiIndexPage.gotoPage().waitUntilPageIsLoaded();
93  1 WikiLink wikiLink = wikiIndexPage.getWikiLink("My new template");
94  1 if (wikiLink == null) {
95  0 throw new Exception("The wiki [My new template] is not in the wiki index.");
96    }
97  1 assertTrue(wikiLink.getURL().endsWith("/xwiki/wiki/mynewtemplate/view/Main/"));
98   
99    }
100   
 
101  1 toggle private void deleteTemplateWiki() throws Exception
102    {
103    // Go to the template wiki
104  1 WikiIndexPage wikiIndexPage = WikiIndexPage.gotoPage().waitUntilPageIsLoaded();
105  1 WikiLink templateWikiLink = wikiIndexPage.getWikiLink("My new template");
106  1 if (templateWikiLink == null) {
107  0 throw new Exception("The wiki [My new template] is not in the wiki index.");
108    }
109  1 DeleteWikiPage deleteWikiPage = wikiIndexPage.deleteWiki(TEMPLATE_WIKI_ID).confirm(TEMPLATE_WIKI_ID);
110  1 assertTrue(deleteWikiPage.hasSuccessMessage());
111    // Verify the wiki has been deleted
112  1 wikiIndexPage = WikiIndexPage.gotoPage().waitUntilPageIsLoaded();
113  1 assertNull(wikiIndexPage.getWikiLink("My new template"));
114    }
115   
 
116  2 toggle private void createWikiFromTemplate()
117    {
118    // Go to the wiki creation wizard
119  2 WikiIndexPage wikiIndexPage = WikiIndexPage.gotoPage();
120  2 CreateWikiPage createWikiPage = wikiIndexPage.createWiki();
121   
122    // First step
123  2 createWikiPage.setPrettyName("My new wiki");
124  2 String wikiName = createWikiPage.getComputedName();
125  2 assertEquals("mynewwiki", wikiName);
126  2 createWikiPage.setTemplate(TEMPLATE_WIKI_ID);
127  2 createWikiPage.setIsTemplate(false);
128  2 createWikiPage.setDescription("My first wiki");
129   
130    // Second step
131  2 CreateWikiPageStepUser createWikiPageStepUser = createWikiPage.goUserStep();
132  2 WikiCreationPage wikiCreationPage = createWikiPageStepUser.create();
133  2 assertEquals("Wiki creation", wikiCreationPage.getStepTitle());
134    // Wait for the finalize button to be displayed, with a 1 minute limit
135    // (it's a lot but we often have problems on ci.xwiki.org).
136  2 wikiCreationPage.waitForFinalizeButton(60);
137    // Ensure there is no error in the log
138  2 assertFalse(wikiCreationPage.hasLogError());
139   
140    // Finalization
141  2 WikiHomePage wikiHomePage = wikiCreationPage.finalizeCreation();
142   
143    // Go the created subwiki and verify the content of the main page is the same than in the template
144  2 assertEquals(wikiHomePage.getContent(), TEMPLATE_CONTENT);
145   
146    // Delete the wiki
147  2 DeleteWikiPage deleteWikiPage = wikiHomePage.deleteWiki();
148  2 deleteWikiPage = deleteWikiPage.confirm("");
149  2 assertTrue(deleteWikiPage.hasUserErrorMessage());
150  2 assertTrue(deleteWikiPage.hasWikiDeleteConfirmationInput(""));
151   
152  2 deleteWikiPage = deleteWikiPage.confirm("My new wiki");
153  2 assertTrue(deleteWikiPage.hasUserErrorMessage());
154  2 assertTrue(deleteWikiPage.hasWikiDeleteConfirmationInput("My new wiki"));
155   
156  2 deleteWikiPage = deleteWikiPage.confirm("mynewwiki");
157  2 assertTrue(deleteWikiPage.hasSuccessMessage());
158   
159    // Verify the wiki has been deleted
160  2 wikiIndexPage = WikiIndexPage.gotoPage().waitUntilPageIsLoaded();
161  2 assertNull(wikiIndexPage.getWikiLink("My new wiki"));
162    }
163   
 
164  1 toggle @Test
165    public void createWikiFromTemplateTest() throws Exception
166    {
167    // Create the template
168  1 createTemplateWiki();
169   
170    // Create the wiki from the template
171  1 createWikiFromTemplate();
172    // Do it twice to check if we can create a wiki with the name of a deleted one
173  1 createWikiFromTemplate();
174   
175    // Delete the template wiki
176  1 deleteTemplateWiki();
177    }
178    }