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

File SectionTest.java

 

Code metrics

4
43
6
1
182
110
8
0.19
7.17
6
1.33

Classes

Class Line # Actions
SectionTest 42 43 0% 8 4
0.924528392.5%
 

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.ui;
21   
22    import java.util.HashMap;
23    import java.util.Map;
24   
25    import org.junit.Assert;
26    import org.junit.Rule;
27    import org.junit.Test;
28    import org.xwiki.administration.test.po.AdministrationPage;
29    import org.xwiki.administration.test.po.LocalizationAdministrationSectionPage;
30    import org.xwiki.model.reference.LocalDocumentReference;
31    import org.xwiki.test.ui.browser.IgnoreBrowser;
32    import org.xwiki.test.ui.browser.IgnoreBrowsers;
33    import org.xwiki.test.ui.po.ViewPage;
34    import org.xwiki.test.ui.po.editor.WikiEditPage;
35   
36    /**
37    * Test the section editing feature.
38    *
39    * @version $Id: afd6a33e0c89c08b3b1bb3a187aa8d24357bfefa $
40    * @since 2.6RC1
41    */
 
42    public class SectionTest extends AbstractTest
43    {
44    @Rule
45    public AdminAuthenticationRule adminAuthenticationRule = new AdminAuthenticationRule(true, getUtil());
46   
 
47  3 toggle private ViewPage createTestPages(String syntaxId)
48    {
49  3 if (syntaxId.equalsIgnoreCase("xwiki/1.0")) {
50  0 getUtil().createPage("Test", "SectionEditing", "1 Section1\nContent1\n\n"
51    + "1 Section2\nContent2\n\n1.1 Section3\nContent3\n\n"
52    + "1 Section4\nContent4", "section test in " + syntaxId, syntaxId);
53   
54  3 } else if (syntaxId.startsWith("xwiki/2.")) {
55  3 getUtil().createPage("Test", "SectionEditingIncluded", "== Section4 ==\n" +
56    "Content4\n" +
57    "\n" +
58    "{{velocity wiki=true}}\n" +
59    "#foreach($h in ['5', '6'])\n" +
60    "== Section$h ==\n" +
61    "Content$h\n" +
62    "#end\n" +
63    "{{velocity}}", "section test included in " + syntaxId, syntaxId);
64   
65  3 getUtil().createPage("Test", "SectionEditing", "= Section1 =\nContent1\n\n"
66    + "= Section2 =\nContent2\n\n== Section3 ==\nContent3\n\n"
67    + "{{include document='Test.SectionEditingIncluded'/}}\n\n" + "= Section7 =\nContent7",
68    "section test in " + syntaxId, syntaxId);
69    } else {
70  0 throw new RuntimeException("Unhandled syntax [" + syntaxId + "]");
71    }
72   
73  3 return new ViewPage();
74    }
75   
76    /**
77    * Verify edit section is working in both wiki and wysiwyg editors (xwiki/2.0 and xwiki/2.1).
78    *
79    * Note that we currently don't support section editing for included content (it would mean navigating to the
80    * included page since it would change that page's content and not the currently page's content).
81    *
82    * See XWIKI-2881: Implement Section editing.
83    */
 
84  1 toggle @Test
85    @IgnoreBrowsers({
86    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See https://jira.xwiki.org/browse/XE-1146"),
87    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See https://jira.xwiki.org/browse/XE-1177")
88    })
89    public void testSectionEditInWikiEditorWhenSyntax2x()
90    {
91  1 testSectionEditInWikiEditorWhenSyntax2x("xwiki/2.0");
92  1 testSectionEditInWikiEditorWhenSyntax2x("xwiki/2.1");
93    }
94   
 
95  2 toggle private void testSectionEditInWikiEditorWhenSyntax2x(String syntaxId)
96    {
97  2 ViewPage vp = createTestPages(syntaxId);
98   
99    // Edit the second section in the wiki editor
100  2 WikiEditPage wikiEditPage = vp.editSection(2).editWiki();
101  2 Assert.assertEquals("= Section2 = Content2 == Section3 == Content3 "
102    + "{{include document=\"Test.SectionEditingIncluded\"/}}", wikiEditPage.getContent());
103  2 vp = wikiEditPage.clickCancel();
104   
105    // Edit the third section in the wiki editor
106  2 wikiEditPage = vp.editSection(3).editWiki();
107  2 Assert.assertEquals("== Section3 == Content3 {{include document=\"Test.SectionEditingIncluded\"/}}",
108    wikiEditPage.getContent());
109  2 vp = wikiEditPage.clickCancel();
110   
111    // Edit the fourth section in the wiki editor
112    // Note: we prove that included documents don't generate editable sections by checking that the fourth section
113    // is "Section7".
114  2 wikiEditPage = vp.editSection(4).editWiki();
115  2 Assert.assertEquals("= Section7 = Content7", wikiEditPage.getContent());
116    }
117   
118    /**
119    * Verify section save does not override the whole document content (xwiki/2.0).
120    * See XWIKI-4033: When saving after section edit entire page is overwritten.
121    */
 
122  1 toggle @Test
123    @IgnoreBrowsers({
124    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See https://jira.xwiki.org/browse/XE-1146"),
125    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See https://jira.xwiki.org/browse/XE-1177")
126    })
127    public void testSectionSaveDoesNotOverwriteTheWholeContentWhenSyntax20()
128    {
129  1 ViewPage vp = createTestPages("xwiki/2.0");
130  1 vp.editSection(4).editWiki().clickSaveAndView();
131  1 WikiEditPage wep = vp.editWiki();
132  1 Assert.assertEquals("= Section1 = Content1 = Section2 = Content2 == Section3 == Content3 "
133    + "{{include document=\"Test.SectionEditingIncluded\"/}} = Section7 = Content7", wep.getContent());
134    }
135   
136    /**
137    * Verify that the document title is not overwritten when saving a section.
138    *
139    * @see <a href="https://jira.xwiki.org/browse/XWIKI-8938">XWIKI-8938: Translated title is overwritten by the default
140    * translation title when editing a document section</a>
141    */
 
142  1 toggle @Test
143    public void testSectionSaveDoesNotOverwriteTheTitle() throws Exception
144    {
145  1 LocalDocumentReference pageReference = new LocalDocumentReference(getTestClassName(), getTestMethodName());
146   
147    // Create the English version.
148  1 setLanguageSettings(false, "en", "en");
149  1 getUtil().rest().delete(pageReference);
150  1 getUtil().rest().savePage(pageReference, "Original content", "Original title");
151   
152  1 try {
153    // Create the French version.
154  1 setLanguageSettings(true, "en", "en,fr");
155  1 Map<String, String> parameters = new HashMap<String, String>();
156  1 parameters.put("language", "fr");
157  1 parameters.put("title", "Translated title");
158  1 parameters.put("content", "= Chapter 1 =\n\n Once upon a time ...");
159  1 getUtil().gotoPage(pageReference, "save", parameters);
160   
161    // Switch back to monolingual with French as default language.
162  1 setLanguageSettings(false, "fr", "fr");
163   
164    // Edit and save a document section and check if the document title was overwritten.
165  1 getUtil().gotoPage(pageReference, "edit", "editor=wiki&section=1");
166  1 Assert.assertEquals("Translated title", new WikiEditPage().clickSaveAndView().getDocumentTitle());
167    } finally {
168    // Restore language settings.
169  1 setLanguageSettings(false, "en", "en");
170    }
171    }
172   
 
173  4 toggle private void setLanguageSettings(boolean isMultiLingual, String defaultLanguage, String supportedLanguages)
174    {
175  4 AdministrationPage adminPage = AdministrationPage.gotoPage();
176  4 LocalizationAdministrationSectionPage localizationSection = adminPage.clickLocalizationSection();
177  4 localizationSection.setMultiLingual(isMultiLingual);
178  4 localizationSection.setDefaultLanguage(defaultLanguage);
179  4 localizationSection.setSupportedLanguages(supportedLanguages);
180  4 localizationSection.clickSave();
181    }
182    }