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

File SectionTest.java

 

Code metrics

4
46
6
1
189
115
8
0.17
7.67
6
1.33

Classes

Class Line # Actions
SectionTest 43 46 0% 8 4
0.928571492.9%
 

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