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

File HTMLUtilsTest.java

 

Code metrics

0
7
3
1
88
56
3
0.43
2.33
3
1

Classes

Class Line # Actions
HTMLUtilsTest 57 7 0% 3 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.xml.html;
21   
22    import java.io.StringReader;
23   
24    import org.junit.Assert;
25    import org.junit.Before;
26    import org.junit.Rule;
27    import org.junit.Test;
28    import org.w3c.dom.Document;
29    import org.xwiki.context.internal.DefaultExecution;
30    import org.xwiki.test.ComponentManagerRule;
31    import org.xwiki.test.annotation.ComponentList;
32    import org.xwiki.xml.internal.html.DefaultHTMLCleaner;
33    import org.xwiki.xml.internal.html.DefaultHTMLCleanerTest;
34    import org.xwiki.xml.internal.html.filter.AttributeFilter;
35    import org.xwiki.xml.internal.html.filter.BodyFilter;
36    import org.xwiki.xml.internal.html.filter.FontFilter;
37    import org.xwiki.xml.internal.html.filter.LinkFilter;
38    import org.xwiki.xml.internal.html.filter.ListFilter;
39    import org.xwiki.xml.internal.html.filter.ListItemFilter;
40   
41    /**
42    * Unit tests for {@link org.xwiki.xml.html.HTMLUtils}.
43    *
44    * @version $Id: b7bd3c881564aa3f7b049dfa06cfa985873e97bd $
45    * @since 1.8.3
46    */
47    @ComponentList({
48    LinkFilter.class,
49    ListFilter.class,
50    ListItemFilter.class,
51    FontFilter.class,
52    BodyFilter.class,
53    AttributeFilter.class,
54    DefaultHTMLCleaner.class,
55    DefaultExecution.class
56    })
 
57    public class HTMLUtilsTest
58    {
59    private HTMLCleaner cleaner;
60   
61    @Rule
62    public final ComponentManagerRule componentManager = new ComponentManagerRule();
63   
 
64  2 toggle @Before
65    public void setUp() throws Exception
66    {
67  2 this.cleaner = this.componentManager.getInstance(HTMLCleaner.class);
68    }
69   
 
70  1 toggle @Test
71    public void testStripHTMLEnvelope() throws Exception
72    {
73  1 Document document =
74    this.cleaner.clean(new StringReader("<html><head><body><p>test1</p><p>test2</p></body></html>"));
75  1 HTMLUtils.stripHTMLEnvelope(document);
76  1 Assert.assertEquals(DefaultHTMLCleanerTest.HEADER + "<html><p>test1</p><p>test2</p></html>\n",
77    HTMLUtils.toString(document));
78    }
79   
 
80  1 toggle @Test
81    public void testStripTopLevelParagraph() throws Exception
82    {
83  1 Document document = this.cleaner.clean(new StringReader("<html><head /><body><p>test</p></body></html>"));
84  1 HTMLUtils.stripFirstElementInside(document, "body", "p");
85  1 Assert.assertEquals(DefaultHTMLCleanerTest.HEADER + "<html><head></head><body>test</body></html>\n",
86    HTMLUtils.toString(document));
87    }
88    }