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

File RemoveFormattingTest.java

 

Code metrics

0
40
6
1
124
72
6
0.15
6.67
6
1

Classes

Class Line # Actions
RemoveFormattingTest 30 40 0% 6 0
1.0100%
 

Contributing tests

This file is covered by 5 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.wysiwyg;
21   
22    import org.junit.Test;
23    import org.xwiki.test.wysiwyg.framework.AbstractWysiwygTestCase;
24   
25    /**
26    * Functional tests for remove formatting support inside the WYSIWYG editor.
27    *
28    * @version $Id: ee5af05046ee1d59fb268bd22b1098b293179726 $
29    */
 
30    public class RemoveFormattingTest extends AbstractWysiwygTestCase
31    {
32    /**
33    * Tests if formatting markers are removed properly.
34    */
 
35  1 toggle @Test
36    public void testRemoveFormattingMarkers()
37    {
38  1 switchToSource();
39  1 setSourceText("==== **//__--abc--__//** ====");
40  1 switchToWysiwyg();
41  1 selectAllContent();
42  1 clickRemoveFormattingButton();
43  1 switchToSource();
44  1 assertSourceText("==== abc ====");
45    }
46   
47    /**
48    * Tests if in-line style is removed properly.
49    */
 
50  1 toggle @Test
51    public void testRemoveInlineStyle()
52    {
53  1 switchToSource();
54  1 setSourceText("a(% style=\"color:red;\" %)b(% style=\"font-size:36pt;\" %)c(%%)d(%%)e");
55  1 switchToWysiwyg();
56  1 selectAllContent();
57  1 clickRemoveFormattingButton();
58  1 switchToSource();
59  1 assertSourceText("abcde");
60    }
61   
62    /**
63    * Tests if the formatting is removed properly when the selection spans across block-level elements.
64    */
 
65  1 toggle @Test
66    public void testRemoveFormattingFromCrossBlockSelection()
67    {
68  1 switchToSource();
69  1 setSourceText("= a(% style=\"color:green\" %)b**cd**(%%)e =\n\nf(% style=\"font-size:36pt\" %)g//hi//(%%)j");
70  1 switchToWysiwyg();
71  1 select("document.body.getElementsByTagName('strong')[0].firstChild", 1,
72    "document.body.getElementsByTagName('em')[0].firstChild", 1);
73  1 clickRemoveFormattingButton();
74  1 switchToSource();
75  1 assertSourceText("= a(% style=\"color:green\" %)b**c**(%%)de =\n\nfgh(% style=\"font-size:36pt\" %)//i//(%%)j");
76    }
77   
78    /**
79    * Tests if the anchors are kept after removing the formatting.
80    */
 
81  1 toggle @Test
82    public void testRemoveFormattingKeepsTheAnchorsIntact()
83    {
84    // Selection includes the anchor.
85  1 switchToSource();
86  1 setSourceText("a**b[[c//d//e>>http://www.xwiki.org]]f**g");
87  1 switchToWysiwyg();
88  1 selectAllContent();
89  1 clickRemoveFormattingButton();
90  1 switchToSource();
91  1 assertSourceText("ab[[cde>>http://www.xwiki.org]]fg");
92   
93    // Selection is included in the anchor.
94  1 setSourceText("1**2[[3//456//7>>http://www.xwiki.org]]8**9");
95  1 switchToWysiwyg();
96  1 select("document.getElementsByTagName('em')[0].firstChild", 1,
97    "document.getElementsByTagName('em')[0].firstChild", 2);
98  1 clickRemoveFormattingButton();
99  1 switchToSource();
100  1 assertSourceText("1**2**[[**3//4//**5**//6//7**>>http://www.xwiki.org]]**8**9");
101    }
102   
103    /**
104    * See XWIKI-3946: Standalone XHTML anchors with spans inside are converted badly to XWiki 2.0 syntax
105    */
 
106  1 toggle @Test
107    public void testRemoveFormattingFromStandaloneAnchor()
108    {
109  1 setContent("<a href=\"http://www.xwiki.org\" style=\"color: red; font-size: 18pt;\">123456</a>");
110  1 select("document.body.firstChild.firstChild", 2, "document.body.firstChild.firstChild", 4);
111  1 clickRemoveFormattingButton();
112  1 switchToSource();
113  1 assertSourceText("[[(% style=\"color: red; font-size: 18pt;\" %)12(%%)34"
114    + "(% style=\"color: red; font-size: 18pt;\" %)56>>url:http://www.xwiki.org]]");
115    }
116   
117    /**
118    * Clicks on the tool bar button for removing the in-line formatting of the current selection.
119    */
 
120  6 toggle protected void clickRemoveFormattingButton()
121    {
122  6 pushToolBarButton("Clear Formatting");
123    }
124    }