| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 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 |
|
@link |
| 43 |
|
|
| 44 |
|
@version |
| 45 |
|
@since |
| 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 |
|
}) |
| |
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 3 |
Complexity Density: 0.43 |
|
| 57 |
|
public class HTMLUtilsTest |
| 58 |
|
{ |
| 59 |
|
private HTMLCleaner cleaner; |
| 60 |
|
|
| 61 |
|
@Rule |
| 62 |
|
public final ComponentManagerRule componentManager = new ComponentManagerRule(); |
| 63 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 64 |
2 |
@Before... |
| 65 |
|
public void setUp() throws Exception |
| 66 |
|
{ |
| 67 |
2 |
this.cleaner = this.componentManager.getInstance(HTMLCleaner.class); |
| 68 |
|
} |
| 69 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
| 70 |
1 |
@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 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
| 80 |
1 |
@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 |
|
} |