1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
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 |
|
@link |
31 |
|
|
32 |
|
@version |
33 |
|
@since |
34 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 2 |
Complexity Density: 0.11 |
|
35 |
|
public class RedundantTagOfficeCleaningTest extends AbstractHTMLCleaningTest |
36 |
|
{ |
37 |
|
|
38 |
|
|
39 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
40 |
1 |
@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 |
|
|
57 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
58 |
1 |
@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 |
|
} |