1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.officeimporter.internal.cleaner

File RedundantTagOfficeCleaningTest.java

 

Code metrics

0
18
2
1
74
39
2
0.11
9
2
1

Classes

Class Line # Actions
RedundantTagOfficeCleaningTest 35 18 0% 2 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.officeimporter.internal.cleaner;
21   
22    import java.io.StringReader;
23   
24    import org.junit.Assert;
25    import org.junit.Test;
26    import org.w3c.dom.Document;
27    import org.w3c.dom.NodeList;
28   
29    /**
30    * Test case for filtering redundant html tags in {@link OfficeHTMLCleaner}.
31    *
32    * @version $Id: 36167a131debd6228e4a0f2976604dd557612e89 $
33    * @since 1.8
34    */
 
35    public class RedundantTagOfficeCleaningTest extends AbstractHTMLCleaningTest
36    {
37    /**
38    * Test filtering of those tags which doesn't have any attributes set.
39    */
 
40  1 toggle @Test
41    public void testFilterIfZeroAttributes()
42    {
43  1 String htmlTemplate = header + "<p>Test%sRedundant%sFiltering</p>" + footer;
44  1 String[] filterIfZeroAttributesTags = new String[] {"span", "div"};
45  1 for (String tag : filterIfZeroAttributesTags) {
46  2 String startTag = "<" + tag + ">";
47  2 String endTag = "</" + tag + ">";
48  2 String html = String.format(htmlTemplate, startTag, endTag);
49  2 Document doc = officeHTMLCleaner.clean(new StringReader(html));
50  2 NodeList nodes = doc.getElementsByTagName(tag);
51  2 Assert.assertEquals(0, nodes.getLength());
52    }
53    }
54   
55    /**
56    * Test filtering of those tags which doesn't have any textual content in them.
57    */
 
58  1 toggle @Test
59    public void testFilterIfNoContent()
60    {
61  1 String htmlTemplate = header + "<p>Test%sRedundant%s%s%sFiltering</p>" + footer;
62  1 String[] filterIfNoContentTags =
63    new String[] {"em", "strong", "dfn", "code", "samp", "kbd", "var", "cite", "abbr", "acronym", "address",
64    "blockquote", "q", "pre", "h1", "h2", "h3", "h4", "h5", "h6"};
65  1 for (String tag : filterIfNoContentTags) {
66  20 String startTag = "<" + tag + ">";
67  20 String endTag = "</" + tag + ">";
68  20 String html = String.format(htmlTemplate, startTag, endTag, startTag, endTag);
69  20 Document doc = officeHTMLCleaner.clean(new StringReader(html));
70  20 NodeList nodes = doc.getElementsByTagName(tag);
71  20 Assert.assertEquals(1, nodes.getLength());
72    }
73    }
74    }