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

File AbstractHTMLCleaningTest.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

0
5
2
1
78
26
2
0.4
2.5
2
1

Classes

Class Line # Actions
AbstractHTMLCleaningTest 37 5 0% 2 0
1.0100%
 

Contributing tests

This file is covered by 4 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   
26    import org.w3c.dom.Document;
27    import org.xwiki.officeimporter.internal.AbstractOfficeImporterTest;
28    import org.xwiki.xml.html.HTMLCleaner;
29    import org.xwiki.xml.html.HTMLUtils;
30   
31    /**
32    * Abstract class for all HTML cleaner tests.
33    *
34    * @version $Id: 75f34a2e7ca2b193188b511f3c908091b14766f9 $
35    * @since 1.8M2
36    */
 
37    public abstract class AbstractHTMLCleaningTest extends AbstractOfficeImporterTest
38    {
39    /**
40    * Beginning of the test html document.
41    */
42    protected String header = "<html><head><title>Title</title></head><body>";
43   
44    /**
45    * Ending of the test html document..
46    */
47    protected String footer = "</body></html>";
48   
49    /**
50    * {@link OfficeHTMLCleaner} used for tests.
51    */
52    protected HTMLCleaner officeHTMLCleaner;
53   
54    /**
55    * {@link WysiwygHTMLCleaner} used for tests.
56    */
57    protected HTMLCleaner wysiwygHTMLCleaner;
58   
 
59  19 toggle @Override
60    public void setUp() throws Exception
61    {
62  19 super.setUp();
63  19 this.officeHTMLCleaner = getComponentManager().getInstance(HTMLCleaner.class, "openoffice");
64  19 this.wysiwygHTMLCleaner = getComponentManager().getInstance(HTMLCleaner.class, "wysiwyg");
65    }
66   
67    /**
68    * Asserts that the given dirty HTML fragment equals the expected clean HTML after the cleaning process.
69    *
70    * @param dirtyHTML the HTML fragment to be cleaned
71    * @param expectedCleanHTML expected clean HTML
72    */
 
73  4 toggle protected void assertCleanHTML(String dirtyHTML, String expectedCleanHTML)
74    {
75  4 Document document = officeHTMLCleaner.clean(new StringReader(header + dirtyHTML + footer));
76  4 Assert.assertEquals(header + expectedCleanHTML + footer, HTMLUtils.toString(document, true, true).trim());
77    }
78    }