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

File HTMLCleanerTest.java

 

Code metrics

0
5
3
1
85
28
3
0.6
1.67
3
1

Classes

Class Line # Actions
HTMLCleanerTest 32 5 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 3 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.wysiwyg.server.internal.cleaner;
21   
22    import org.junit.Assert;
23    import org.junit.Test;
24    import org.xwiki.gwt.wysiwyg.client.cleaner.HTMLCleaner;
25   
26    /**
27    * A generic JUnit test used by {@link HTMLCleanerTestSuite} to clean some passed HTML content and verify it matches
28    * some passed expectation.
29    *
30    * @version $Id: 17f171b354d283c5979ae3c378b82fa88268cbd7 $
31    */
 
32    public class HTMLCleanerTest
33    {
34    /**
35    * The HTML cleaner being tested.
36    */
37    private HTMLCleaner cleaner;
38   
39    /**
40    * The HTML fragment to be cleaned.
41    */
42    private final String input;
43   
44    /**
45    * The expected clean HTML.
46    */
47    private final String expected;
48   
49    /**
50    * Creates a new test case that checks if the result of cleaning the given HTML input equals the expected HTML.
51    *
52    * @param input the HTML fragment to be cleaned
53    * @param expected the expected clean HTML
54    * @param cleaner the HTML cleaner being tested
55    */
 
56  3 toggle public HTMLCleanerTest(String input, String expected, HTMLCleaner cleaner)
57    {
58  3 this.input = input;
59  3 this.expected = expected;
60  3 this.cleaner = cleaner;
61    }
62   
63    /**
64    * The actual test.
65    */
 
66  3 toggle @Test
67    public void execute()
68    {
69  3 Assert.assertEquals(xhtmlFragment(expected), cleaner.clean(input));
70    }
71   
72    /**
73    * Adds the XHTML envelope to the given XHTML fragment.
74    *
75    * @param fragment the content to be placed inside the {@code body} tag
76    * @return the given XHTML fragment wrapped in the XHTML envelope
77    */
 
78  3 toggle private String xhtmlFragment(String fragment)
79    {
80  3 return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
81    + "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" "
82    + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n" + "<html><head></head><body>" + fragment
83    + "</body></html>\n";
84    }
85    }